| Conditions | 2 |
| Paths | 2 |
| Total Lines | 57 |
| Code Lines | 40 |
| 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 |
||
| 29 | public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) |
||
| 30 | { |
||
| 31 | CanProxyAssertion::assertClassCanBeProxied($originalClass); |
||
| 32 | |||
| 33 | $interfaces = ['Isolate\\LazyObjects\\WrappedObject']; |
||
| 34 | |||
| 35 | if ($originalClass->isInterface()) { |
||
| 36 | $interfaces[] = $originalClass->name; |
||
| 37 | } else { |
||
| 38 | $classGenerator->setExtendedClass($originalClass->name); |
||
| 39 | } |
||
| 40 | |||
| 41 | $classGenerator->setImplementedInterfaces($interfaces); |
||
| 42 | $classGenerator->addPropertyFromGenerator($wrappedObjectProperty = new WrappedObject()); |
||
| 43 | $classGenerator->addPropertyFromGenerator($lazyPropertiesProperty = new LazyProperties()); |
||
| 44 | $classGenerator->addPropertyFromGenerator($methodReplacementsProperty = new MethodReplacements()); |
||
| 45 | $classGenerator->addPropertyFromGenerator($initializerProperty = new Initializer()); |
||
| 46 | |||
| 47 | array_map( |
||
| 48 | function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) { |
||
| 49 | ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod); |
||
| 50 | }, |
||
| 51 | array_merge( |
||
| 52 | array_map( |
||
| 53 | function (ReflectionMethod $method) use ($wrappedObjectProperty, $lazyPropertiesProperty, $initializerProperty) { |
||
| 54 | return MethodProxy::generateMethod( |
||
| 55 | new MethodReflection($method->getDeclaringClass()->name, $method->name), |
||
| 56 | $wrappedObjectProperty, |
||
| 57 | $lazyPropertiesProperty, |
||
| 58 | $initializerProperty |
||
| 59 | ); |
||
| 60 | }, |
||
| 61 | ProxiedMethodsFilter::getProxiedMethods($originalClass) |
||
| 62 | ), |
||
| 63 | [ |
||
| 64 | new Constructor( |
||
| 65 | $originalClass, |
||
| 66 | $wrappedObjectProperty, |
||
| 67 | $lazyPropertiesProperty, |
||
| 68 | $methodReplacementsProperty, |
||
| 69 | $initializerProperty |
||
| 70 | ), |
||
| 71 | new Sleep( |
||
| 72 | $wrappedObjectProperty, |
||
| 73 | $initializerProperty, |
||
| 74 | $lazyPropertiesProperty, |
||
| 75 | $methodReplacementsProperty |
||
| 76 | ), |
||
| 77 | new GetWrappedObject($wrappedObjectProperty), |
||
| 78 | new GetLazyProperties($lazyPropertiesProperty), |
||
| 79 | new GetMethodReplacements($methodReplacementsProperty), |
||
| 80 | new HasMethodReplacement($methodReplacementsProperty), |
||
| 81 | new GetMethodReplacement($methodReplacementsProperty) |
||
| 82 | ] |
||
| 83 | ) |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | } |
||
| 87 |