Conditions | 1 |
Paths | 1 |
Total Lines | 80 |
Code Lines | 55 |
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 |
||
104 | public function validExamples() : iterable |
||
105 | { |
||
106 | yield 'fixture - AnnotationTargetAll' => [ |
||
|
|||
107 | new Reference(AnnotationTargetAll::class, true), |
||
108 | new Scope(new ReflectionClass($this), new Imports([]), new IgnoredAnnotations()), |
||
109 | function (AnnotationMetadata $metadata) : void { |
||
110 | $this->assertEquals(AnnotationTargetAllMetadata::get(), $metadata); |
||
111 | }, |
||
112 | ]; |
||
113 | |||
114 | yield 'fixture - AnnotationWithRequiredAttributes' => [ |
||
115 | new Reference(AnnotationWithRequiredAttributes::class, true), |
||
116 | new Scope(new ReflectionClass($this), new Imports([]), new IgnoredAnnotations()), |
||
117 | function (AnnotationMetadata $metadata) : void { |
||
118 | $this->assertSame(AnnotationWithRequiredAttributes::class, $metadata->getName()); |
||
119 | $this->assertTrue($metadata->getTarget()->all(), 'Invalid target'); |
||
120 | $this->assertTrue($metadata->hasConstructor(), 'Has no constructor'); |
||
121 | $properties = $metadata->getProperties(); |
||
122 | $this->assertEmpty($properties); |
||
123 | $this->assertNull($metadata->getDefaultProperty()); |
||
124 | }, |
||
125 | ]; |
||
126 | |||
127 | yield 'fixture - AnnotationWithRequiredAttributesWithoutConstructor' => [ |
||
128 | new Reference(AnnotationWithRequiredAttributesWithoutConstructor::class, true), |
||
129 | new Scope(new ReflectionClass($this), new Imports([]), new IgnoredAnnotations()), |
||
130 | function (AnnotationMetadata $metadata) : void { |
||
131 | $this->assertSame(AnnotationWithRequiredAttributesWithoutConstructor::class, $metadata->getName()); |
||
132 | $this->assertTrue($metadata->getTarget()->all(), 'Invalid target'); |
||
133 | $this->assertFalse($metadata->hasConstructor(), 'Has constructor'); |
||
134 | $properties = $metadata->getProperties(); |
||
135 | $expectedProperties = [ |
||
136 | 'value' => new PropertyMetadata( |
||
137 | 'value', |
||
138 | TestNullableType::fromType(new StringType()), |
||
139 | true, |
||
140 | [], |
||
141 | true |
||
142 | ), |
||
143 | 'annot' => new PropertyMetadata( |
||
144 | 'annot', |
||
145 | TestNullableType::fromType(new ObjectType(AnnotationTargetAnnotation::class)), |
||
146 | false, |
||
147 | [], |
||
148 | true |
||
149 | ), |
||
150 | ]; |
||
151 | |||
152 | $this->assertEquals( |
||
153 | $expectedProperties, |
||
154 | $properties |
||
155 | ); |
||
156 | $this->assertEquals( |
||
157 | $expectedProperties['value'], |
||
158 | $metadata->getDefaultProperty() |
||
159 | ); |
||
160 | }, |
||
161 | ]; |
||
162 | |||
163 | yield 'fixture - AnnotationWithVarType' => [ |
||
164 | new Reference(AnnotationWithVarType::class, true), |
||
165 | new Scope(new ReflectionClass($this), new Imports([]), new IgnoredAnnotations()), |
||
166 | function (AnnotationMetadata $metadata) : void { |
||
167 | $this->assertEquals(AnnotationWithVarTypeMetadata::get(), $metadata); |
||
168 | }, |
||
169 | ]; |
||
170 | |||
171 | yield 'fixture - AnnotationWithConstants' => [ |
||
172 | new Reference(AnnotationWithConstants::class, true), |
||
173 | new Scope(new ReflectionClass($this), new Imports([]), new IgnoredAnnotations()), |
||
174 | function (AnnotationMetadata $metadata) : void { |
||
175 | $this->assertEquals(AnnotationWithConstantsMetadata::get(), $metadata); |
||
176 | }, |
||
177 | ]; |
||
178 | |||
179 | yield 'fixture - AnnotationEnum' => [ |
||
180 | new Reference(AnnotationEnum::class, true), |
||
181 | new Scope(new ReflectionClass($this), new Imports([]), new IgnoredAnnotations()), |
||
182 | static function (AnnotationMetadata $metadata) : void { |
||
183 | self::assertEquals(AnnotationEnumMetadata::get(), $metadata); |
||
184 | }, |
||
188 |