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