| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 45 |
| 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 | $this->assertEquals( |
||
| 136 | [ |
||
| 137 | 'value' => new PropertyMetadata( |
||
| 138 | 'value', |
||
| 139 | TestNullableType::fromType(new StringType()), |
||
| 140 | true |
||
| 141 | ), |
||
| 142 | 'annot' => new PropertyMetadata( |
||
| 143 | 'annot', |
||
| 144 | TestNullableType::fromType(new ObjectType(AnnotationTargetAnnotation::class)) |
||
| 145 | ), |
||
| 146 | ], |
||
| 147 | $properties |
||
| 148 | ); |
||
| 149 | $this->assertEquals( |
||
| 150 | new PropertyMetadata('value', TestNullableType::fromType(new StringType()), true), |
||
| 151 | $metadata->getDefaultProperty() |
||
| 152 | ); |
||
| 153 | }, |
||
| 154 | ]; |
||
| 155 | |||
| 156 | yield 'fixture - AnnotationWithVarType' => [ |
||
| 157 | new Reference(AnnotationWithVarType::class, true), |
||
| 158 | new Scope(new ReflectionClass($this), new Imports([]), new IgnoredAnnotations()), |
||
| 159 | function (AnnotationMetadata $metadata) : void { |
||
| 160 | $this->assertEquals(AnnotationWithVarTypeMetadata::get(), $metadata); |
||
| 161 | }, |
||
| 162 | ]; |
||
| 163 | |||
| 164 | yield 'fixture - AnnotationWithConstants' => [ |
||
| 165 | new Reference(AnnotationWithConstants::class, true), |
||
| 166 | new Scope(new ReflectionClass($this), new Imports([]), new IgnoredAnnotations()), |
||
| 167 | function (AnnotationMetadata $metadata) : void { |
||
| 168 | $this->assertEquals(AnnotationWithConstantsMetadata::get(), $metadata); |
||
| 169 | }, |
||
| 173 |