-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add attributes to ClassMethod abstraction #93
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7f27040
Create a new getAttribute() method on MethodInterface and implement f…
jongardiner 3bcd0d0
Ansi color when outputting to TTY.
jongardiner 92e429f
Remove a couple of unused variables.
jongardiner db95e2f
Merge branch 'master' into jgardiner/attribute-abstraction
jongardiner d6d1337
Merge branch 'master' into jgardiner/attribute-abstraction
jongardiner bd09d94
Merge remote-tracking branch 'origin/jgardiner/attribute-abstraction'…
jongardiner b618725
Convert getAttributes() to only take an exact name. Built a new util…
jongardiner 9bf0169
Support for "never" as a return type. 8.1
jongardiner 3bd5cfa
Support for "never" as a return type. 8.1
jongardiner badb71a
Support for "never" as a return type. 8.1
jongardiner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace BambooHR\Guardrail\Checks; | ||
|
||
use BambooHR\Guardrail\Output\OutputInterface; | ||
use BambooHR\Guardrail\Scope; | ||
use BambooHR\Guardrail\SymbolTable\SymbolTable; | ||
use BambooHR\Guardrail\TypeComparer; | ||
use PhpParser\Node; | ||
use PhpParser\Node\Stmt\ClassConst; | ||
use PhpParser\Node\Stmt\ClassLike; | ||
|
||
class ClassConstCheck extends BaseCheck { | ||
private $comparer; | ||
function __construct(SymbolTable $symbolTable, OutputInterface $doc) { | ||
parent::__construct($symbolTable, $doc); | ||
$this->comparer=new TypeComparer($symbolTable); | ||
} | ||
|
||
function getCheckNodeTypes() { | ||
return [ClassConst::class]; | ||
} | ||
|
||
function run($fileName, Node $node, ClassLike $inside = null, Scope $scope = null) { | ||
if ($node instanceof ClassConst) { | ||
foreach($node->consts as $const) { | ||
/** @var Node\Const_ $const */ | ||
$constValue = $const->value->getAttribute(TypeComparer::INFERRED_TYPE_ATTR ); | ||
if ($node->type && $constValue) { | ||
if (!$this->comparer->isCompatibleWithTarget($node->type, $constValue, $scope)) { | ||
$this->emitError($fileName, $node, ErrorConstants::TYPE_CONST_TYPE, | ||
"Type mismatch between declared type and constant value " . | ||
TypeComparer::typeToString($node->type) . " vs " . | ||
TypeComparer::typeToString($constValue) | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wouldn't the node here always be an instance of ClassConst?
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.
Yes. I use the if to cast them so that static analyzers will know what we do about the type.