Skip to content

Commit 417254e

Browse files
committed
Various phpinsight fixes
1 parent e921fb4 commit 417254e

File tree

3 files changed

+79
-30
lines changed

3 files changed

+79
-30
lines changed

src/ControllerComponentsExtension.php

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
/**
1313
* Supports discovering models in controllers.
1414
*/
15-
final class ControllerComponentsExtension implements PropertiesClassReflectionExtension
15+
final class ControllerComponentsExtension implements
16+
PropertiesClassReflectionExtension
1617
{
1718
/**
1819
* @var ReflectionProvider
@@ -24,15 +25,36 @@ public function __construct(ReflectionProvider $reflectionProvider)
2425
$this->reflectionProvider = $reflectionProvider;
2526
}
2627

27-
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
28-
{
29-
return $classReflection->is('Controller')
30-
&& $this->reflectionProvider->hasClass($propertyName)
31-
&& $this->reflectionProvider->getClass($propertyName)->is('Component');
28+
public function hasProperty(
29+
ClassReflection $classReflection,
30+
string $propertyName
31+
): bool {
32+
if (! $classReflection->is('Controller')) {
33+
return false;
34+
}
35+
36+
if (! $this->reflectionProvider->hasClass($propertyName)) {
37+
return false;
38+
}
39+
40+
if (
41+
! $this->reflectionProvider
42+
->getClass($propertyName)
43+
->is('Component')
44+
) {
45+
return false;
46+
}
47+
48+
return true;
3249
}
3350

34-
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
35-
{
36-
return new ControllerPropertyReflection($propertyName, $classReflection);
51+
public function getProperty(
52+
ClassReflection $classReflection,
53+
string $propertyName
54+
): PropertyReflection {
55+
return new ControllerPropertyReflection(
56+
$propertyName,
57+
$classReflection
58+
);
3759
}
3860
}

src/ControllerModelsExtension.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
/**
1313
* Supports discovering models in controllers.
1414
*/
15-
final class ControllerModelsExtension implements PropertiesClassReflectionExtension
15+
final class ControllerModelsExtension implements
16+
PropertiesClassReflectionExtension
1617
{
1718
/**
1819
* @var ReflectionProvider
@@ -24,15 +25,22 @@ public function __construct(ReflectionProvider $reflectionProvider)
2425
$this->reflectionProvider = $reflectionProvider;
2526
}
2627

27-
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
28-
{
28+
public function hasProperty(
29+
ClassReflection $classReflection,
30+
string $propertyName
31+
): bool {
2932
return $classReflection->is('Controller')
3033
&& $this->reflectionProvider->hasClass($propertyName)
3134
&& $this->reflectionProvider->getClass($propertyName)->is('Model');
3235
}
3336

34-
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
35-
{
36-
return new ControllerPropertyReflection($propertyName, $classReflection);
37+
public function getProperty(
38+
ClassReflection $classReflection,
39+
string $propertyName
40+
): PropertyReflection {
41+
return new ControllerPropertyReflection(
42+
$propertyName,
43+
$classReflection
44+
);
3745
}
3846
}

src/ModelBehaviorsExtension.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,35 @@ final class ModelBehaviorsExtension implements MethodsClassReflectionExtension
3535
/**
3636
* @param array<string> $behaviorPaths
3737
*/
38-
public function __construct(ReflectionProvider $reflectionProvider, array $behaviorPaths)
39-
{
38+
public function __construct(
39+
ReflectionProvider $reflectionProvider,
40+
array $behaviorPaths
41+
) {
4042
$this->reflectionProvider = $reflectionProvider;
4143
$this->behaviorPaths = $behaviorPaths;
4244
}
4345

44-
public function hasMethod(ClassReflection $classReflection, string $methodName): bool
45-
{
46+
/**
47+
* @throws Exception
48+
*/
49+
public function hasMethod(
50+
ClassReflection $classReflection,
51+
string $methodName
52+
): bool {
4653
return $classReflection->is('Model')
47-
&& in_array($methodName, array_map([$this, 'getMethodReflectionName'], $this->getBehaviorMethods()));
54+
&& in_array(
55+
$methodName,
56+
array_map(
57+
[$this, 'getMethodReflectionName'],
58+
$this->getBehaviorMethods()
59+
)
60+
);
4861
}
4962

50-
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
51-
{
63+
public function getMethod(
64+
ClassReflection $classReflection,
65+
string $methodName
66+
): MethodReflection {
5267
$methodReflections = array_filter(
5368
$this->getBehaviorMethods(),
5469
static function (MethodReflection $methodReflection) use ($methodName) {
@@ -101,8 +116,9 @@ private function getBehaviorMethods(): array
101116
*
102117
* @return array<MethodReflection>
103118
*/
104-
private function getModelBehaviorMethods(ClassReflection $classReflection): array
105-
{
119+
private function getModelBehaviorMethods(
120+
ClassReflection $classReflection
121+
): array {
106122
$methodNames = array_map(
107123
[$this, 'getMethodReflectionName'],
108124
$classReflection->getNativeReflection()->getMethods()
@@ -115,8 +131,9 @@ private function getModelBehaviorMethods(ClassReflection $classReflection): arra
115131
return array_map([$this, 'wrapBehaviorMethod'], $methodReflections);
116132
}
117133

118-
private function filterBehaviorMethods(ExtendedMethodReflection $methodReflection): bool
119-
{
134+
private function filterBehaviorMethods(
135+
ExtendedMethodReflection $methodReflection
136+
): bool {
120137
return $methodReflection->isPublic()
121138
&& ! $methodReflection->isStatic()
122139
&& array_filter(
@@ -125,17 +142,19 @@ private function filterBehaviorMethods(ExtendedMethodReflection $methodReflectio
125142
);
126143
}
127144

128-
private function filterBehaviorMethodVariants(ParametersAcceptor $parametersAcceptor): bool
129-
{
145+
private function filterBehaviorMethodVariants(
146+
ParametersAcceptor $parametersAcceptor
147+
): bool {
130148
$parameters = $parametersAcceptor->getParameters();
131149
/** @var ParameterReflection|null $firstParameter */
132150
$firstParameter = array_shift($parameters);
133151
return $firstParameter
134152
&& ! $firstParameter->getType()->isSuperTypeOf(new ObjectType('Model'))->no();
135153
}
136154

137-
private function wrapBehaviorMethod(MethodReflection $methodReflection): MethodReflection
138-
{
155+
private function wrapBehaviorMethod(
156+
MethodReflection $methodReflection
157+
): MethodReflection {
139158
return new ModelBehaviorMethodWrapper($methodReflection);
140159
}
141160

0 commit comments

Comments
 (0)