Skip to content

Commit 0130290

Browse files
committed
cleanup
1 parent c345261 commit 0130290

22 files changed

+213
-121
lines changed

composer.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
"role": "Author"
1111
}
1212
],
13-
"minimum-stability": "dev",
14-
"prefer-stable": true,
1513
"require": {
1614
"php": ">=8.1.0",
1715
"phpstan/phpstan": "^1.0",
18-
"cakephp/cakephp": "5.x-dev"
16+
"cakephp/cakephp": "^5.0.0"
1917
},
2018
"require-dev": {
2119
"phpstan/phpstan-phpunit": "^1.0",
@@ -42,8 +40,8 @@
4240
}
4341
},
4442
"scripts": {
45-
"cs-check": "phpcs -p --standard=PSR12 src/ tests",
46-
"cs-fix": "phpcbf -p --standard=PSR12 src/ tests",
43+
"cs-check": "phpcs -p src/ tests",
44+
"cs-fix": "phpcbf -p src/ tests",
4745
"test": "phpunit --stderr",
4846
"stan-integration": [
4947
"phpstan analyse tests/test_app/",

phpcs.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="CakePHP Core">
3+
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
4+
5+
<rule ref="CakePHP" />
6+
7+
<arg value="s"/>
8+
</ruleset>

src/Method/AssociationTableMixinClassReflectionExtension.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* @source https://github.com/cakephp/cakephp
@@ -24,10 +25,10 @@ class AssociationTableMixinClassReflectionExtension implements
2425
/**
2526
* @var \PHPStan\Broker\Broker
2627
*/
27-
private $broker;
28+
private Broker $broker;
2829

2930
/**
30-
* @param Broker $broker Class reflection broker
31+
* @param \PHPStan\Broker\Broker $broker Class reflection broker
3132
* @return void
3233
*/
3334
public function setBroker(Broker $broker): void
@@ -36,16 +37,16 @@ public function setBroker(Broker $broker): void
3637
}
3738

3839
/**
39-
* @return ClassReflection
40+
* @return \PHPStan\Reflection\ClassReflection
4041
*/
4142
protected function getTableReflection(): ClassReflection
4243
{
4344
return $this->broker->getClass(Table::class);
4445
}
4546

4647
/**
47-
* @param ClassReflection $classReflection Class reflection
48-
* @param string $methodName Method name
48+
* @param \PHPStan\Reflection\ClassReflection $classReflection Class reflection
49+
* @param string $methodName Method name
4950
* @return bool
5051
*/
5152
public function hasMethod(ClassReflection $classReflection, string $methodName): bool
@@ -63,9 +64,9 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
6364
}
6465

6566
/**
66-
* @param ClassReflection $classReflection Class reflection
67-
* @param string $methodName Method name
68-
* @return MethodReflection
67+
* @param \PHPStan\Reflection\ClassReflection $classReflection Class reflection
68+
* @param string $methodName Method name
69+
* @return \PHPStan\Reflection\MethodReflection
6970
*/
7071
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
7172
{
@@ -78,8 +79,8 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
7879
}
7980

8081
/**
81-
* @param ClassReflection $classReflection Class reflection
82-
* @param string $propertyName Method name
82+
* @param \PHPStan\Reflection\ClassReflection $classReflection Class reflection
83+
* @param string $propertyName Method name
8384
* @return bool
8485
*/
8586
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
@@ -92,9 +93,9 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
9293
}
9394

9495
/**
95-
* @param ClassReflection $classReflection Class reflection
96-
* @param string $propertyName Method name
97-
* @return PropertyReflection
96+
* @param \PHPStan\Reflection\ClassReflection $classReflection Class reflection
97+
* @param string $propertyName Method name
98+
* @return \PHPStan\Reflection\PropertyReflection
9899
*/
99100
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
100101
{

src/Method/TableFindByPropertyMethodReflection.php

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* @source https://github.com/cakephp/cakephp
@@ -9,71 +10,108 @@
910
use PHPStan\Reflection\ClassMemberReflection;
1011
use PHPStan\Reflection\ClassReflection;
1112
use PHPStan\Reflection\MethodReflection;
13+
use PHPStan\Reflection\TrivialParametersAcceptor;
1214
use PHPStan\TrinaryLogic;
1315
use PHPStan\Type\ObjectType;
16+
use PHPStan\Type\Type;
1417

1518
class TableFindByPropertyMethodReflection implements MethodReflection
1619
{
17-
/** @var string */
18-
private $name;
20+
/**
21+
* @var string
22+
*/
23+
private string $name;
1924

20-
/** @var \PHPStan\Reflection\ClassReflection */
21-
private $declaringClass;
25+
/**
26+
* @var \PHPStan\Reflection\ClassReflection
27+
*/
28+
private ClassReflection $declaringClass;
2229

30+
/**
31+
* @param string $name
32+
* @param \PHPStan\Reflection\ClassReflection $declaringClass
33+
*/
2334
public function __construct(string $name, ClassReflection $declaringClass)
2435
{
2536
$this->name = $name;
2637
$this->declaringClass = $declaringClass;
2738
}
2839

40+
/**
41+
* @return \PHPStan\Reflection\ClassReflection
42+
*/
2943
public function getDeclaringClass(): ClassReflection
3044
{
3145
return $this->declaringClass;
3246
}
3347

48+
/**
49+
* @return \PHPStan\Reflection\ClassMemberReflection
50+
*/
3451
public function getPrototype(): ClassMemberReflection
3552
{
3653
return $this;
3754
}
3855

56+
/**
57+
* @return bool
58+
*/
3959
public function isStatic(): bool
4060
{
4161
return false;
4262
}
4363

4464
/**
45-
* @return \PHPStan\Reflection\ParameterReflection[]
65+
* @return array<\PHPStan\Reflection\ParameterReflection>
4666
*/
4767
public function getParameters(): array
4868
{
4969
return [];
5070
}
5171

72+
/**
73+
* @return bool
74+
*/
5275
public function isVariadic(): bool
5376
{
5477
return false;
5578
}
5679

80+
/**
81+
* @return bool
82+
*/
5783
public function isPrivate(): bool
5884
{
5985
return false;
6086
}
6187

88+
/**
89+
* @return bool
90+
*/
6291
public function isPublic(): bool
6392
{
6493
return true;
6594
}
6695

96+
/**
97+
* @return string
98+
*/
6799
public function getName(): string
68100
{
69101
return $this->name;
70102
}
71103

72-
public function getReturnType(): \PHPStan\Type\ObjectType
104+
/**
105+
* @return \PHPStan\Type\ObjectType
106+
*/
107+
public function getReturnType(): ObjectType
73108
{
74109
return new ObjectType('\Cake\ORM\Query');
75110
}
76111

112+
/**
113+
* @return string|null
114+
*/
77115
public function getDocComment(): ?string
78116
{
79117
return null;
@@ -84,35 +122,53 @@ public function getDocComment(): ?string
84122
*/
85123
public function getVariants(): array
86124
{
87-
return [new \PHPStan\Reflection\TrivialParametersAcceptor()];
125+
return [new TrivialParametersAcceptor()];
88126
}
89127

90-
public function isDeprecated(): \PHPStan\TrinaryLogic
128+
/**
129+
* @return \PHPStan\TrinaryLogic
130+
*/
131+
public function isDeprecated(): TrinaryLogic
91132
{
92133
return TrinaryLogic::createNo();
93134
}
94135

136+
/**
137+
* @return string|null
138+
*/
95139
public function getDeprecatedDescription(): ?string
96140
{
97141
return null;
98142
}
99143

100-
public function isFinal(): \PHPStan\TrinaryLogic
144+
/**
145+
* @return \PHPStan\TrinaryLogic
146+
*/
147+
public function isFinal(): TrinaryLogic
101148
{
102149
return TrinaryLogic::createNo();
103150
}
104151

105-
public function isInternal(): \PHPStan\TrinaryLogic
152+
/**
153+
* @return \PHPStan\TrinaryLogic
154+
*/
155+
public function isInternal(): TrinaryLogic
106156
{
107157
return TrinaryLogic::createNo();
108158
}
109159

110-
public function getThrowType(): ?\PHPStan\Type\Type
160+
/**
161+
* @return \PHPStan\Type\Type|null
162+
*/
163+
public function getThrowType(): ?Type
111164
{
112165
return null;
113166
}
114167

115-
public function hasSideEffects(): \PHPStan\TrinaryLogic
168+
/**
169+
* @return \PHPStan\TrinaryLogic
170+
*/
171+
public function hasSideEffects(): TrinaryLogic
116172
{
117173
return TrinaryLogic::createNo();
118174
}

src/Traits/BaseCakeRegistryReturnTrait.php

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* Copyright 2020, Cake Development Corporation (https://www.cakedc.com)
@@ -7,7 +8,7 @@
78
* Redistributions of files must retain the above copyright notice.
89
*
910
* @copyright Copyright 2020, Cake Development Corporation (https://www.cakedc.com)
10-
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
11+
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1112
*/
1213

1314
namespace CakeDC\PHPStan\Traits;
@@ -18,44 +19,49 @@
1819
use PHPStan\Reflection\ParametersAcceptorSelector;
1920
use PHPStan\Type\ObjectType;
2021
use PHPStan\Type\Type;
21-
2222
use function Cake\Core\pluginSplit;
23+
use function class_exists;
24+
use function count;
25+
use function method_exists;
26+
use function sprintf;
27+
use function str_replace;
2328

2429
trait BaseCakeRegistryReturnTrait
2530
{
2631
/**
27-
* @param MethodReflection $methodReflection
28-
* @param MethodCall $methodCall
29-
* @param Scope $scope
32+
* @param \PHPStan\Reflection\MethodReflection $methodReflection
33+
* @param \PhpParser\Node\Expr\MethodCall $methodCall
34+
* @param \PHPStan\Analyser\Scope $scope
3035
* @param string $defaultClass
31-
* @param string|array<string> $namespaceFormat
32-
* @return ObjectType|Type
36+
* @param array<string>|string $namespaceFormat
37+
* @return \PHPStan\Type\Type
3338
* @throws \PHPStan\ShouldNotHappenException
3439
*/
3540
protected function getRegistryReturnType(
36-
$methodReflection,
37-
$methodCall,
38-
$scope,
41+
MethodReflection $methodReflection,
42+
MethodCall $methodCall,
43+
Scope $scope,
3944
string $defaultClass,
40-
$namespaceFormat
41-
) {
42-
if (\count($methodCall->getArgs()) === 0) {
43-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
45+
string|array $namespaceFormat
46+
): Type {
47+
if (count($methodCall->getArgs()) === 0) {
48+
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())
49+
->getReturnType();
4450
}
4551

4652
$argType = $scope->getType($methodCall->getArgs()[0]->value);
47-
if (!\method_exists($argType, 'getValue')) {
53+
if (!method_exists($argType, 'getValue')) {
4854
return new ObjectType($defaultClass);
4955
}
5056
$baseName = $argType->getValue();
51-
list($plugin, $name) = $this->pluginSplit($baseName);
57+
[$plugin, $name] = $this->pluginSplit($baseName);
5258
$prefixes = $plugin ? [$plugin] : ['Cake', 'App'];
5359
$namespaceFormat = (array)$namespaceFormat;
5460
foreach ($namespaceFormat as $format) {
5561
foreach ($prefixes as $prefix) {
56-
$namespace = \str_replace('/', '\\', $prefix);
57-
$className = \sprintf($format, $namespace, $name);
58-
if (\class_exists($className)) {
62+
$namespace = str_replace('/', '\\', $prefix);
63+
$className = sprintf($format, $namespace, $name);
64+
if (class_exists($className)) {
5965
return new ObjectType($className);
6066
}
6167
}
@@ -75,7 +81,7 @@ public function getClass(): string
7581
}
7682

7783
/**
78-
* @param MethodReflection $methodReflection
84+
* @param \PHPStan\Reflection\MethodReflection $methodReflection
7985
* @return bool
8086
*/
8187
public function isMethodSupported(MethodReflection $methodReflection): bool
@@ -88,7 +94,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
8894
* @return array
8995
* @psalm-return array{string|null, string}
9096
*/
91-
protected function pluginSplit($baseName): array
97+
protected function pluginSplit(string $baseName): array
9298
{
9399
return pluginSplit($baseName);
94100
}

0 commit comments

Comments
 (0)