-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: fix PHPStan errors #9125
base: develop
Are you sure you want to change the base?
Changes from all commits
0d0cb9c
ee45f02
8d5e76f
545dd43
0123877
7a42176
41adadc
b9406ba
643a45c
a8cf541
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,10 +145,10 @@ public function getClassname(string $file): string | |
|
||
if ((isset($tokens[$i - 2][1]) && ($tokens[$i - 2][1] === 'phpnamespace' || $tokens[$i - 2][1] === 'namespace')) || ($dlm && $tokens[$i - 1][0] === T_NS_SEPARATOR && $token[0] === T_STRING)) { | ||
if (! $dlm) { | ||
$namespace = 0; | ||
$namespace = ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why the original code is Please make another PR to fix this issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After changing 151 line in this file it's failing:
|
||
} | ||
if (isset($token[1])) { | ||
$namespace = $namespace ? $namespace . '\\' . $token[1] : $token[1]; | ||
$namespace = $namespace !== '' ? $namespace . '\\' . $token[1] : $token[1]; | ||
$dlm = true; | ||
} | ||
} elseif ($dlm && ($token[0] !== T_NS_SEPARATOR) && ($token[0] !== T_STRING)) { | ||
|
@@ -194,8 +194,9 @@ public function search(string $path, string $ext = 'php', bool $prioritizeApp = | |
|
||
foreach ($this->getNamespaces() as $namespace) { | ||
if (isset($namespace['path']) && is_file($namespace['path'] . $path)) { | ||
$fullPath = $namespace['path'] . $path; | ||
$fullPath = realpath($fullPath) ?: $fullPath; | ||
$fullPath = ($realPath = realpath($namespace['path'] . $path)) !== false | ||
? $realPath | ||
: ($namespace['path'] . $path); | ||
|
||
if ($prioritizeApp) { | ||
$foundPaths[] = $fullPath; | ||
|
@@ -272,14 +273,14 @@ protected function getNamespaces() | |
*/ | ||
public function findQualifiedNameFromPath(string $path) | ||
{ | ||
$path = realpath($path) ?: $path; | ||
$path = ($realPath = realpath($path)) !== false ? $realPath : $path; | ||
|
||
if (! is_file($path)) { | ||
return false; | ||
} | ||
|
||
foreach ($this->getNamespaces() as $namespace) { | ||
$namespace['path'] = realpath($namespace['path']) ?: $namespace['path']; | ||
$namespace['path'] = ($realPath = realpath($namespace['path'])) !== false ? $realPath : $namespace['path']; | ||
|
||
if ($namespace['path'] === '') { | ||
continue; | ||
|
@@ -331,8 +332,9 @@ public function listFiles(string $path): array | |
helper('filesystem'); | ||
|
||
foreach ($this->getNamespaces() as $namespace) { | ||
$fullPath = $namespace['path'] . $path; | ||
$fullPath = realpath($fullPath) ?: $fullPath; | ||
$fullPath = ($realPath = realpath($namespace['path'] . $path)) !== false | ||
? $realPath | ||
: ($namespace['path'] . $path); | ||
|
||
if (! is_dir($fullPath)) { | ||
continue; | ||
|
@@ -366,7 +368,7 @@ public function listNamespaceFiles(string $prefix, string $path): array | |
// autoloader->getNamespace($prefix) returns an array of paths for that namespace | ||
foreach ($this->autoloader->getNamespace($prefix) as $namespacePath) { | ||
$fullPath = rtrim($namespacePath, '/') . '/' . $path; | ||
$fullPath = realpath($fullPath) ?: $fullPath; | ||
$fullPath = ($realPath = realpath($fullPath)) !== false ? $realPath : $fullPath; | ||
|
||
if (! is_dir($fullPath)) { | ||
continue; | ||
|
@@ -393,7 +395,7 @@ public function listNamespaceFiles(string $prefix, string $path): array | |
protected function legacyLocate(string $file, ?string $folder = null) | ||
{ | ||
$path = APPPATH . ($folder === null ? $file : $folder . '/' . $file); | ||
$path = realpath($path) ?: $path; | ||
$path = ($realPath = realpath($path)) !== false ? $realPath : $path; | ||
|
||
if (is_file($path)) { | ||
return $path; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix phpstan error:
Call to function method_exists() with 'Composer\InstalledVersions' and 'getAllRawData' will always evaluate to true.
But I think, that better way will be to remove this check and check composer version during
composer install
andcomposer update
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I got why. But your code seems to take time more.
The PHPStan error is inevitable. Because we use the latest
composer
command.So I think the error should be suppressed by
@phpstan-ignore-next-line
or@phpstan-ignore-line
.