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