Skip to content

Commit

Permalink
Merge pull request #25 from kubawerlos/feature/allow-symfony-4
Browse files Browse the repository at this point in the history
Allow Symfony 4
  • Loading branch information
overtrue authored Dec 12, 2017
2 parents adae4aa + c318352 commit 1cf7775
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
45 changes: 31 additions & 14 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
<?php

$year = date('Y');
/*
* This file is part of the overtrue/phplint.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

$header = <<<EOF
This file is part of the overtrue/phplint.
(c) $year overtrue <[email protected]>
EOF;
(c) overtrue <[email protected]>
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

return Symfony\CS\Config\Config::create()
return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRiskyAllowed(true)
// use default SYMFONY_LEVEL and extra fixers:
->fixers(array(
'header_comment',
'short_array_syntax',
'ordered_use',
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'header_comment' => [
'header' => $header,
],
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => true,
//'strict',
//'strict_param',
'phpdoc_order', // 注释中param throw return等的顺序
'php4_constructor', //将同名构造方法改为__construct()
))
->finder(
Symfony\CS\Finder\DefaultFinder::create()
'phpdoc_order' => true, // 注释中param throw return等的顺序
'no_php4_constructor' => true, //将同名构造方法改为__construct()
])
->setFinder(
PhpCsFixer\Config::create()->getFinder()
->exclude('vendor')
->in(__DIR__.'/')
->append([
__FILE__,
])
)
;
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
],
"require": {
"php": ">=5.5.9",
"symfony/console": "^2.7|^3.0",
"symfony/finder": "^2.7|^3.0",
"symfony/process": "^2.7|^3.0",
"symfony/yaml": "^2.7|^3.0"
"symfony/console": "^2.7 || ^3.0 || ^4.0",
"symfony/finder": "^2.7 || ^3.0 || ^4.0",
"symfony/process": "^2.7 || ^3.0 || ^4.0",
"symfony/yaml": "^2.7 || ^3.0 || ^4.0"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 7 additions & 7 deletions src/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$linter = new Linter($options['path'], $options['exclude'], $options['extensions']);
$linter->setProcessLimit($options['jobs']);

if ($input->getOption('cache') !== null) {
if (null !== $input->getOption('cache')) {
Cache::setFilename($input->getOption('cache'));
}

Expand Down Expand Up @@ -207,15 +207,15 @@ protected function executeLint($linter, $output, $fileCount, $cache = true)
$linter->setProcessCallback(function ($status, $filename) use ($output, $verbosity, $fileCount, $maxColumns) {
static $i = 0;

if ($i && $i % $maxColumns === 0) {
if ($i && 0 === $i % $maxColumns) {
$percent = floor(($i / $fileCount) * 100);
$output->writeln(str_pad(" {$i} / {$fileCount} ({$percent}%)", 18, ' ', STR_PAD_LEFT));
}
++$i;
if ($verbosity >= OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln('Linting: '.$filename."\t".($status === 'ok' ? '<info>OK</info>' : '<error>Error</error>'));
$output->writeln('Linting: '.$filename."\t".('ok' === $status ? '<info>OK</info>' : '<error>Error</error>'));
} else {
$output->write($status === 'ok' ? '<info>.</info>' : '<error>E</error>');
$output->write('ok' === $status ? '<info>.</info>' : '<error>E</error>');
}
});

Expand Down Expand Up @@ -286,7 +286,7 @@ protected function getConfigFile()

$dir = './';

if (count($inputPath) == 1 && $first = reset($inputPath)) {
if (1 == count($inputPath) && $first = reset($inputPath)) {
$dir = is_dir($first) ? $first : dirname($first);
}

Expand Down Expand Up @@ -354,13 +354,13 @@ protected function getScreenColumns()
return $columns - 1;
}

if (function_exists('shell_exec') && preg_match('#\d+ (\d+)#', shell_exec('stty size'), $match) === 1) {
if (function_exists('shell_exec') && 1 === preg_match('#\d+ (\d+)#', shell_exec('stty size'), $match)) {
if ((int) $match[1] > 0) {
return (int) $match[1];
}
}

if (function_exists('shell_exec') && preg_match('#columns = (\d+);#', shell_exec('stty'), $match) === 1) {
if (function_exists('shell_exec') && 1 === preg_match('#columns = (\d+);#', shell_exec('stty'), $match)) {
if ((int) $match[1] > 0) {
return (int) $match[1];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Overtrue\PHPLint;

use InvalidArgumentException;
use Overtrue\PHPLint\Process\Lint;
use Symfony\Component\Finder\Finder;
use SplFileInfo;
use InvalidArgumentException;
use Symfony\Component\Finder\Finder;

/**
* Class Linter.
Expand Down
2 changes: 1 addition & 1 deletion src/Process/Lint.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function hasSyntaxError()
return false;
}

return strpos($output, 'No syntax errors detected') === false;
return false === strpos($output, 'No syntax errors detected');
}

/**
Expand Down

0 comments on commit 1cf7775

Please sign in to comment.