Skip to content

Commit

Permalink
CS.
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Nov 29, 2021
1 parent 52440be commit a646e43
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG VERSION=8.0

FROM composer:2.0 AS build
RUN composer global require overtrue/phplint
RUN composer global require overtrue/phplint:^4.0.0

FROM php:${VERSION}-cli-alpine
COPY --from=build /tmp/vendor /root/.composer/vendor
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

```shell
// PHP 8
$ composer require overtrue/phplint --dev -vvv
$ composer require overtrue/phplint:^4.0 --dev -vvv

// PHP 7
$ composer require overtrue/phplint:^2.0 --dev -vvv
$ composer require overtrue/phplint:^3.0 --dev -vvv
```

### Locally, if you only have Docker
Expand Down Expand Up @@ -153,7 +153,7 @@ Run this command using `overtrue/phplint:8.0` Docker image:
### Warnings
Not all linting problems are errors, PHP also has warnings, for example when using a `continue` statement within a
`switch` `case`. By default these errors are not reported, but you can turn this on with the `warning` cli flag, or
`switch` `case`. By default, these errors are not reported, but you can turn this on with the `warning` cli flag, or
by setting the `warning` to true in the configuration.
## :heart: Sponsor me
Expand Down
15 changes: 6 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
"require": {
"php": ">=8.0",
"ext-json": "*",
"symfony/console": "^5.0",
"symfony/finder": "^5.0",
"symfony/process": "^5.0",
"symfony/yaml": "^5.0",
"symfony/console": "^5.3.11",
"symfony/finder": "^5.3.7",
"symfony/process": "^5.3.12",
"symfony/yaml": "^5.3.11",
"n98/junit-xml": "1.1.0"
},
"require-dev": {
"jakub-onderka/php-console-highlighter": "^0.4",
"brainmaestro/composer-git-hooks": "^2.7",
"friendsofphp/php-cs-fixer": "^3.0"
"brainmaestro/composer-git-hooks": "^2.8.5",
"friendsofphp/php-cs-fixer": "^3.3.2"
},
"autoload": {
"psr-4": {
Expand All @@ -38,9 +38,6 @@
"hooks": {
"pre-commit": [
"composer fix-style"
],
"pre-push": [
"composer check-style"
]
}
},
Expand Down
12 changes: 6 additions & 6 deletions src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ public static function put(mixed $contents): int
return file_put_contents(self::getFilename(), json_encode($contents));
}

public static function setFilename(string $filename)
public static function setFilename(string $filename): void
{
self::$filename = $filename;
self::makeFolderForFilename();
}

private static function makeFolderForFilename()
private static function makeFolderForFilename(): void
{
$filename = self::getFilename();
$dirname = dirname($filename);
if (!file_exists($dirname)) {
mkdir($dirname, 0777, true);
$dir = dirname(self::getFilename());

if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LintCommand extends Command
protected InputInterface $input;
protected OutputInterface $output;

protected function configure()
protected function configure(): void
{
$this
->setName('phplint')
Expand Down Expand Up @@ -116,7 +116,7 @@ protected function configure()
);
}

public function initialize(InputInterface $input, OutputInterface $output)
public function initialize(InputInterface $input, OutputInterface $output): void
{
$this->input = $input;
$this->output = $output;
Expand Down Expand Up @@ -205,7 +205,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return $code;
}

protected function dumpJsonResult(string $path, array $errors, array $options, array $context = [])
protected function dumpJsonResult(string $path, array $errors, array $options, array $context = []): void
{
$result = [
'status' => 'success',
Expand All @@ -216,17 +216,19 @@ protected function dumpJsonResult(string $path, array $errors, array $options, a
\file_put_contents($path, \json_encode(\array_merge($result, $context)));
}

protected function dumpXmlResult(string $path, array $errors, array $options, array $context = [])
protected function dumpXmlResult(string $path, array $errors, array $options, array $context = []): void
{
$document = new Document();
$suite = $document->addTestSuite();
$suite->setName('PHP Linter');
$suite->setTimestamp(new DateTime());
$suite->setTime($context['time_usage']);
$testCase = $suite->addTestCase();

foreach ($errors as $errorName => $value) {
$testCase->addError($errorName, 'Error', $value['error']);
}

$document->save($path);
}

Expand Down Expand Up @@ -280,7 +282,7 @@ protected function executeLint(Linter $linter, InputInterface $input, OutputInte
/**
* @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException
*/
protected function showErrors(array $errors)
protected function showErrors(array $errors): void
{
$i = 0;
$this->output->writeln("\nThere was " . count($errors) . ' errors:');
Expand Down Expand Up @@ -367,7 +369,7 @@ protected function mergeOptions(): array
return $options;
}

protected function getConfigFile(): ?string
protected function getConfigFile(): false|string
{
$inputPath = $this->input->getArgument('path');

Expand Down
2 changes: 1 addition & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Application extends BaseApplication
{
public const NAME = 'phplint';

public const VERSION = '3.0';
public const VERSION = '4.0';

public function __construct()
{
Expand Down
6 changes: 1 addition & 5 deletions src/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ public function lint(array $files = [], bool $cache = true): array

public function setCache(array $cache = [])
{
if (is_array($cache)) {
$this->cache = $cache;
} else {
$this->cache = [];
}
$this->cache = $cache;
}

public function getFiles(): array
Expand Down

0 comments on commit a646e43

Please sign in to comment.