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