-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Scrutinizer fixes #76
Changes from 4 commits
8de7f8c
294ea1e
7dbdc50
6d26c55
37c2244
ef64e04
266f378
295b2da
98cfabb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,9 @@ class ReflectionFile | |
*/ | ||
public function __construct($fileName, $topLevelNodes = null) | ||
{ | ||
if (!is_string($fileName)) { | ||
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. It seems, that you've started to change more code. I'd recommend doing this in another PRs. 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. This was a change from my original commit from July 3rd before I ever issued this PR. I'm slightly confused. 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. Interesting. I've reviewed only changes that Scrutinizer CI reported as fixes to existing issues. Probably this change fixed nothing of Scrutinizer CI reported bugs. In either case I think it's too much to check filename to be a string. Likely nobody would be crazy enough to pass non-string in there. 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. The only reason I made this addition was that it was flagged by Scrutinizer:
I think this based on type variations in the calling functions, despite this function only ever being called with string. I expect the other change that might fix this is isolating the parameter into a distinct, string-only variable that is used when calling this method. I think this type check is the easier solution. 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. Then better to:
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. The purpose of this PR was to address the Scrutinizer issues. This does that and it was in the PR from the beginning. I'm confused why this is suddenly an issue? Let me investigate the calling code to see if that is more easily addressed than this. I'll get back to you. 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.
The Scrutinizer CI told that multiple types could come in and you've restricted to type check instead of actually investigating places from where multiple types could come in and deciding on fixing these places instead. This could be a lots of changes and that's why I've suggested another PR. P.S. 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. Ok... I searched the code, and (outside of 👎 Keeping change in PR pending @lisachenko's approval. 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. Enforcing something, that will never happen would only slow down whole code checking process. For that reason I'd rather not check unless somebody stumbles upon this and reports it. 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. Let's keep it then. I hope this won't be a performance issue. |
||
throw new \InvalidArgumentException(sprintf('$fileName must be a string, but a %s was passed', gettype($fileName))); | ||
} | ||
$fileName = PathResolver::realpath($fileName); | ||
$this->fileName = $fileName; | ||
$this->topLevelNodes = $topLevelNodes ?: ReflectionEngine::parseFile($fileName); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,9 @@ class ReflectionFileNamespace | |
*/ | ||
public function __construct($fileName, $namespaceName, Namespace_ $namespaceNode = null) | ||
{ | ||
if (!is_string($fileName)) { | ||
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. It seems, that you've started to change more code. I'd recommend doing this in another PRs. 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. This was a change from my original commit from July 3rd before I ever issued this PR. I'm slightly confused. 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. Interesting. I've reviewed only changes that Scrutinizer CI reported as fixes to existing issues. Probably this change fixed nothing of Scrutinizer CI reported bugs. In either case I think it's too much to check filename to be a string. Likely nobody would be crazy enough to pass non-string in there. 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. The only reason I made this addition was that it was flagged by Scrutinizer:
(Same comment as above) 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. Then better to:
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. While there are 3 places in the code where 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. What is the 3rd place, can you post a link to that code line? If total call count in that 3rd place is much smaller than sum of other 2 places, then from performance point it would be better to type cast before calling this method instead of checking in constructor. Same is valid for other similar place. 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. Ok... I'm happy to show you the three places that call this constructor, but the fact that you're asking indicates a failure to communicate on my part. I apologize for being unclear. Here are the 3 places that call this constructor: .../parser-reflection/src/ReflectionFile.php: 153 $namespaceName = $topLevelNode->name ? $topLevelNode->name->toString() : '';
154
155: $namespaces[$namespaceName] = new ReflectionFileNamespace(
156 $this->fileName,
157 $namespaceName, .../parser-reflection/src/ValueResolver/NodeExpressionResolver.php: 231 $fileName = $this->context->getFileName();
232 $namespaceName = $this->resolveScalarMagicConstNamespace();
233: $fileNamespace = new ReflectionFileNamespace($fileName, $namespaceName);
234 if ($fileNamespace->hasConstant($constantName)) {
235 $constantValue = $fileNamespace->getConstant($constantName); 500 $namespaceName = $this->resolveScalarMagicConstNamespace();
501
502: $fileNamespace = new ReflectionFileNamespace($fileName, $namespaceName);
503 return $fileNamespace->getClass($className);
504 } That said, I think this largely misses the point. Let me see if I can clear this up a little bit:
So, your choices are:
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. 1 - keep. If we try to imagine real life examples, then 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. Thank you for your quick response. I hope to have the final commit pushed this afternoon. |
||
throw new \InvalidArgumentException(sprintf('$fileName must be a string, but a %s was passed', gettype($fileName))); | ||
} | ||
$fileName = PathResolver::realpath($fileName); | ||
if (!$namespaceNode) { | ||
$namespaceNode = ReflectionEngine::parseFileNamespace($fileName, $namespaceName); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ public function ___debugInfo() | |
public function __toString() | ||
{ | ||
$hasReturnType = $this->hasReturnType(); | ||
$returnType = $hasReturnType ? $this->getReturnType() : null; | ||
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. The 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. Good catch 👍 |
||
$paramsNeeded = $hasReturnType || $this->getNumberOfParameters() > 0; | ||
$paramFormat = $paramsNeeded ? "\n\n - Parameters [%d] {%s\n }" : ''; | ||
$returnFormat = $hasReturnType ? "\n - Return [ %s ]" : ''; | ||
|
@@ -114,7 +115,7 @@ public function __toString() | |
$this->getEndLine(), | ||
count($methodParameters), | ||
$paramString, | ||
$hasReturnType ? ReflectionType::convertToDisplayType($this->getReturnType()) : '' | ||
$returnType ? ReflectionType::convertToDisplayType($returnType) : '' | ||
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. 👍 , but also add tests (or post a link in comment if test exists already), that would verify atleast 2 cases:
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. Ok... Good point on adding tests. As I said, needing to untangle a branch first, but: Note to self... Implement/find relevant test cases. 👍 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. Ok... I confirmed that both cases are tested... (I did not flag the specific tests, but they're easy to find.) When |
||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,14 +85,14 @@ public static function convertToDisplayType(\ReflectionType $type) | |
'int' => 'integer', | ||
'bool' => 'boolean' | ||
]; | ||
$displayType = $type->type; | ||
$displayType = (string)$type; | ||
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. 👍 , but a test is needed (or post link to existing test), that would make a call to
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. As above... add tests 👍 |
||
if (isset($typeMap[$displayType])) { | ||
$displayType = $typeMap[$displayType]; | ||
} | ||
|
||
$displayType = ltrim($displayType, '\\'); | ||
|
||
if ($type->allowsNull()) { | ||
if (method_exists($type, 'allowsNull') && $type->allowsNull()) { | ||
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. Please return the original code, because Scrutinizer CI issue in https://scrutinizer-ci.com/g/goaop/parser-reflection/inspections/eaf283f6-f982-44a4-bb28-51489bcba537/issues/files/src/ReflectionType.php?status=fixed&orderField=path&order=asc&honorSelectedPaths=0 likely is reported because they're using incorrect PHP stubs for class method signature resolution. On the PHP docs (see http://php.net/manual/en/reflectiontype.allowsnull.php) there is 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. Hmm... I agree that I should revert this code, but for a different reason. I think this is catching the class definition from the polyfill, which had no 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.
Then I think you need to add stubs in the polyfill class for all 3 methods: http://php.net/manual/en/class.reflectiontype.php 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. Fair enough! :-) 👍 |
||
$displayType .= ' or NULL'; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
namespace Go\ParserReflection\Traits; | ||
|
||
use Go\ParserReflection\ReflectionClass; | ||
use ReflectionClass as BaseReflectionClass; | ||
use Go\ParserReflection\ReflectionException; | ||
use Go\ParserReflection\ReflectionMethod; | ||
use Go\ParserReflection\ReflectionProperty; | ||
|
@@ -442,7 +443,7 @@ public function getParentClass() | |
$extendsNode = $hasExtends ? $this->classLikeNode->$extendsField : null; | ||
if ($extendsNode instanceof FullyQualified) { | ||
$extendsName = $extendsNode->toString(); | ||
$parentClass = class_exists($extendsName, false) ? new parent($extendsName) : new static($extendsName); | ||
$parentClass = class_exists($extendsName, false) ? new BaseReflectionClass($extendsName) : new ReflectionClass($extendsName); | ||
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. Please revert, because Scrutinizer CI seem to incorrectly tracked trait usage in https://scrutinizer-ci.com/g/goaop/parser-reflection/inspections/eaf283f6-f982-44a4-bb28-51489bcba537/issues/files/src/Traits/ReflectionClassLikeTrait.php?status=fixed&orderField=path&order=asc&honorSelectedPaths=0. The original code doesn't have any issues. 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. Hmm... Here I'm a bit torn here:
@aik099, for now, I think the best solution is a method in the using class to return the newly created objects. What do you think? 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. Fact, that trait is used only once and seems like it would be for a long time (unless PHP decides to reflect class/interface/trait using different reflection classes) is a problem that I think needs to be solved. If we inline trait (copy trait code into the only class using it and drop trait), then problem should go away by itself. This is a major change however (even though not a BC break) and likely a @lisachenko approval is required before making such change. Actually better to move it out into PR of it's own. 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 was only really suggesting adding a |
||
} | ||
$this->parentClass = $parentClass; | ||
} | ||
|
@@ -698,8 +699,16 @@ public function isInstance($object) | |
} | ||
|
||
$className = $this->getName(); | ||
|
||
return $className === get_class($object) || is_subclass_of($object, $className); | ||
$objClass = get_class($object); | ||
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. Please revert because Scrutinizer CI report (see https://scrutinizer-ci.com/g/goaop/parser-reflection/inspections/eaf283f6-f982-44a4-bb28-51489bcba537/issues/files/src/Traits/ReflectionClassLikeTrait.php?status=fixed&orderField=path&order=asc&honorSelectedPaths=0) mentions https://bugs.php.net/bug.php?id=53727 bug, which was fixed in PHP 5.3 and PHP 5.4, but this library has PHP 5.5+ as minimum required version. Therefore bug never manifested itself in here. 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. This makes sense... I should check if there's a way to turn off a specific issue check for a whole project. 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. Users with administrative permissions for repo can do it on Scrutinizer CI. 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. marking with 👍 to remind me to revert. |
||
if ($className === $objClass) { | ||
return true; | ||
} | ||
$objClassRef = new BaseReflectionClass($objClass); | ||
if ($objClassRef->isSubclassOf($className)) { | ||
return true; | ||
} | ||
$thisIsInterface = $this->isInterface(); | ||
return $thisIsInterface && $objClassRef->implementsInterface($className); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ protected function resolveScalarString(Scalar\String_ $node) | |
protected function resolveScalarMagicConstMethod() | ||
{ | ||
if ($this->context instanceof \ReflectionMethod) { | ||
$fullName = $this->context->getDeclaringClass()->getName() . '::' . $this->context->getShortName(); | ||
$fullName = $this->context->class . '::' . $this->context->getShortName(); | ||
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. The suggestion in Scrutinizer CI inspection (see https://scrutinizer-ci.com/g/goaop/parser-reflection/inspections/eaf283f6-f982-44a4-bb28-51489bcba537/issues/files/src/ValueResolver/NodeExpressionResolver.php?status=fixed&orderField=path&order=asc&honorSelectedPaths=0) seems to be incorrect because mentioned https://bugs.php.net/bug.php?id=61384 PHP bug only affects Knowing that I recommend
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. marking with 👍 to remind me to update. |
||
|
||
return $fullName; | ||
} | ||
|
@@ -175,12 +175,12 @@ protected function resolveScalarMagicConstNamespace() | |
protected function resolveScalarMagicConstClass() | ||
{ | ||
if ($this->context instanceof \ReflectionClass) { | ||
return $this->context->getName(); | ||
return $this->context->name; | ||
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. Looks good. |
||
} | ||
if (method_exists($this->context, 'getDeclaringClass')) { | ||
$declaringClass = $this->context->getDeclaringClass(); | ||
if ($declaringClass instanceof \ReflectionClass) { | ||
return $declaringClass->getName(); | ||
return $declaringClass->name; | ||
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. Looks good. |
||
} | ||
} | ||
|
||
|
@@ -213,7 +213,7 @@ protected function resolveScalarMagicConstLine(MagicConst\Line $node) | |
protected function resolveScalarMagicConstTrait() | ||
{ | ||
if ($this->context instanceof \ReflectionClass && $this->context->isTrait()) { | ||
return $this->context->getName(); | ||
return $this->context->name; | ||
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. Looks good. |
||
} | ||
|
||
return ''; | ||
|
@@ -224,15 +224,14 @@ protected function resolveExprConstFetch(Expr\ConstFetch $node) | |
$constantValue = null; | ||
$isResolved = false; | ||
|
||
/** @var ReflectionFileNamespace|null $fileNamespace */ | ||
$fileNamespace = null; | ||
$isFQNConstant = $node->name instanceof Node\Name\FullyQualified; | ||
$constantName = $node->name->toString(); | ||
|
||
if (!$isFQNConstant) { | ||
if (method_exists($this->context, 'getFileName')) { | ||
$fileName = $this->context->getFileName(); | ||
$namespaceName = $this->resolveScalarMagicConstNamespace(); | ||
/** @var ReflectionFileNamespace $fileNamespace */ | ||
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. You can safely remove this, because IDE can detect type from 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. Agreed... This comment just "came along for the ride" when I moved the variable's initialization. |
||
$fileNamespace = new ReflectionFileNamespace($fileName, $namespaceName); | ||
if ($fileNamespace->hasConstant($constantName)) { | ||
$constantValue = $fileNamespace->getConstant($constantName); | ||
|
@@ -256,7 +255,12 @@ protected function resolveExprConstFetch(Expr\ConstFetch $node) | |
|
||
protected function resolveExprClassConstFetch(Expr\ClassConstFetch $node) | ||
{ | ||
$refClass = $this->fetchReflectionClass($node->class); | ||
$classToReflect = $node->class; | ||
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. Doesn't seem to be related to Scrutinizer CI reported problems. Maybe belongs to separate PR with a description. 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'm not sure why this issue isn't showing up for you, nor why I can't find links to individual Scrutinizer issues, but this is to address the Scrutinizer issue reported for this line that reads:
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. Interesting. So class constant can be an expression. Seem to addition in PHP syntax, that PHP-Parser now supports. In either cases a test for that is needed too. 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. Yes, I know you can do a constant fetch from a class name stored in a variable. I'm unsure what other As far as adding corresponding test cases, I agree, but I was lumping my test changes into a separate PR. (I'm shooting for 100% code coverage, but I've always been a cockeyed optimist.) I can add these tests to this PR after I've untangled my current repo branches. (I don't really want to do a stash right now.) 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've meant const ONE = 1;
class foo {
// As of PHP 5.6.0
const TWO = ONE * 2;
const THREE = ONE + self::TWO;
const SENTENCE = 'The value of THREE is '.self::THREE;
} This way you can create test for that kind of syntax.
The tests for changed code needs to come as part of PR, where that code is changed. Later you can send another PR for improving code coverage. 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 agree we need to test for this case, but it isn't demonstrated in the example above. It would be something like this, which I'm doubting is valid PHP: const LEFT = 'Foo';
const RIGHT = 'Bar';
class FooBar {
const FILENAME = 'baz.php';
}
require((LEFT . RIGHT)::FILENAME); Like I said... I'm unsure if this is valid PHP, but I think, given that PhpParser accepts an expression, and we need something that can evaluate at compile time, something like this would be a valid test, even if not legal PHP currently. Opinions? Thumbing up to remind myself to add test cases. 👍 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. Anything that would force PHP-Parser to create 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. Just for reference: Variation of above sample code on 3v4l.org |
||
if ($classToReflect instanceof Expr) { | ||
$refClass = $this->resolve($classToReflect); | ||
} else { | ||
$refClass = $this->fetchReflectionClass($node->class); | ||
} | ||
$constantName = $node->name; | ||
|
||
// special handling of ::class constants | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,9 @@ | |
use Go\ParserReflection\ReflectionEngine; | ||
|
||
/** | ||
* This file is used for automatic configuration of Go\ParserReflection\ReflectionEngine class | ||
* This file is used for automatic configuration of | ||
* Go\ParserReflection\ReflectionEngine class | ||
*/ | ||
ReflectionEngine::init(new ComposerLocator()); | ||
// Polifyll for PHP<7.0 | ||
if (!class_exists(ReflectionType::class, false)) { | ||
class ReflectionType {} | ||
} | ||
|
||
require(__DIR__ . '/polyfill.php'); | ||
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. It's a fix for https://scrutinizer-ci.com/g/goaop/parser-reflection/inspections/eaf283f6-f982-44a4-bb28-51489bcba537/issues/files/src/bootstrap.php?status=fixed&orderField=path&order=asc&honorSelectedPaths=0 , but I'm not sure it's worth it. Better to reduce file operation count (the 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. Hmm... I think this is a case of minor improvement in PSR-1 compliance for 1 extra small file load once, during execution. I think it's a worthwhile cost... and I think having Polyfills in a file called polyfill.php helps people know where to find them. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* Parser Reflection API | ||
* | ||
* @copyright Copyright 2015, Lisachenko Alexander <[email protected]> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
/** | ||
* This file is for ployfilling classes not defined in all supported | ||
* versions of PHP, (i.e. PHP < 7). | ||
*/ | ||
if (!class_exists(ReflectionType::class, false)) { | ||
class ReflectionType | ||
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. Each class must be in a namespace of at least one level (a top-level vendor name) 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. This is obviously a non-issue for a polyfill class. 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. Each class must be in a namespace of at least one level (a top-level vendor name) 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. Each class must be in a namespace of at least one level (a top-level vendor name) 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. Each class must be in a namespace of at least one level (a top-level vendor name) 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. Each class must be in a namespace of at least one level (a top-level vendor name) 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. Each class must be in a namespace of at least one level (a top-level vendor name) |
||
{ | ||
public function allowsNull() | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
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 is really a failed attempt to fix a false-positive in Scrutinizer. I merely copied the original function docblock from PhpParser. The issue is that Scrutinizer is letting the less specific type hint
array
take precedence over the compatible and more specific@param Node[]
, and saying thatarray
does not satisfy the specification@return null|Node[]
. I expect this change should actually be reverted, but I didn't want to do so without feedback.As far as the false-positive, I'm trying to notify Scrutinizer about it, but haven't gotten any confirmation yet.
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.
Thumbing myself up purely so I remember to revert this change: 👍