| Conditions | 4 |
| Paths | 1 |
| Total Lines | 80 |
| Code Lines | 49 |
| 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 |
||
| 62 | public function docBlocksProvider() : iterable |
||
| 63 | { |
||
| 64 | yield 'single without parameters' => [ |
||
|
|
|||
| 65 | new Annotations( |
||
| 66 | new Annotation( |
||
| 67 | new Reference('Foo', true), |
||
| 68 | new Parameters() |
||
| 69 | ) |
||
| 70 | ), |
||
| 71 | static function (AnnotationMetadataAssembler $assembler) : void { |
||
| 72 | /** @var AnnotationMetadataAssembler|MockObject $assembler */ |
||
| 73 | $assembler->method('assemble') |
||
| 74 | ->with( |
||
| 75 | self::callback(static function (Reference $reference) : bool { |
||
| 76 | return $reference->getIdentifier() === 'Foo' && $reference->isFullyQualified() === true; |
||
| 77 | }), |
||
| 78 | self::isInstanceOf(Scope::class) |
||
| 79 | ) |
||
| 80 | ->willReturn(new AnnotationMetadata( |
||
| 81 | 'Foo', |
||
| 82 | new AnnotationTarget(AnnotationTarget::TARGET_ALL), |
||
| 83 | false, |
||
| 84 | [] |
||
| 85 | )); |
||
| 86 | }, |
||
| 87 | static function (MetadataCollection $collection) : void { |
||
| 88 | self::assertCount(1, $collection); |
||
| 89 | self::assertSame('Foo', $collection['Foo']->getName()); |
||
| 90 | }, |
||
| 91 | ]; |
||
| 92 | yield 'nested' => [ |
||
| 93 | new Annotations( |
||
| 94 | new Annotation( |
||
| 95 | new Reference('Foo', true), |
||
| 96 | new Parameters( |
||
| 97 | new UnnamedParameter( |
||
| 98 | new Annotation( |
||
| 99 | new Reference('Bar', false), |
||
| 100 | new Parameters() |
||
| 101 | ) |
||
| 102 | ) |
||
| 103 | ) |
||
| 104 | ) |
||
| 105 | ), |
||
| 106 | static function (AnnotationMetadataAssembler $assembler) : void { |
||
| 107 | /** @var AnnotationMetadataAssembler|MockObject $assembler */ |
||
| 108 | $assembler->method('assemble') |
||
| 109 | ->withConsecutive( |
||
| 110 | [ |
||
| 111 | self::callback(static function (Reference $reference) : bool { |
||
| 112 | return $reference->getIdentifier() === 'Bar' && $reference->isFullyQualified() === false; |
||
| 113 | }), |
||
| 114 | self::isInstanceOf(Scope::class), |
||
| 115 | ], |
||
| 116 | [ |
||
| 117 | self::callback(static function (Reference $reference) : bool { |
||
| 118 | return $reference->getIdentifier() === 'Foo' && $reference->isFullyQualified() === true; |
||
| 119 | }), |
||
| 120 | self::isInstanceOf(Scope::class), |
||
| 121 | ] |
||
| 122 | ) |
||
| 123 | ->willReturnOnConsecutiveCalls( |
||
| 124 | new AnnotationMetadata( |
||
| 125 | 'Bar', |
||
| 126 | new AnnotationTarget(AnnotationTarget::TARGET_ALL), |
||
| 127 | false, |
||
| 128 | [] |
||
| 129 | ), |
||
| 130 | new AnnotationMetadata( |
||
| 131 | 'Foo', |
||
| 132 | new AnnotationTarget(AnnotationTarget::TARGET_ALL), |
||
| 133 | false, |
||
| 134 | [] |
||
| 135 | ) |
||
| 136 | ); |
||
| 137 | }, |
||
| 138 | static function (MetadataCollection $collection) : void { |
||
| 139 | self::assertCount(2, $collection); |
||
| 140 | self::assertSame('Bar', $collection['Bar']->getName()); |
||
| 141 | self::assertSame('Foo', $collection['Foo']->getName()); |
||
| 142 | }, |
||
| 146 |