33
44namespace SaschaEgerer \PhpstanTypo3 \Reflection ;
55
6+ use PHPStan \Broker \Broker ;
67use PHPStan \Reflection \ClassReflection ;
78use PHPStan \Reflection \MethodReflection ;
89use PHPStan \Type \ObjectType ;
910use PHPStan \Type \Type ;
10- use TYPO3 \CMS \Extbase \Persistence \ObjectStorage ;
11+ use TYPO3 \CMS \Core \Utility \ClassNamingUtility ;
12+ use TYPO3 \CMS \Extbase \Persistence \QueryResultInterface ;
1113
1214class RepositoryFindByMethodReflection implements MethodReflection
1315{
14-
16+ /**
17+ * @var \PHPStan\Reflection\ClassReflection
18+ */
1519 private $ classReflection ;
1620
21+ /**
22+ * @var string
23+ */
1724 private $ name ;
1825
19- public function __construct (ClassReflection $ classReflection , string $ name )
26+ /**
27+ * @var \PHPStan\Broker\Broker
28+ */
29+ private $ broker ;
30+
31+ public function __construct (ClassReflection $ classReflection , string $ name , Broker $ broker )
2032 {
2133 $ this ->classReflection = $ classReflection ;
2234 $ this ->name = $ name ;
35+ $ this ->broker = $ broker ;
2336 }
2437
2538 public function getDeclaringClass (): ClassReflection
@@ -52,9 +65,27 @@ public function getName(): string
5265 return $ this ->name ;
5366 }
5467
68+ private function getPropertyName (): string
69+ {
70+ return lcfirst (substr ($ this ->getName (), 6 ));
71+ }
72+
73+ private function getModelName (): string
74+ {
75+ $ className = $ this ->classReflection ->getName ();
76+
77+ return ClassNamingUtility::translateRepositoryNameToModelName ($ className );
78+ }
79+
5580 public function getParameters (): array
5681 {
57- return [];
82+ $ modelReflection = $ this ->broker ->getClass ($ this ->getModelName ());
83+
84+ $ type = $ modelReflection ->getNativeProperty ($ this ->getPropertyName ())->getType ();
85+
86+ return [
87+ new RepositoryFindByParameterReflection ('arg ' , $ type )
88+ ];
5889 }
5990
6091 public function isVariadic (): bool
@@ -64,6 +95,6 @@ public function isVariadic(): bool
6495
6596 public function getReturnType (): Type
6697 {
67- return new ObjectType (ObjectStorage ::class);
98+ return new ObjectType (QueryResultInterface ::class);
6899 }
69100}
0 commit comments