Skip to content

Commit

Permalink
Add config option to exclude mixin classes
Browse files Browse the repository at this point in the history
  • Loading branch information
canvural authored and ondrejmirtes committed May 7, 2020
1 parent b58d311 commit b5a6597
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ parameters:
reportMaybes: false
reportMaybesInMethodSignatures: false
reportStaticMethodSignatures: false
mixinExcludeClasses: []
parallel:
jobSize: 20
processTimeout: 60.0
Expand Down Expand Up @@ -215,6 +216,7 @@ parametersSchema:
tmpDir: string()
currentWorkingDirectory: string()
cliArgumentsVariablesRegistered: bool()
mixinExcludeClasses: listOf(string())

# irrelevant Nette parameters
debugMode: bool()
Expand Down Expand Up @@ -480,11 +482,15 @@ services:
class: PHPStan\Reflection\Mixin\MixinMethodsClassReflectionExtension
tags:
- phpstan.broker.methodsClassReflectionExtension
arguments:
mixinExcludeClasses: %mixinExcludeClasses%

-
class: PHPStan\Reflection\Mixin\MixinPropertiesClassReflectionExtension
tags:
- phpstan.broker.propertiesClassReflectionExtension
arguments:
mixinExcludeClasses: %mixinExcludeClasses%

-
class: PHPStan\Reflection\Php\PhpClassReflectionExtension
Expand Down
16 changes: 16 additions & 0 deletions src/Reflection/Mixin/MixinMethodsClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\MethodsClassReflectionExtension;
use PHPStan\Type\TypeUtils;

class MixinMethodsClassReflectionExtension implements MethodsClassReflectionExtension
{

/** @var string[] */
private $mixinExcludeClasses;

/**
* @param string[] $mixinExcludeClasses
*/
public function __construct(array $mixinExcludeClasses)
{
$this->mixinExcludeClasses = $mixinExcludeClasses;
}

public function hasMethod(ClassReflection $classReflection, string $methodName): bool
{
return $this->findMethod($classReflection, $methodName) !== null;
Expand All @@ -29,6 +41,10 @@ private function findMethod(ClassReflection $classReflection, string $methodName
{
$mixinTypes = $classReflection->getResolvedMixinTypes();
foreach ($mixinTypes as $type) {
if (count(array_intersect(TypeUtils::getDirectClassNames($type), $this->mixinExcludeClasses)) > 0) {
continue;
}

if (!$type->hasMethod($methodName)->yes()) {
continue;
}
Expand Down
16 changes: 16 additions & 0 deletions src/Reflection/Mixin/MixinPropertiesClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Type\TypeUtils;

class MixinPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension
{

/** @var string[] */
private $mixinExcludeClasses;

/**
* @param string[] $mixinExcludeClasses

This comment has been minimized.

Copy link
@clxmstaab

clxmstaab May 7, 2020

Contributor

could this be something like class-string[]?

This comment has been minimized.

Copy link
@ondrejmirtes

ondrejmirtes May 7, 2020

Member

It could but it doesn't matter much here, the constructor is called in DIC which isn't analysed code.

*/
public function __construct(array $mixinExcludeClasses)
{
$this->mixinExcludeClasses = $mixinExcludeClasses;
}

public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
{
return $this->findProperty($classReflection, $propertyName) !== null;
Expand All @@ -29,6 +41,10 @@ private function findProperty(ClassReflection $classReflection, string $property
{
$mixinTypes = $classReflection->getResolvedMixinTypes();
foreach ($mixinTypes as $type) {
if (count(array_intersect(TypeUtils::getDirectClassNames($type), $this->mixinExcludeClasses)) > 0) {
continue;
}

if (!$type->hasProperty($propertyName)->yes()) {
continue;
}
Expand Down

0 comments on commit b5a6597

Please sign in to comment.