Skip to content

Commit 6a36bec

Browse files
committed
[+]: fixes found by the project itself v2
1 parent f414fc0 commit 6a36bec

25 files changed

+749
-272
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### 0.8.0 (2020-06-16)
4+
5+
- replace PhpReflection with BetterReflection v2
6+
- fix bugs reported by PhpStan & PhpCodeCheck
7+
38
### 0.7.0 (2020-06-02)
49

510
- replace PhpReflection with BetterReflection

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[![Build Status](https://travis-ci.com/voku/Simple-PHP-Code-Parser.svg?branch=master)](https://travis-ci.com/voku/Simple-PHP-Code-Parser)
2-
[![Coverage Status](https://coveralls.io/repos/github/voku/Simple-PHP-Code-Parser/badge.svg?branch=master)](https://coveralls.io/github/voku/Simple-PHP-Code-Parser?branch=master)
32
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/2feaf2a179a24a5fac99cbf67e72df2f)](https://www.codacy.com/manual/voku/Simple-PHP-Code-Parser?utm_source=github.com&utm_medium=referral&utm_content=voku/Simple-PHP-Code-Parser&utm_campaign=Badge_Grade)
43
[![Latest Stable Version](https://poser.pugx.org/voku/Simple-PHP-Code-Parser/v/stable)](https://packagist.org/packages/voku/simple-php-code-parser)
54
[![Total Downloads](https://poser.pugx.org/voku/simple-php-code-parser/downloads)](https://packagist.org/packages/voku/simple-php-code-parser)
@@ -21,8 +20,10 @@ This code is forked from [JetBrains/phpstorm-stubs](https://github.com/JetBrains
2120
because they are in a test namespace and the autoloader is "autoload-dev", so here is a extended version with support for [ondrejmirtes/BetterReflection](https://github.com/ondrejmirtes/BetterReflection).
2221

2322
We will use:
24-
- "BetterReflection" AND "PHP-Parser"
25-
- "phpDocumentor" AND "psalm" for phpdocs
23+
- "PHP-Parser"
24+
- "BetterReflection"
25+
- "phpDocumentor"
26+
- "psalm" (*currently only for phpdocs*)
2627

2728
### Install via "composer require"
2829

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"phpdocumentor/reflection-common": "~2.1",
2727
"voku/simple-cache": "~4.0",
2828
"nikic/php-parser": "~4.4",
29-
"ondrejmirtes/better-reflection": "~4.2",
29+
"ondrejmirtes/better-reflection": "~4.3",
3030
"vimeo/psalm": "~3.11"
3131
},
3232
"require-dev": {

src/voku/SimplePhpParser/CliCommand/PhpCodeCheckerCommand.php

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\Console\Input\InputArgument;
1212
use Symfony\Component\Console\Input\InputDefinition;
1313
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Input\InputOption;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

1617
final class PhpCodeCheckerCommand extends Command
@@ -44,6 +45,41 @@ public function configure(): void
4445
new InputArgument('autoload-file', InputArgument::OPTIONAL, 'The path to your autoloader'),
4546
]
4647
)
48+
)
49+
->addOption(
50+
'access',
51+
null,
52+
InputOption::VALUE_OPTIONAL,
53+
'Check for "public|protected|private" methods.',
54+
'public|protected|private'
55+
)
56+
->addOption(
57+
'skip-mixed-types-as-error',
58+
null,
59+
InputOption::VALUE_OPTIONAL,
60+
'Skip check for mixed types. (false or true)',
61+
'false'
62+
)
63+
->addOption(
64+
'skip-deprecated-functions',
65+
null,
66+
InputOption::VALUE_OPTIONAL,
67+
'Skip check for deprecated functions / methods. (false or true)',
68+
'false'
69+
)
70+
->addOption(
71+
'skip-functions-with-leading-underscore',
72+
null,
73+
InputOption::VALUE_OPTIONAL,
74+
'Skip check for functions / methods with leading underscore. (false or true)',
75+
'false'
76+
)
77+
->addOption(
78+
'skip-parse-errors',
79+
null,
80+
InputOption::VALUE_OPTIONAL,
81+
'Skip parse errors in the output. (false or true)',
82+
'true'
4783
);
4884
}
4985

@@ -63,6 +99,15 @@ public function execute(InputInterface $input, OutputInterface $output): int
6399
$this->composerAutoloaderProjectPaths[] = $autoloadRealPath;
64100
}
65101

102+
$access = $input->getOption('access');
103+
\assert(\is_string($access));
104+
$access = (array) \explode('|', $access);
105+
106+
$skipMixedTypesAsError = (bool) $input->getOption('skip-mixed-types-as-error');
107+
$skipDeprecatedFunctions = (bool) $input->getOption('skip-deprecated-functions');
108+
$skipFunctionsWithLeadingUnderscore = (bool) $input->getOption('skip-functions-with-leading-underscore');
109+
$skipParseErrorsAsError = (bool) $input->getOption('skip-parse-errors');
110+
66111
$formatter = $output->getFormatter();
67112
$formatter->setStyle('file', new OutputFormatterStyle('default', null, ['bold']));
68113
$formatter->setStyle('error', new OutputFormatterStyle('red', null, []));
@@ -73,22 +118,22 @@ public function execute(InputInterface $input, OutputInterface $output): int
73118
$output->writeln(\str_repeat('=', \strlen($banner)));
74119
$output->writeln('');
75120

76-
$access = ['public', 'protected', 'private'];
77-
$skipMixedTypesAsError = false;
78-
$skipDeprecatedMethods = false;
79-
$skipFunctionsWithLeadingUnderscore = false;
80-
81121
$errors = \voku\SimplePhpParser\Parsers\PhpCodeChecker::checkPhpFiles(
82122
$realPath,
83123
$access,
84124
$skipMixedTypesAsError,
85-
$skipDeprecatedMethods,
125+
$skipDeprecatedFunctions,
86126
$skipFunctionsWithLeadingUnderscore,
127+
$skipParseErrorsAsError,
87128
$this->composerAutoloaderProjectPaths
88129
);
89130

131+
$errorCount = 0;
90132
foreach ($errors as $file => $errorsInner) {
91-
$output->writeln('<file>' . $file . '</file>');
133+
$errorCountFile = \count($errorsInner);
134+
$errorCount += $errorCountFile;
135+
136+
$output->writeln('<file>' . $file . '</file>' . ' (' . $errorCountFile . ' errors)');
92137

93138
foreach ($errorsInner as $errorInner) {
94139
$output->writeln('<error>' . $errorInner . '</error>');
@@ -98,6 +143,10 @@ public function execute(InputInterface $input, OutputInterface $output): int
98143
$output->writeln('');
99144
}
100145

146+
$output->writeln('-------------------------------');
147+
$output->writeln($errorCount . ' errors in ' . \count($errors) . ' files.');
148+
$output->writeln('-------------------------------');
149+
101150
return 0;
102151
}
103152
}

src/voku/SimplePhpParser/Model/BasePHPElement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public function __construct($parserContainer)
5757
abstract public function readObjectFromBetterReflection($object);
5858

5959
/**
60-
* @param NodeAbstract $mixed_1
61-
* @param NodeAbstract|null $mixed_2
60+
* @param \PhpParser\NodeAbstract $mixed_1
61+
* @param \PhpParser\NodeAbstract|null $mixed_2
6262
*
6363
* @return $this
6464
*/
@@ -85,7 +85,7 @@ protected function getConstantFQN(NodeAbstract $node, string $nodeName): string
8585
*
8686
* @psalm-suppress MoreSpecificReturnType or Less ?
8787
*/
88-
protected function getFQN($node): string
88+
protected static function getFQN($node): string
8989
{
9090
// init
9191
$fqn = '';
@@ -110,7 +110,7 @@ protected function getFQN($node): string
110110
}
111111

112112
/**
113-
* @param Node $node
113+
* @param \PhpParser\Node $node
114114
*
115115
* @return void
116116
*/

src/voku/SimplePhpParser/Model/PHPClass.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ public function readObjectFromPhpNode($node, $dummy = null): self
4141
{
4242
$this->prepareNode($node);
4343

44-
$this->name = $this->getFQN($node);
44+
$this->name = static::getFQN($node);
4545

4646
/** @noinspection NotOptimalIfConditionsInspection */
47+
/** @noinspection ArgumentEqualsDefaultValueInspection */
4748
if (\class_exists($this->name, true)) {
4849
$reflectionClass = ReflectionClass::createFromName($this->name);
4950
$this->readObjectFromBetterReflection($reflectionClass);
@@ -331,9 +332,7 @@ private function readPhpDocProperties(string $docComment): void
331332
}
332333

333334
$typeTmp = Utils::parseDocTypeObject($type);
334-
if (\is_array($typeTmp) && \count($typeTmp) > 0) {
335-
$propertyPhp->typeFromPhpDocSimple = \implode('|', $typeTmp);
336-
} elseif (\is_string($typeTmp)) {
335+
if ($typeTmp !== '') {
337336
$propertyPhp->typeFromPhpDocSimple = $typeTmp;
338337
}
339338

src/voku/SimplePhpParser/Model/PHPConst.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function readObjectFromPhpNode($node, $dummy = null): self
5151
$this->collectTags($node);
5252

5353
if ($node->getAttribute('parent') instanceof ClassConst) {
54-
$this->parentName = $this->getFQN($node->getAttribute('parent')->getAttribute('parent'));
54+
$this->parentName = static::getFQN($node->getAttribute('parent')->getAttribute('parent'));
5555
}
5656

5757
return $this;

src/voku/SimplePhpParser/Model/PHPDocElement.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,43 @@
44

55
namespace voku\SimplePhpParser\Model;
66

7-
use phpDocumentor\Reflection\DocBlock\Tag;
87
use PhpParser\Node;
98
use voku\SimplePhpParser\Parsers\Helper\DocFactoryProvider;
109

1110
trait PHPDocElement
1211
{
1312
/**
14-
* @var Tag[]
13+
* @var \phpDocumentor\Reflection\DocBlock\Tag[]
1514
*/
1615
public $linkTags = [];
1716

1817
/**
19-
* @var Tag[]
18+
* @var \phpDocumentor\Reflection\DocBlock\Tag[]
2019
*/
2120
public $seeTags = [];
2221

2322
/**
24-
* @var Tag[]
23+
* @var \phpDocumentor\Reflection\DocBlock\Tag[]
2524
*/
2625
public $sinceTags = [];
2726

2827
/**
29-
* @var Tag[]
28+
* @var \phpDocumentor\Reflection\DocBlock\Tag[]
3029
*/
3130
public $deprecatedTags = [];
3231

3332
/**
34-
* @var Tag[]
33+
* @var \phpDocumentor\Reflection\DocBlock\Tag[]
3534
*/
3635
public $metaTags = [];
3736

3837
/**
39-
* @var Tag[]
38+
* @var \phpDocumentor\Reflection\DocBlock\Tag[]
4039
*/
4140
public $internalTags = [];
4241

4342
/**
44-
* @var Tag[]
43+
* @var \phpDocumentor\Reflection\DocBlock\Tag[]
4544
*/
4645
public $removedTags = [];
4746

@@ -86,7 +85,7 @@ trait PHPDocElement
8685
public $hasRemovedTag = false;
8786

8887
/**
89-
* @param Node $node
88+
* @param \PhpParser\Node $node
9089
*
9190
* @return void
9291
*/

0 commit comments

Comments
 (0)