| Total Lines | 132 |
| Code Lines | 33 |
| 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 |
||
| 78 | private function createInternalVisitor(SplObjectStorage $storage, Scope $scope) : Visitor |
||
| 79 | { |
||
| 80 | return new class ($this->assembler, $this->referenceAcceptor, $scope, $storage) implements Visitor |
||
| 81 | { |
||
| 82 | /** @var AnnotationMetadataAssembler */ |
||
| 83 | private $assembler; |
||
| 84 | |||
| 85 | /** @var ReferenceAcceptor */ |
||
| 86 | private $referenceAcceptor; |
||
| 87 | |||
| 88 | /** @var Scope */ |
||
| 89 | private $scope; |
||
| 90 | |||
| 91 | /** @var SplObjectStorage<AnnotationMetadata> */ |
||
| 92 | private $storage; |
||
| 93 | |||
| 94 | /** @var SplStack<mixed> */ |
||
| 95 | private $stack; |
||
| 96 | |||
| 97 | 3 | public function __construct( |
|
| 98 | AnnotationMetadataAssembler $assembler, |
||
| 99 | ReferenceAcceptor $referenceAcceptor, |
||
| 100 | Scope $scope, |
||
| 101 | SplObjectStorage $storage |
||
| 102 | ) { |
||
| 103 | 3 | $this->assembler = $assembler; |
|
| 104 | 3 | $this->referenceAcceptor = $referenceAcceptor; |
|
| 105 | 3 | $this->scope = $scope; |
|
| 106 | 3 | $this->storage = $storage; |
|
| 107 | 3 | $this->stack = new SplStack(); |
|
| 108 | 3 | } |
|
| 109 | |||
| 110 | 3 | public function visitAnnotations(Annotations $annotations) : void |
|
| 111 | { |
||
| 112 | 3 | foreach ($annotations as $annotation) { |
|
| 113 | 3 | $annotation->dispatch($this); |
|
| 114 | } |
||
| 115 | 3 | } |
|
| 116 | |||
| 117 | 3 | public function visitAnnotation(Annotation $annotation) : void |
|
| 118 | { |
||
| 119 | 3 | if (! $this->referenceAcceptor->accepts($annotation->getName(), $this->scope)) { |
|
| 120 | return; |
||
| 121 | } |
||
| 122 | |||
| 123 | 3 | $annotation->getParameters()->dispatch($this); |
|
| 124 | 3 | $annotation->getName()->dispatch($this); |
|
| 125 | |||
| 126 | 3 | $this->storage->attach($this->stack->pop()); |
|
| 127 | 3 | } |
|
| 128 | |||
| 129 | 3 | public function visitReference(Reference $reference) : void |
|
| 130 | { |
||
| 131 | 3 | $this->stack->push($reference); |
|
| 132 | 3 | } |
|
| 133 | |||
| 134 | 3 | public function visitParameters(Parameters $parameters) : void |
|
| 135 | { |
||
| 136 | 3 | foreach ($parameters as $parameter) { |
|
| 137 | 2 | $parameter->dispatch($this); |
|
| 138 | } |
||
| 139 | 3 | } |
|
| 140 | |||
| 141 | 1 | public function visitNamedParameter(NamedParameter $parameter) : void |
|
| 142 | { |
||
| 143 | 1 | $parameter->getValue()->dispatch($this); |
|
| 144 | 1 | $parameter->getName()->dispatch($this); |
|
| 145 | 1 | } |
|
| 146 | |||
| 147 | 1 | public function visitUnnamedParameter(UnnamedParameter $parameter) : void |
|
| 148 | { |
||
| 149 | 1 | $parameter->getValue()->dispatch($this); |
|
| 150 | 1 | } |
|
| 151 | |||
| 152 | public function visitListCollection(ListCollection $listCollection) : void |
||
| 153 | { |
||
| 154 | foreach ($listCollection as $item) { |
||
| 155 | $item->dispatch($this); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | public function visitMapCollection(MapCollection $mapCollection) : void |
||
| 160 | { |
||
| 161 | foreach ($mapCollection as $item) { |
||
| 162 | $item->dispatch($this); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | public function visitPair(Pair $pair) : void |
||
| 167 | { |
||
| 168 | $pair->getValue()->dispatch($this); |
||
| 169 | $pair->getKey()->dispatch($this); |
||
| 170 | } |
||
| 171 | |||
| 172 | 1 | public function visitIdentifier(Identifier $identifier) : void |
|
| 173 | { |
||
| 174 | // leaf - no dispatch |
||
| 175 | 1 | } |
|
| 176 | |||
| 177 | public function visitConstantFetch(ConstantFetch $constantFetch) : void |
||
| 178 | { |
||
| 179 | $constantFetch->getName()->dispatch($this); |
||
| 180 | } |
||
| 181 | |||
| 182 | public function visitClassConstantFetch(ClassConstantFetch $classConstantFetch) : void |
||
| 183 | { |
||
| 184 | $classConstantFetch->getName()->dispatch($this); |
||
| 185 | $classConstantFetch->getClass()->dispatch($this); |
||
| 186 | } |
||
| 187 | |||
| 188 | public function visitNullScalar(NullScalar $nullScalar) : void |
||
| 189 | { |
||
| 190 | // leaf - no dispatch |
||
| 191 | } |
||
| 192 | |||
| 193 | public function visitBooleanScalar(BooleanScalar $booleanScalar) : void |
||
| 194 | { |
||
| 195 | // leaf - no dispatch |
||
| 196 | } |
||
| 197 | |||
| 198 | 1 | public function visitIntegerScalar(IntegerScalar $integerScalar) : void |
|
| 199 | { |
||
| 200 | // leaf - no dispatch |
||
| 201 | 1 | } |
|
| 202 | |||
| 203 | public function visitFloatScalar(FloatScalar $floatScalar) : void |
||
| 204 | { |
||
| 205 | // leaf - no dispatch |
||
| 206 | } |
||
| 207 | |||
| 208 | public function visitStringScalar(StringScalar $stringScalar) : void |
||
| 209 | { |
||
| 210 | // leaf - no dispatch |
||
| 215 |