| Conditions | 4 |
| Paths | 5 |
| Total 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 |
||
| 97 | public function make(\ReflectionClass $reflection, Declaration\DeclarationInterface $class, Declaration\DeclarationInterface $parent): string |
||
| 98 | { |
||
| 99 | $structure = $this->extractor->extract($reflection); |
||
| 100 | foreach ($structure->methodNames() as $name) { |
||
| 101 | if (array_key_exists($name, self::PROMISE_METHODS)) { |
||
| 102 | throw new ProxyFactoryException("Promise method `$name` already defined."); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | $property = $this->resolverPropertyName($structure); |
||
| 107 | $unsetPropertiesConst = $this->unsetPropertiesConstName($structure); |
||
| 108 | |||
| 109 | $visitors = [ |
||
| 110 | new Visitor\AddUseStmts($this->useStmts($class, $parent)), |
||
| 111 | new Visitor\UpdateNamespace($class->getNamespaceName()), |
||
| 112 | new Visitor\DeclareClass($class->getShortName(), $parent->getShortName(), Utils::shortName(PromiseInterface::class)), |
||
| 113 | new Visitor\AddUnsetPropertiesConst($unsetPropertiesConst, $structure->properties), |
||
| 114 | new Visitor\AddResolverProperty($property, $this->propertyType(), $parent->getShortName()), |
||
| 115 | new Visitor\AddInitMethod( |
||
| 116 | $property, |
||
| 117 | $this->propertyType(), |
||
| 118 | self::DEPENDENCIES, |
||
| 119 | $this->unsetPropertiesConstName($structure), |
||
| 120 | $this->initMethodName($structure) |
||
| 121 | ), |
||
| 122 | new Visitor\AddMagicCloneMethod($property, $structure->hasClone), |
||
| 123 | new Visitor\AddMagicGetMethod($property, self::RESOLVE_METHOD), |
||
| 124 | new Visitor\AddMagicSetMethod($property, self::RESOLVE_METHOD), |
||
| 125 | new Visitor\AddMagicIssetMethod($property, self::RESOLVE_METHOD, $unsetPropertiesConst), |
||
| 126 | new Visitor\AddMagicUnset($property, self::RESOLVE_METHOD, $unsetPropertiesConst), |
||
| 127 | new Visitor\AddMagicDebugInfoMethod( |
||
| 128 | $property, |
||
| 129 | self::RESOLVE_METHOD, |
||
| 130 | self::LOADED_METHOD, |
||
| 131 | self::ROLE_METHOD, |
||
| 132 | self::SCOPE_METHOD, |
||
| 133 | $structure->properties |
||
| 134 | ), |
||
| 135 | new Visitor\UpdatePromiseMethods($property), |
||
| 136 | new Visitor\AddProxiedMethods($property, $structure->methods, self::RESOLVE_METHOD), |
||
| 137 | ]; |
||
| 138 | |||
| 139 | foreach (self::PROMISE_METHODS as $method => $returnType) { |
||
| 140 | $visitors[] = new Visitor\AddPromiseMethod($property, $method, $returnType); |
||
| 141 | } |
||
| 142 | |||
| 143 | $nodes = $this->getNodesFromStub(); |
||
| 144 | $output = $this->traverser->traverseClonedNodes($nodes, ...$visitors); |
||
| 145 | |||
| 146 | return $this->printer->printFormatPreserving( |
||
| 147 | $output, |
||
| 148 | $nodes, |
||
| 149 | $this->lexer->getTokens() |
||
| 150 | ); |
||
| 151 | } |
||
| 152 | |||
| 190 | } |