Skip to content

Commit 2ebcbef

Browse files
committed
[+]: fixes found by the project itself
1 parent b0ef16a commit 2ebcbef

File tree

7 files changed

+47
-16
lines changed

7 files changed

+47
-16
lines changed

src/voku/SimplePhpParser/Model/PHPClass.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ public function readObjectFromPhpNode($node, $dummy = null): self
6464

6565
$docComment = $node->getDocComment();
6666
if ($docComment) {
67-
$propertiesPhp = $this->readPhpDocProperties($docComment->getText());
68-
foreach ($propertiesPhp as $propertyPhp) {
69-
$this->properties[$propertyPhp->name] = $propertyPhp;
70-
}
67+
$this->readPhpDocProperties($docComment->getText());
7168
}
7269

7370
foreach ($node->getProperties() as $property) {
@@ -284,13 +281,13 @@ public function getMethodsInfo(
284281
/**
285282
* @param string $docComment
286283
*
287-
* @return PHPProperty[]
284+
* @return void
288285
*/
289-
private function readPhpDocProperties(string $docComment): array
286+
private function readPhpDocProperties(string $docComment): void
290287
{
291-
// init
292-
/** @var PHPProperty[] $classPhpDocProperties */
293-
$classPhpDocProperties = [];
288+
if ($docComment === '') {
289+
return;
290+
}
294291

295292
try {
296293
$phpDoc = Utils::createDocBlockInstance()->create($docComment);
@@ -345,15 +342,13 @@ private function readPhpDocProperties(string $docComment): array
345342
$propertyPhp->typeFromPhpDocPslam = (string) @\Psalm\Type::parseString($propertyPhp->typeFromPhpDoc);
346343
}
347344

348-
$classPhpDocProperties[$propertyPhp->name] = $propertyPhp;
345+
$this->properties[$propertyPhp->name] = $propertyPhp;
349346
}
350347
}
351348
}
352349
} catch (\Exception $e) {
353350
$tmpErrorMessage = $this->name . ':' . ($this->line ?? '') . ' | ' . \print_r($e->getMessage(), true);
354351
$this->parseError[\md5($tmpErrorMessage)] = $tmpErrorMessage;
355352
}
356-
357-
return $classPhpDocProperties;
358353
}
359354
}

src/voku/SimplePhpParser/Model/PHPFunction.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ protected function readObjectFromBetterReflectionReturnHelper($function): ?strin
195195

196196
protected function readPhpDoc(string $docComment): void
197197
{
198+
if ($docComment === '') {
199+
return;
200+
}
201+
198202
try {
199203
$phpDoc = Utils::createDocBlockInstance()->create($docComment);
200204

src/voku/SimplePhpParser/Model/PHPParameter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ private function readObjectFromBetterReflectionParamHelper($parameter): ?string
230230

231231
private function readPhpDoc(string $docComment, string $parameterName): void
232232
{
233+
if ($docComment === '') {
234+
return;
235+
}
236+
233237
try {
234238
$phpDoc = Utils::createDocBlockInstance()->create($docComment);
235239

src/voku/SimplePhpParser/Model/PHPProperty.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ private function readObjectFromBetterReflectionVarHelper(ReflectionProperty $pro
235235

236236
private function readPhpDoc(string $docComment): void
237237
{
238+
if ($docComment === '') {
239+
return;
240+
}
241+
238242
try {
239243
$phpDoc = Utils::createDocBlockInstance()->create($docComment);
240244

src/voku/SimplePhpParser/Parsers/Helper/Utils.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public static function flattenArray(array $arr, bool $group): array
2626
/**
2727
* @param \phpDocumentor\Reflection\DocBlock\Tags\BaseTag $parsedParamTag
2828
*
29-
* @return array{parsedParamTagStr: string, variableName: null|string}
29+
* @return array
30+
*
31+
* @paalm-return array{parsedParamTagStr: string, variableName: null|string}
3032
*/
3133
public static function splitTypeAndVariable(
3234
\phpDocumentor\Reflection\DocBlock\Tags\BaseTag $parsedParamTag

src/voku/SimplePhpParser/Parsers/PhpCodeChecker.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function checkFromString(
2828
* @param string[] $access
2929
* @param bool $skipDeprecatedMethods
3030
* @param bool $skipFunctionsWithLeadingUnderscore
31-
* @pram string[] $composerAutoloaderProjectPaths
31+
* @param string[] $composerAutoloaderProjectPaths
3232
*
3333
* @return string[][]
3434
*/
@@ -40,7 +40,10 @@ public static function checkPhpFiles(
4040
bool $skipFunctionsWithLeadingUnderscore = false,
4141
array $composerAutoloaderProjectPaths = []
4242
): array {
43-
$phpInfo = PhpCodeParser::getPhpFiles($path, $composerAutoloaderProjectPaths);
43+
$phpInfo = PhpCodeParser::getPhpFiles(
44+
$path,
45+
$composerAutoloaderProjectPaths
46+
);
4447

4548
$errors = $phpInfo->getParseErrors();
4649

src/voku/SimplePhpParser/Parsers/PhpCodeParser.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,25 @@ public static function getPhpFiles(
8484
$interface->parentInterfaces = $visitor->combineParentInterfaces($interface);
8585
}
8686

87+
$pathTmp = null;
88+
if (\is_file($pathOrCode)) {
89+
$pathTmp = \realpath(\pathinfo($pathOrCode, \PATHINFO_DIRNAME));
90+
} elseif (\is_dir($pathOrCode)) {
91+
$pathTmp = \realpath($pathOrCode);
92+
}
93+
8794
$classes = $parserContainer->getClasses();
8895
foreach ($classes as &$class) {
96+
97+
// remove methods from outside of the current file-path-scope
98+
if ($pathTmp) {
99+
foreach ($class->methods as $methodKey => $method) {
100+
if (strpos($method->file, $pathTmp) === false) {
101+
unset($class->methods[$methodKey]);
102+
}
103+
}
104+
}
105+
89106
$class->interfaces = Utils::flattenArray(
90107
$visitor->combineImplementedInterfaces($class),
91108
false
@@ -190,7 +207,9 @@ public static function process(
190207
* @param string $fileName
191208
* @param Cache $cache
192209
*
193-
* @return array{content: string, fileName: string, cacheKey: string}
210+
* @return array
211+
*
212+
* @psalm-return array{content: string, fileName: string, cacheKey: string}
194213
*
195214
* @internal
196215
*/

0 commit comments

Comments
 (0)