| Conditions | 4 |
| Paths | 5 |
| Total Lines | 59 |
| 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 |
||
| 114 | public function make( |
||
| 115 | \ReflectionClass $reflection, |
||
| 116 | Declaration\DeclarationInterface $class, |
||
| 117 | Declaration\DeclarationInterface $parent |
||
| 118 | ): string { |
||
| 119 | $structure = $this->extractor->extract($reflection); |
||
| 120 | foreach ($structure->methodNames() as $name) { |
||
| 121 | if (array_key_exists($name, self::PROMISE_METHODS)) { |
||
| 122 | throw new ProxyFactoryException("Promise method `$name` already defined."); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | $property = $this->resolverPropertyName($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($class->getShortName(), $parent->getShortName(), |
||
| 133 | Utils::shortName(PromiseInterface::class)), |
||
| 134 | new Visitor\AddUnsetPropertiesConst($unsetPropertiesConst, $structure->properties), |
||
| 135 | new Visitor\AddResolverProperty($property, $this->propertyType(), $parent->getShortName()), |
||
| 136 | new Visitor\AddInitMethod( |
||
| 137 | $property, |
||
| 138 | $this->propertyType(), |
||
| 139 | self::DEPENDENCIES, |
||
| 140 | $this->unsetPropertiesConstName($structure), |
||
| 141 | $this->initMethodName($structure) |
||
| 142 | ), |
||
| 143 | new Visitor\AddMagicCloneMethod($property, $structure->hasClone), |
||
| 144 | new Visitor\AddMagicGetMethod($property, self::RESOLVE_METHOD), |
||
| 145 | new Visitor\AddMagicSetMethod($property, self::RESOLVE_METHOD), |
||
| 146 | new Visitor\AddMagicIssetMethod($property, self::RESOLVE_METHOD, $unsetPropertiesConst), |
||
| 147 | new Visitor\AddMagicUnset($property, self::RESOLVE_METHOD, $unsetPropertiesConst), |
||
| 148 | new Visitor\AddMagicDebugInfoMethod( |
||
| 149 | $property, |
||
| 150 | self::RESOLVE_METHOD, |
||
| 151 | self::LOADED_METHOD, |
||
| 152 | self::ROLE_METHOD, |
||
| 153 | self::SCOPE_METHOD, |
||
| 154 | $structure->properties |
||
| 155 | ), |
||
| 156 | new Visitor\UpdatePromiseMethods($property), |
||
| 157 | new Visitor\AddProxiedMethods($property, $structure->methods, self::RESOLVE_METHOD), |
||
| 158 | ]; |
||
| 159 | |||
| 160 | foreach (self::PROMISE_METHODS as $method => $returnType) { |
||
| 161 | $visitors[] = new Visitor\AddPromiseMethod($property, $method, $returnType); |
||
| 162 | } |
||
| 163 | |||
| 164 | $nodes = $this->getNodesFromStub(); |
||
| 165 | $output = $this->traverser->traverseClonedNodes($nodes, ...$visitors); |
||
| 166 | |||
| 167 | return $this->printer->printFormatPreserving( |
||
| 168 | $output, |
||
| 169 | $nodes, |
||
| 170 | $this->lexer->getTokens() |
||
| 171 | ); |
||
| 172 | } |
||
| 173 | |||
| 231 | } |