Skip to content

Commit f4a896a

Browse files
authored
Merge pull request #38 from bigcommerce/microopt
Micro-optimisations to ClassInspector and ParameterInspector
2 parents 249643b + 17712ad commit f4a896a

3 files changed

Lines changed: 7 additions & 12 deletions

File tree

.phpstan/baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ parameters:
120120
count: 1
121121
path: ../src/InjectorServiceProvider.php
122122

123-
-
124-
message: '#^Call to an undefined method ReflectionType\:\:getName\(\)\.$#'
125-
identifier: method.notFound
126-
count: 1
127-
path: ../src/Reflection/ParameterInspector.php
128-
129123
-
130124
message: '#^Method Bigcommerce\\Injector\\Reflection\\ParameterInspector\:\:getMethodSignature\(\) has parameter \$refClass with generic class ReflectionClass but does not specify its types\: T$#'
131125
identifier: missingType.generics

src/Reflection/ClassInspector.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ public function getStats(): ClassInspectorStats
7373
*/
7474
private function getReflectionClass(string $class): ReflectionClass
7575
{
76-
if ($this->reflectionClassCache->has($class)) {
77-
$reflectionClass = $this->reflectionClassCache->get($class);
78-
} else {
76+
$reflectionClass = $this->reflectionClassCache->get($class);
77+
if ($reflectionClass === null) {
7978
$reflectionClass = new ReflectionClass($class);
8079
$this->stats->incrementReflectionClassesCreated();
8180
$this->reflectionClassCache->put($reflectionClass);

src/Reflection/ParameterInspector.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Bigcommerce\Injector\Reflection;
33

4+
use ReflectionNamedType;
5+
46
/**
57
* The ParameterInspector exposes cached reflection of a methods signature enabling auto-wiring of dependencies within
68
* the Injector. This class does expose the \ReflectionParameter or utilise Parameter value objects but
@@ -64,7 +66,7 @@ private function getMethodSignature($className, $methodName, ?\ReflectionClass $
6466
"name" => $name
6567
];
6668
$type = $parameter->getType();
67-
if ($type && method_exists($type, 'isBuiltin') && !$type->isBuiltin()) {
69+
if ($type instanceof ReflectionNamedType && !$type->isBuiltin()) {
6870
$parameterSignature['type'] = $type->getName();
6971
}
7072
if ($parameter->isDefaultValueAvailable()) {
@@ -77,8 +79,8 @@ private function getMethodSignature($className, $methodName, ?\ReflectionClass $
7779
$methodSignature[] = $parameterSignature;
7880
}
7981
} catch (\ReflectionException $e) {
80-
//The requested method doesn't exist on this class. Check if the class provides a magic call method or die.
81-
if (!method_exists($className, "__call")) {
82+
// The requested method doesn't exist on this class. Check if the class provides a magic call method or die.
83+
if (!$refClass->hasMethod("__call")) {
8284
throw $e;
8385
}
8486
}

0 commit comments

Comments
 (0)