Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 1, 2021
1 parent 347fc74 commit ca7e9ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ public function getNativeMethod(string $methodName): MethodReflection
}

/**
* @deprecated Use ClassReflection::getNativeReflection() instead.
* @return MethodReflection[]
*/
public function getNativeMethods(): array
Expand Down
7 changes: 2 additions & 5 deletions src/Rules/Methods/MissingMethodImplementationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@ public function processNode(Node $node, Scope $scope): array
$messages = [];

try {
$nativeMethods = $classReflection->getNativeMethods();
$nativeMethods = $classReflection->getNativeReflection()->getMethods();
} catch (IdentifierNotFound $e) {
return [];
}
foreach ($nativeMethods as $method) {
if (!method_exists($method, 'isAbstract')) {
continue;
}
if (!$method->isAbstract()) {
continue;
}
Expand All @@ -52,7 +49,7 @@ public function processNode(Node $node, Scope $scope): array
$classReflection->getDisplayName(),
$method->getName(),
$declaringClass->isInterface() ? 'interface' : 'class',
$declaringClass->getDisplayName()
$declaringClass->getName()
))->nonIgnorable()->build();
}

Expand Down
27 changes: 16 additions & 11 deletions src/Rules/Properties/UninitializedPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,28 @@ private function getConstructors(ClassReflection $classReflection): array
$constructors[] = $classReflection->getConstructor()->getName();
}

$nativeReflection = $classReflection->getNativeReflection();
foreach ($this->additionalConstructors as $additionalConstructor) {
[$className, $methodName] = explode('::', $additionalConstructor);
foreach ($classReflection->getNativeMethods() as $nativeMethod) {
if ($nativeMethod->getName() !== $methodName) {
continue;
}
if ($nativeMethod->getDeclaringClass()->getName() !== $classReflection->getName()) {
continue;
}
if (!$nativeReflection->hasMethod($methodName)) {
continue;
}
$nativeMethod = $nativeReflection->getMethod($methodName);
if ($nativeMethod->getDeclaringClass()->getName() !== $nativeReflection->getName()) {
continue;
}

try {
$prototype = $nativeMethod->getPrototype();
if ($prototype->getDeclaringClass()->getName() !== $className) {
continue;
}
} catch (\ReflectionException $e) {
$prototype = $nativeMethod;
}

$constructors[] = $methodName;
if ($prototype->getDeclaringClass()->getName() !== $className) {
continue;
}

$constructors[] = $methodName;
}

$this->additionalConstructorsCache[$classReflection->getName()] = $constructors;
Expand Down

0 comments on commit ca7e9ef

Please sign in to comment.