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