|
4 | 4 |
|
5 | 5 | namespace Tpetry\PostgresqlEnhanced\Support\Phpstan;
|
6 | 6 |
|
7 |
| -use Illuminate\Contracts\Database\Query\Expression as ExpressionContract; |
8 |
| -use Illuminate\Database\Schema\ColumnDefinition; |
| 7 | +use Illuminate\Database\Schema\ColumnDefinition as BaseColumnDefinition; |
9 | 8 | use PHPStan\Reflection\ClassReflection;
|
10 |
| -use PHPStan\Reflection\FunctionVariant; |
11 | 9 | use PHPStan\Reflection\MethodReflection;
|
12 | 10 | use PHPStan\Reflection\MethodsClassReflectionExtension;
|
13 |
| -use PHPStan\Type\Generic\TemplateTypeMap; |
14 |
| -use PHPStan\Type\MixedType; |
15 |
| -use PHPStan\Type\ObjectType; |
16 |
| -use PHPStan\Type\StringType; |
17 |
| -use Tpetry\PostgresqlEnhanced\Support\Phpstan\Values\ReflectedMethod; |
18 |
| -use Tpetry\PostgresqlEnhanced\Support\Phpstan\Values\ReflectedParameter; |
| 11 | +use PHPStan\Reflection\ReflectionProvider; |
| 12 | +use Tpetry\PostgresqlEnhanced\Schema\ColumnDefinition; |
19 | 13 |
|
20 | 14 | class SchemaColumnDefinitionExtension implements MethodsClassReflectionExtension
|
21 | 15 | {
|
22 |
| - /** |
23 |
| - * @param 'compression'|'initial'|'using' $methodName |
24 |
| - */ |
| 16 | + public function __construct( |
| 17 | + private ReflectionProvider $reflectionProvider, |
| 18 | + ) { |
| 19 | + } |
| 20 | + |
25 | 21 | public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
|
26 | 22 | {
|
27 |
| - return match ($methodName) { |
28 |
| - 'initial' => $this->getInitialMethod($classReflection), |
29 |
| - 'compression' => $this->getCompressionMethod($classReflection), |
30 |
| - 'using' => $this->getUsingMethod($classReflection), |
31 |
| - }; |
| 23 | + return $this->reflectionProvider->getClass(ColumnDefinition::class)->getNativeMethod($methodName); |
32 | 24 | }
|
33 | 25 |
|
34 | 26 | public function hasMethod(ClassReflection $classReflection, string $methodName): bool
|
35 | 27 | {
|
36 |
| - if (ColumnDefinition::class !== $classReflection->getName()) { |
| 28 | + if (BaseColumnDefinition::class !== $classReflection->getName()) { |
37 | 29 | return false;
|
38 | 30 | }
|
39 | 31 |
|
40 |
| - return \in_array($methodName, ['compression', 'initial', 'using']); |
41 |
| - } |
42 |
| - |
43 |
| - private function getCompressionMethod(ClassReflection $classReflection): MethodReflection |
44 |
| - { |
45 |
| - $parameters = [new ReflectedParameter('algorithm', new StringType())]; |
46 |
| - $returnType = new ObjectType(ColumnDefinition::class); |
47 |
| - |
48 |
| - return new ReflectedMethod( |
49 |
| - classReflection: $classReflection, |
50 |
| - name: 'compression', |
51 |
| - variants: [ |
52 |
| - new FunctionVariant(TemplateTypeMap::createEmpty(), null, $parameters, false, $returnType), |
53 |
| - ], |
54 |
| - ); |
55 |
| - } |
56 |
| - |
57 |
| - private function getInitialMethod(ClassReflection $classReflection): MethodReflection |
58 |
| - { |
59 |
| - $parameters = [new ReflectedParameter('value', new MixedType())]; |
60 |
| - $returnType = new ObjectType(ColumnDefinition::class); |
61 |
| - |
62 |
| - return new ReflectedMethod( |
63 |
| - classReflection: $classReflection, |
64 |
| - name: 'initial', |
65 |
| - variants: [ |
66 |
| - new FunctionVariant(TemplateTypeMap::createEmpty(), null, $parameters, false, $returnType), |
67 |
| - ], |
68 |
| - ); |
69 |
| - } |
70 |
| - |
71 |
| - private function getUsingMethod(ClassReflection $classReflection): MethodReflection |
72 |
| - { |
73 |
| - $parametersExpression = [new ReflectedParameter('expression', new ObjectType(ExpressionContract::class))]; |
74 |
| - $parametersString = [new ReflectedParameter('expression', new StringType())]; |
75 |
| - $returnType = new ObjectType(ColumnDefinition::class); |
76 |
| - |
77 |
| - return new ReflectedMethod( |
78 |
| - classReflection: $classReflection, |
79 |
| - name: 'using', |
80 |
| - variants: [ |
81 |
| - new FunctionVariant(TemplateTypeMap::createEmpty(), null, $parametersExpression, false, $returnType), |
82 |
| - new FunctionVariant(TemplateTypeMap::createEmpty(), null, $parametersString, false, $returnType), |
83 |
| - ], |
84 |
| - ); |
| 32 | + return $this->reflectionProvider->getClass(ColumnDefinition::class)->hasNativeMethod($methodName); |
85 | 33 | }
|
86 | 34 | }
|
0 commit comments