Conditions | 1 |
Paths | 1 |
Total Lines | 58 |
Code Lines | 42 |
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 |
||
72 | public function validExamples() : iterable |
||
73 | { |
||
74 | yield 'fixture - ClassWithAnnotationTargetAll' => [ |
||
75 | ClassWithAnnotationTargetAll::class, |
||
76 | [AnnotationTargetAllMetadata::get()], |
||
77 | function (array $result) : void { |
||
78 | $this->assertCount(1, $result); |
||
79 | /** @var AnnotationTargetAll $resultAnnotation */ |
||
80 | $resultAnnotation = $result[0]; |
||
81 | $this->assertInstanceOf(AnnotationTargetAll::class, $resultAnnotation); |
||
82 | $this->assertSame(123, $resultAnnotation->name); |
||
83 | }, |
||
84 | ]; |
||
85 | |||
86 | yield 'fixture - ClassWithFullValidUsageOfAnnotationWithVarType' => [ |
||
87 | ClassWithFullValidUsageOfAnnotationWithVarType::class, |
||
88 | [ |
||
89 | AnnotationTargetAllMetadata::get(), |
||
90 | AnnotationWithVarTypeMetadata::get(), |
||
91 | ], |
||
92 | function (array $result) : void { |
||
93 | $this->assertCount(1, $result); |
||
94 | /** @var AnnotationWithVarType $resultAnnotation */ |
||
95 | $resultAnnotation = $result[0]; |
||
96 | $this->assertInstanceOf(AnnotationWithVarType::class, $resultAnnotation); |
||
97 | |||
98 | $this->assertNull($resultAnnotation->mixed); |
||
99 | $this->assertTrue($resultAnnotation->boolean); |
||
100 | $this->assertFalse($resultAnnotation->bool); |
||
101 | $this->assertSame(3.14, $resultAnnotation->float); |
||
102 | $this->assertSame('foo', $resultAnnotation->string); |
||
103 | $this->assertSame(42, $resultAnnotation->integer); |
||
104 | $this->assertSame(['foo', 42, false], $resultAnnotation->array); |
||
105 | $this->assertSame(['foo' => 'bar'], $resultAnnotation->arrayMap); |
||
106 | $this->assertInstanceOf(AnnotationTargetAll::class, $resultAnnotation->annotation); |
||
107 | $this->assertSame('baz', $resultAnnotation->annotation->name); |
||
108 | $this->assertSame([1, 2, 3], $resultAnnotation->arrayOfIntegers); |
||
109 | $this->assertSame(['foo', 'bar', 'baz'], $resultAnnotation->arrayOfStrings); |
||
110 | |||
111 | $this->assertInternalType('array', $resultAnnotation->arrayOfAnnotations); |
||
112 | $this->assertCount(2, $resultAnnotation->arrayOfAnnotations); |
||
113 | $this->assertInstanceOf(AnnotationTargetAll::class, $resultAnnotation->arrayOfAnnotations[0]); |
||
114 | $this->assertNull($resultAnnotation->arrayOfAnnotations[0]->name); |
||
115 | $this->assertInstanceOf(AnnotationTargetAll::class, $resultAnnotation->arrayOfAnnotations[1]); |
||
116 | $this->assertSame(123, $resultAnnotation->arrayOfAnnotations[1]->name); |
||
117 | }, |
||
118 | ]; |
||
119 | |||
120 | yield 'fixture - ClassWithAnnotationWithConstants' => [ |
||
121 | ClassWithAnnotationWithConstants::class, |
||
122 | [AnnotationWithConstantsMetadata::get()], |
||
123 | function (array $result) : void { |
||
124 | $this->assertCount(1, $result); |
||
125 | /** @var AnnotationWithConstants $resultAnnotation */ |
||
126 | $resultAnnotation = $result[0]; |
||
127 | $this->assertInstanceOf(AnnotationWithConstants::class, $resultAnnotation); |
||
128 | |||
129 | $this->assertSame(AnnotationWithConstants::FLOAT, $resultAnnotation->value); |
||
130 | }, |
||
159 |