Skip to content

Commit

Permalink
Bleeding edge - OverridingPropertyRule
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 18, 2021
1 parent 9395ecf commit 0f4885a
Show file tree
Hide file tree
Showing 11 changed files with 507 additions and 19 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"nette/neon": "^3.0",
"nette/schema": "^1.0",
"nette/utils": "^3.1.3",
"nikic/php-parser": "4.12.0",
"nikic/php-parser": "dev-master as 4.12.0",
"ondram/ci-detector": "^3.4.0",
"ondrejmirtes/better-reflection": "4.3.64",
"ondrejmirtes/better-reflection": "4.3.65",
"phpstan/php-8-stubs": "^0.1.22",
"phpstan/phpdoc-parser": "^0.5.5",
"react/child-process": "^0.6.1",
Expand Down
39 changes: 24 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions conf/bleedingEdge.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ parameters:
finalByPhpDocTag: true
classConstants: true
privateStaticCall: true
overridingProperty: true
stubFiles:
- ../stubs/arrayFunctions.stub
7 changes: 7 additions & 0 deletions conf/config.level0.neon
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ conditionalTags:
phpstan.rules.rule: %featureToggles.fileWhitespace%
PHPStan\Rules\Properties\UninitializedPropertyRule:
phpstan.rules.rule: %checkUninitializedProperties%
PHPStan\Rules\Properties\OverridingPropertyRule:
phpstan.rules.rule: %featureToggles.overridingProperty%

parametersSchema:
missingClosureNativeReturnCheckObjectTypehint: bool()
Expand Down Expand Up @@ -213,6 +215,11 @@ services:
checkClassCaseSensitivity: %checkClassCaseSensitivity%
checkThisOnly: %checkThisOnly%

-
class: PHPStan\Rules\Properties\OverridingPropertyRule
arguments:
checkPhpDocMethodSignatures: %checkPhpDocMethodSignatures%

-
class: PHPStan\Rules\Properties\UninitializedPropertyRule
arguments:
Expand Down
4 changes: 3 additions & 1 deletion conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ parameters:
finalByPhpDocTag: false
classConstants: false
privateStaticCall: false
overridingProperty: false
fileExtensions:
- php
checkAlwaysTrueCheckTypeFunctionCall: false
Expand Down Expand Up @@ -229,7 +230,8 @@ parametersSchema:
crossCheckInterfaces: bool(),
finalByPhpDocTag: bool(),
classConstants: bool(),
privateStaticCall: bool()
privateStaticCall: bool(),
overridingProperty: bool()
])
fileExtensions: listOf(string())
checkAlwaysTrueCheckTypeFunctionCall: bool()
Expand Down
5 changes: 5 additions & 0 deletions src/Node/ClassPropertyNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public function isStatic(): bool
return (bool) ($this->flags & Class_::MODIFIER_STATIC);
}

public function isReadOnly(): bool
{
return (bool) ($this->flags & Class_::MODIFIER_READONLY);
}

/**
* @return Identifier|Name|NullableType|UnionType|null
*/
Expand Down
14 changes: 14 additions & 0 deletions src/Reflection/Php/PhpPropertyReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ public function isPublic(): bool
return $this->reflection->isPublic();
}

public function isReadOnly(): bool
{
if (method_exists($this->reflection, 'isReadOnly')) {
return $this->reflection->isReadOnly();
}

return false;
}

public function getReadableType(): Type
{
if ($this->type === null) {
Expand Down Expand Up @@ -149,6 +158,11 @@ public function getPhpDocType(): Type
return new MixedType();
}

public function hasNativeType(): bool
{
return $this->nativeType !== null;
}

public function getNativeType(): Type
{
if ($this->finalNativeType === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/PhpDoc/IncompatiblePropertyPhpDocTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array
$propertyName = $node->getName();
$propertyReflection = $scope->getClassReflection()->getNativeProperty($propertyName);

if (!$propertyReflection->hasPhpDoc()) {
if (!$propertyReflection->hasPhpDocType()) {
return [];
}

Expand Down
Loading

0 comments on commit 0f4885a

Please sign in to comment.