| Conditions | 4 |
| Paths | 5 |
| Total Lines | 87 |
| 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 |
||
| 113 | public function make( |
||
| 114 | ReflectionClass $reflection, |
||
| 115 | Declaration\DeclarationInterface $class, |
||
| 116 | Declaration\DeclarationInterface $parent |
||
| 117 | ): string { |
||
| 118 | $structure = $this->extractor->extract($reflection); |
||
| 119 | foreach ($structure->methodNames() as $name) { |
||
| 120 | if (array_key_exists($name, self::PROMISE_METHODS)) { |
||
| 121 | throw new ProxyFactoryException("Promise method `$name` already defined."); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | $resolverProperty = $this->resolverPropertyName($structure); |
||
| 126 | $publicPropertiesConst = $this->publicPropertiesConstName($structure); |
||
| 127 | $unsetPropertiesConst = $this->unsetPropertiesConstName($structure); |
||
| 128 | |||
| 129 | $visitors = [ |
||
| 130 | new Visitor\AddUseStmts($this->useStmts($class, $parent)), |
||
| 131 | new Visitor\UpdateNamespace($class->getNamespaceName()), |
||
| 132 | new Visitor\DeclareClass( |
||
| 133 | $class->getShortName(), |
||
| 134 | $parent->getShortName(), |
||
| 135 | shortName(PromiseInterface::class) |
||
| 136 | ), |
||
| 137 | new Visitor\AddPropertiesConst($unsetPropertiesConst, $structure->toBeUnsetProperties()), |
||
| 138 | new Visitor\AddPropertiesConst($publicPropertiesConst, $structure->publicProperties()), |
||
| 139 | new Visitor\AddResolverProperty($resolverProperty, $this->propertyType(), $parent->getShortName()), |
||
| 140 | new Visitor\AddInitMethod( |
||
| 141 | $resolverProperty, |
||
| 142 | $this->propertyType(), |
||
| 143 | self::DEPENDENCIES, |
||
| 144 | $unsetPropertiesConst, |
||
| 145 | $this->initMethodName($structure) |
||
| 146 | ), |
||
| 147 | new Visitor\AddMagicCloneMethod($resolverProperty, $structure->hasClone), |
||
| 148 | new Visitor\AddMagicGetMethod( |
||
| 149 | $parent->getFullName(), |
||
| 150 | $resolverProperty, |
||
| 151 | self::RESOLVE_METHOD |
||
| 152 | ), |
||
| 153 | new Visitor\AddMagicSetMethod( |
||
| 154 | $parent->getFullName(), |
||
| 155 | $resolverProperty, |
||
| 156 | self::RESOLVE_METHOD |
||
| 157 | ), |
||
| 158 | new Visitor\AddMagicIssetMethod( |
||
| 159 | $parent->getFullName(), |
||
| 160 | $resolverProperty, |
||
| 161 | self::RESOLVE_METHOD, |
||
| 162 | $publicPropertiesConst |
||
| 163 | ), |
||
| 164 | new Visitor\AddMagicUnset( |
||
| 165 | $parent->getFullName(), |
||
| 166 | $resolverProperty, |
||
| 167 | self::RESOLVE_METHOD, |
||
| 168 | $publicPropertiesConst |
||
| 169 | ), |
||
| 170 | new Visitor\AddMagicDebugInfoMethod( |
||
| 171 | $resolverProperty, |
||
| 172 | self::RESOLVE_METHOD, |
||
| 173 | self::LOADED_METHOD, |
||
| 174 | self::ROLE_METHOD, |
||
| 175 | self::SCOPE_METHOD, |
||
| 176 | $structure->properties() |
||
| 177 | ), |
||
| 178 | new Visitor\UpdatePromiseMethods($resolverProperty), |
||
| 179 | new Visitor\AddProxiedMethods( |
||
| 180 | $parent->getFullName(), |
||
| 181 | $resolverProperty, |
||
| 182 | $structure->methods, |
||
| 183 | self::RESOLVE_METHOD |
||
| 184 | ), |
||
| 185 | ]; |
||
| 186 | |||
| 187 | foreach (self::PROMISE_METHODS as $method => $returnType) { |
||
| 188 | $visitors[] = new Visitor\AddPromiseMethod($resolverProperty, $method, $returnType); |
||
| 189 | } |
||
| 190 | |||
| 191 | $nodes = $this->getNodesFromStub(); |
||
| 192 | $output = $this->traverser->traverseClonedNodes($nodes, ...$visitors); |
||
| 193 | |||
| 194 | return $this->printer->printFormatPreserving( |
||
| 195 | $output, |
||
| 196 | $nodes, |
||
| 197 | $this->lexer->getTokens() |
||
| 198 | ); |
||
| 199 | } |
||
| 200 | |||
| 268 |