Skip to content

Commit 4003268

Browse files
authored
Merge pull request #20 from wundii/dev
version 0.1.0
2 parents be29dc5 + 67c326a commit 4003268

25 files changed

+803
-123
lines changed

README.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,62 @@
1-
# PHPLint
1+
# PHPLint - the fastest way to check your syntax
22

33
[![PHP-Tests](https://github.com/wundii/PHPLint/actions/workflows/code_quality.yml/badge.svg)](https://github.com/wundii/PHPLint/actions/workflows/code_quality.yml)
44
[![PHPStan](https://img.shields.io/badge/PHPStan-level%208-brightgreen.svg?style=flat)](https://phpstan.org/)
5+
[![Downloads](https://img.shields.io/packagist/dt/wundii/phplint.svg?style=flat)](https://packagist.org/packages/wundii/phplint)
56

6-
## Installation
7+
This program is one of the fastest tools for static code analysis and error detection in PHP source code.
8+
The native php lint checking is used here.
9+
10+
## Installation and Usage
11+
12+
```shell
13+
composer require wundii/phplint --dev
14+
```
15+
16+
```shell
17+
php vendor/bin/phplint
18+
php vendor/bin/phplint --config=phplint.php
19+
php vendor/bin/phplint --help
20+
```
21+
22+
### Functionality over the config file (phplint.php)
23+
+ php cgi executable (default: php)
24+
+ paths (default: src)
25+
+ skip
26+
+ memory limit (default: 512M)
27+
+ async processes (default: 10)
28+
+ enable warnings (default: true)
29+
+ enable notice (default: true)
30+
+ ignore exit code (default: false)
31+
+ ignore process bar (default: false)
32+
33+
## Development for PHPLint
34+
35+
### composer scripts
36+
37+
```shell
38+
composer rector-dry
39+
composer rector-apply
40+
composer phpstan
41+
composer ecs-dry
42+
composer ecs-apply
43+
composer phpunit
44+
composer cache-clear
45+
```
46+
47+
### complete checks before merge
748

849
```shell
9-
placeholder
10-
```
50+
composer complete-check
51+
```
52+
53+
### To-do list for version 1.0.0
54+
+ [ ] add symfony cache-system
55+
+ [ ] refactor LintConsoleOutput class
56+
+ [ ] refactor LintConfig class
57+
58+
## Feedback and Contributions
59+
I welcome feedback, bug reports and contributions from the community!
60+
If you found a bug or have a suggestion for improvement, please create an issue.
61+
62+
Every contribution is welcome!

bin/phplint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
declare(strict_types=1);
55

6-
require_once __DIR__ . '/phplint.php';
6+
require_once __DIR__ . DIRECTORY_SEPARATOR . 'phplint.php';

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wundii/phplint",
3-
"description": "This tool checks the syntax and style of PHP files",
3+
"description": "This tool is the fast way, to checks the syntax of your PHP files.",
44
"license": "MIT",
55
"authors": [
66
{
@@ -14,11 +14,11 @@
1414
"require": {
1515
"php": ">=8.1",
1616
"ext-json": "*",
17-
"symfony/config": "6.*",
18-
"symfony/console": "6.*",
19-
"symfony/dependency-injection": "6.*",
20-
"symfony/finder": "6.*",
21-
"symfony/process": "6.*"
17+
"symfony/config": "^6.0",
18+
"symfony/console": "^6.0",
19+
"symfony/dependency-injection": "^6.0",
20+
"symfony/finder": "^6.0",
21+
"symfony/process": "^6.0"
2222
},
2323
"require-dev": {
2424
"phpstan/phpstan": "^1.10",

phpunit.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4-
colors="true"
54
bootstrap="tests/bootstrap.php"
65
cacheDirectory="cache/phpunit"
7-
stopOnError ="true"
6+
colors="true"
7+
failOnRisky="true"
8+
failOnWarning="true"
89
testdox="true"
9-
defaultTestSuite="main"
1010
>
1111
<php>
1212
<ini name="display_errors" value="1"/>
@@ -22,8 +22,12 @@
2222
<directory>tests/Main/DependencyInjection</directory>
2323
<directory>tests/Main/Finder</directory>
2424
<directory>tests/Main/Process</directory>
25+
<directory>tests/Main/Lint</directory>
2526
<directory>tests/Main/Console</directory>
2627
</testsuite>
28+
<testsuite name="e2e">
29+
<directory>tests/E2E/Console</directory>
30+
</testsuite>
2731
</testsuites>
2832
<source>
2933
<include>

src/Config/LintConfig.php

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,23 @@ final class LintConfig
2727

2828
private int $asyncProcess = 10;
2929

30-
private bool $allowWarning = true;
30+
private bool $enableWarning = true;
3131

32-
private bool $allowNotice = true;
32+
private bool $enableNotice = true;
33+
34+
private bool $ignoreExitCode = false;
35+
36+
private bool $ignoreProcessBar = false;
37+
38+
/**
39+
* @todo not implemented
40+
*/
41+
private bool $cache = true;
42+
43+
/**
44+
* @todo not implemented
45+
*/
46+
private string $cacheDirectory = '.phplint';
3347

3448
public function getPhpCgiExecutable(): string
3549
{
@@ -147,23 +161,63 @@ public function setAsyncProcess(int $asyncProcess): void
147161
$this->asyncProcess = $asyncProcess;
148162
}
149163

150-
public function isAllowWarning(): bool
164+
public function isEnableWarning(): bool
165+
{
166+
return $this->enableWarning;
167+
}
168+
169+
public function disableWarning(): void
170+
{
171+
$this->enableWarning = false;
172+
}
173+
174+
public function isEnableNotice(): bool
175+
{
176+
return $this->enableNotice;
177+
}
178+
179+
public function disableNotice(): void
180+
{
181+
$this->enableNotice = false;
182+
}
183+
184+
public function isIgnoreExitCode(): bool
185+
{
186+
return $this->ignoreExitCode;
187+
}
188+
189+
public function ignoreExitCode(): void
190+
{
191+
$this->ignoreExitCode = true;
192+
}
193+
194+
public function isIgnoreProcessBar(): bool
195+
{
196+
return $this->ignoreProcessBar;
197+
}
198+
199+
public function ignoreProcessBar(): void
200+
{
201+
$this->ignoreProcessBar = true;
202+
}
203+
204+
public function isCache(): bool
151205
{
152-
return $this->allowWarning;
206+
return $this->cache;
153207
}
154208

155-
public function setAllowWarning(bool $allowWarning): void
209+
public function setCache(bool $cache): void
156210
{
157-
$this->allowWarning = $allowWarning;
211+
$this->cache = $cache;
158212
}
159213

160-
public function isAllowNotice(): bool
214+
public function getCacheDirectory(): string
161215
{
162-
return $this->allowNotice;
216+
return $this->cacheDirectory;
163217
}
164218

165-
public function setAllowNotice(bool $allowNotice): void
219+
public function setCacheDirectory(string $cacheDirectory): void
166220
{
167-
$this->allowNotice = $allowNotice;
221+
$this->cacheDirectory = $cacheDirectory;
168222
}
169223
}

src/Console/Commands/LintCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5656

5757
$usageExecuteTime = Helper::formatTime(microtime(true) - $startExecuteTime);
5858

59-
return (int) $this->lintConsoleOutput->finishApplication($usageExecuteTime);
59+
$exitCode = (int) $this->lintConsoleOutput->finishApplication($usageExecuteTime);
60+
61+
if ($this->lintConfig->isIgnoreExitCode()) {
62+
return self::SUCCESS;
63+
}
64+
65+
return $exitCode;
6066
}
6167
}

src/Console/LintApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class LintApplication
2929
/**
3030
* @var string
3131
*/
32-
public const VERSION = '0.0.1';
32+
public const VERSION = '0.1.0';
3333

3434
public function __construct(
3535
private readonly LintCommand $lintCommand,

src/Console/Output/LintConsoleOutput.php

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace PHPLint\Console\Output;
66

7-
use PHPLint\Console\ConsoleColorEnum;
7+
use PHPLint\Config\LintConfig;
8+
use PHPLint\Console\OutputColorEnum;
89
use PHPLint\Process\LintProcessResult;
910
use PHPLint\Process\StatusEnum;
1011
use Symfony\Component\Console\Helper\Helper;
@@ -27,7 +28,8 @@ final class LintConsoleOutput
2728
private int $countFiles = 0;
2829

2930
public function __construct(
30-
private readonly SymfonyStyle $symfonyStyle
31+
private readonly SymfonyStyle $symfonyStyle,
32+
private readonly LintConfig $lintConfig,
3133
) {
3234
}
3335

@@ -62,29 +64,38 @@ public function finishApplication(string $executionTime): bool
6264

6365
public function progressBarStart(int $count): void
6466
{
65-
$this->symfonyStyle->writeln('Linting files...');
66-
$this->symfonyStyle->newLine();
67+
if ($this->lintConfig->isIgnoreProcessBar()) {
68+
return;
69+
}
6770

6871
$this->symfonyStyle->progressStart($count);
6972
}
7073

7174
public function progressBarAdvance(): void
7275
{
76+
if ($this->lintConfig->isIgnoreProcessBar()) {
77+
return;
78+
}
79+
7380
$this->symfonyStyle->progressAdvance();
7481
}
7582

7683
public function progressBarFinish(): void
7784
{
85+
if ($this->lintConfig->isIgnoreProcessBar()) {
86+
return;
87+
}
88+
7889
$this->symfonyStyle->progressFinish();
7990
}
8091

8192
public function messageByProcessResult(LintProcessResult $lintProcessResult): void
8293
{
83-
$consoleColorEnum = match ($lintProcessResult->getStatus()) {
84-
StatusEnum::OK => ConsoleColorEnum::GREEN,
85-
StatusEnum::NOTICE => ConsoleColorEnum::BLUE,
86-
StatusEnum::WARNING => ConsoleColorEnum::YELLOW,
87-
default => ConsoleColorEnum::RED,
94+
$outputColorEnum = match ($lintProcessResult->getStatus()) {
95+
StatusEnum::OK => OutputColorEnum::GREEN,
96+
StatusEnum::NOTICE => OutputColorEnum::BLUE,
97+
StatusEnum::WARNING => OutputColorEnum::YELLOW,
98+
default => OutputColorEnum::RED,
8899
};
89100

90101
++$this->countFiles;
@@ -97,25 +108,29 @@ public function messageByProcessResult(LintProcessResult $lintProcessResult): vo
97108
);
98109
$line02 = sprintf(
99110
'<fg=%s;options=bold>%s</>: <fg=%s>%s</>',
100-
$consoleColorEnum->getBrightValue(),
111+
$outputColorEnum->getBrightValue(),
101112
ucfirst($lintProcessResult->getStatus()->value),
102-
$consoleColorEnum->value,
113+
$outputColorEnum->value,
103114
$lintProcessResult->getResult(),
104115
);
105116

106117
$this->symfonyStyle->writeln($line01);
107118
$this->symfonyStyle->writeln($line02);
108-
$this->loadCodeSnippet($lintProcessResult->getFilename(), (int) $lintProcessResult->getLine(), $consoleColorEnum);
119+
$this->loadCodeSnippet($lintProcessResult->getFilename(), (int) $lintProcessResult->getLine(), $outputColorEnum);
109120
$this->symfonyStyle->newLine();
110121

111122
$this->isSuccess = false;
112123
}
113124

114-
private function loadCodeSnippet(string $filename, int $line, ConsoleColorEnum $consoleColorEnum): void
125+
private function loadCodeSnippet(string $filename, int $line, OutputColorEnum $outputColorEnum): void
115126
{
116127
$lineStart = $line - self::SNIPPED_LINE;
117128
$lineEnd = $line + (self::SNIPPED_LINE - 1);
118129

130+
if (! file_exists($filename)) {
131+
return;
132+
}
133+
119134
$content = file_get_contents($filename);
120135
if ($content === false) {
121136
return;
@@ -126,25 +141,25 @@ private function loadCodeSnippet(string $filename, int $line, ConsoleColorEnum $
126141
$lineCnt = 0;
127142
foreach ($contentArray as $contentLine) {
128143
if ($lineCnt >= $lineStart && $lineCnt < $lineEnd) {
129-
$lineNumberPost = $lineCnt + 1;
130-
$tmp = str_pad((string) $lineNumberPost, self::LINE_LENGTH, '0', STR_PAD_LEFT);
131-
$lineNumberPre = substr($tmp, 0, self::LINE_LENGTH - strlen((string) $lineNumberPost));
144+
$lineNumber = $lineCnt + 1;
145+
$tmp = str_pad((string) $lineNumber, self::LINE_LENGTH, '0', STR_PAD_LEFT);
146+
$lineNumberPrefix = substr($tmp, 0, self::LINE_LENGTH - strlen((string) $lineNumber));
132147

133148
if ($lineCnt + 1 === $line) {
134149
$result = sprintf(
135-
'<fg=%s;options=bold>%s</><fg=%s>%s</><fg=blue;options=bold>:</> <fg=%s>%s</>',
136-
$consoleColorEnum->getBrightValue(),
137-
$lineNumberPre,
138-
$consoleColorEnum->value,
139-
$lineNumberPost,
140-
$consoleColorEnum->value,
150+
'<fg=%s>%s</><fg=%s;options=bold>%s</><fg=gray>|</> <fg=%s>%s</>',
151+
$outputColorEnum->getBrightValue(),
152+
$lineNumberPrefix,
153+
$outputColorEnum->value,
154+
$lineNumber,
155+
$outputColorEnum->value,
141156
$contentLine,
142157
);
143158
} else {
144159
$result = sprintf(
145-
'<fg=gray;options=bold>%s</><fg=white>%s</><fg=blue;options=bold>:</> <fg=white>%s</>',
146-
$lineNumberPre,
147-
$lineNumberPost,
160+
'<fg=gray>%s</><fg=white;options=bold>%s</><fg=gray>|</> <fg=white>%s</>',
161+
$lineNumberPrefix,
162+
$lineNumber,
148163
$contentLine,
149164
);
150165
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PHPLint\Console;
66

7-
enum ConsoleColorEnum: string
7+
enum OutputColorEnum: string
88
{
99
case BLACK = 'black';
1010
case RED = 'red';

0 commit comments

Comments
 (0)