Conditions | 2 |
Paths | 1 |
Total Lines | 70 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
52 | public function shouldReadAnnotations() |
||
53 | { |
||
54 | $someAnnotationA = new Service(); |
||
55 | $someAnnotationA->id = "some_service"; |
||
56 | $someAnnotationA->field = "foo"; |
||
57 | |||
58 | $someAnnotationB = new Service(); |
||
59 | $someAnnotationB->id = "other_service"; |
||
60 | $someAnnotationB->field = "bar"; |
||
61 | $someAnnotationB->lax = true; |
||
62 | |||
63 | $someAnnotationC = new Choice(); |
||
64 | $someAnnotationC->column = "baz_column"; |
||
65 | $someAnnotationC->nullable = true; |
||
66 | $someAnnotationC->choices = [ |
||
67 | 'foo' => $someAnnotationA, |
||
68 | 'bar' => $someAnnotationB, |
||
69 | ]; |
||
70 | |||
71 | $someAnnotationD = new Choice(); |
||
72 | $someAnnotationD->column = "faz_column"; |
||
73 | $someAnnotationD->nullable = false; |
||
74 | $someAnnotationD->choices = [ |
||
75 | 'foo' => $someAnnotationA, |
||
76 | 'bar' => $someAnnotationB, |
||
77 | ]; |
||
78 | |||
79 | /** @var string $entityClass */ |
||
80 | $entityClass = EntityExample::class; |
||
81 | |||
82 | /** @var array<MappingInterface> $expectedFieldMappings */ |
||
83 | $expectedFieldMappings = [ |
||
84 | 'foo' => new ServiceMapping("some_service", false, "in entity '{$entityClass}' on field 'foo'"), |
||
85 | 'bar' => new ServiceMapping("other_service", true, "in entity '{$entityClass}' on field 'bar'"), |
||
86 | 'baz' => new ChoiceMapping('baz_column', [ |
||
87 | 'foo' => new ServiceMapping("some_service", false, "in entity '{$entityClass}' on field 'baz'"), |
||
88 | 'bar' => new ServiceMapping("other_service", true, "in entity '{$entityClass}' on field 'baz'"), |
||
89 | ], "in entity 'Addiks\RDMBundle\Tests\Hydration\EntityExample' on field 'baz'"), |
||
90 | 'faz' => new ChoiceMapping(new Column('faz_column', Type::getType('string'), [ |
||
91 | 'notnull' => true, |
||
92 | 'length' => 255, |
||
93 | ]), [ |
||
94 | 'foo' => new ServiceMapping("some_service", false, "in entity '{$entityClass}' on field 'faz'"), |
||
95 | 'bar' => new ServiceMapping("other_service", true, "in entity '{$entityClass}' on field 'faz'"), |
||
96 | ], "in entity 'Addiks\RDMBundle\Tests\Hydration\EntityExample' on field 'faz'"), |
||
97 | ]; |
||
98 | |||
99 | /** @var array<array<Service>> $annotationMap */ |
||
100 | $annotationMap = [ |
||
101 | 'foo' => [$someAnnotationA], |
||
102 | 'bar' => [$someAnnotationB], |
||
103 | 'baz' => [$someAnnotationC], |
||
104 | 'faz' => [$someAnnotationD], |
||
105 | ]; |
||
106 | |||
107 | $this->annotationReader->method('getPropertyAnnotations')->will($this->returnCallback( |
||
108 | function (ReflectionProperty $propertyReflection) use ($annotationMap) { |
||
109 | if (isset($annotationMap[$propertyReflection->getName()])) { |
||
110 | return $annotationMap[$propertyReflection->getName()]; |
||
111 | } else { |
||
112 | return []; |
||
113 | } |
||
114 | } |
||
115 | )); |
||
116 | |||
117 | /** @var EntityMapping $actualMapping */ |
||
118 | $actualMapping = $this->mappingDriver->loadRDMMetadataForClass(EntityExample::class); |
||
119 | |||
120 | $this->assertEquals($expectedFieldMappings, $actualMapping->getFieldMappings()); |
||
121 | } |
||
122 | |||
124 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..