| Conditions | 2 |
| Paths | 2 |
| Total Lines | 69 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 29 |
| CRAP Score | 2 |
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 |
||
| 65 | public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) |
||
| 66 | 8 | { |
|
| 67 | CanProxyAssertion::assertClassCanBeProxied($originalClass); |
||
| 68 | 8 | ||
| 69 | 8 | $publicProperties = new PublicPropertiesMap(Properties::fromReflectionClass($originalClass)); |
|
| 70 | $interfaces = [AccessInterceptorValueHolderInterface::class]; |
||
| 71 | 8 | ||
| 72 | 2 | if ($originalClass->isInterface()) { |
|
| 73 | $interfaces[] = $originalClass->getName(); |
||
| 74 | 6 | } else { |
|
| 75 | $classGenerator->setExtendedClass($originalClass->getName()); |
||
| 76 | } |
||
| 77 | 8 | ||
| 78 | 8 | $classGenerator->setImplementedInterfaces($interfaces); |
|
| 79 | 8 | $classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty()); |
|
| 80 | 8 | $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors()); |
|
| 81 | 8 | $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodSuffixInterceptors()); |
|
| 82 | $classGenerator->addPropertyFromGenerator($publicProperties); |
||
| 83 | 8 | ||
| 84 | array_map( |
||
| 85 | 8 | function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) { |
|
| 86 | 8 | ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod); |
|
| 87 | }, |
||
| 88 | array_merge( |
||
| 89 | 8 | array_map( |
|
| 90 | 5 | $this->buildMethodInterceptor($prefixInterceptors, $suffixInterceptors, $valueHolder), |
|
| 91 | 5 | ProxiedMethodsFilter::getProxiedMethods($originalClass) |
|
| 92 | ), |
||
| 93 | [ |
||
| 94 | Constructor::generateMethod($originalClass, $valueHolder), |
||
| 95 | new StaticProxyConstructor($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors), |
||
| 96 | 8 | new GetWrappedValueHolderValue($valueHolder), |
|
| 97 | 8 | new SetMethodPrefixInterceptor($prefixInterceptors), |
|
| 98 | new SetMethodSuffixInterceptor($suffixInterceptors), |
||
| 99 | new MagicGet( |
||
| 100 | 8 | $originalClass, |
|
| 101 | 8 | $valueHolder, |
|
| 102 | 8 | $prefixInterceptors, |
|
| 103 | 8 | $suffixInterceptors, |
|
| 104 | 8 | $publicProperties |
|
| 105 | 8 | ), |
|
| 106 | new MagicSet( |
||
| 107 | $originalClass, |
||
| 108 | $valueHolder, |
||
| 109 | $prefixInterceptors, |
||
| 110 | $suffixInterceptors, |
||
| 111 | $publicProperties |
||
| 112 | 8 | ), |
|
| 113 | new MagicIsset( |
||
| 114 | $originalClass, |
||
| 115 | $valueHolder, |
||
| 116 | $prefixInterceptors, |
||
| 117 | $suffixInterceptors, |
||
| 118 | $publicProperties |
||
| 119 | 8 | ), |
|
| 120 | new MagicUnset( |
||
| 121 | $originalClass, |
||
| 122 | $valueHolder, |
||
| 123 | $prefixInterceptors, |
||
| 124 | $suffixInterceptors, |
||
| 125 | $publicProperties |
||
| 126 | 8 | ), |
|
| 127 | new MagicClone($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors), |
||
| 128 | new MagicSleep($originalClass, $valueHolder), |
||
| 129 | new MagicWakeup($originalClass, $valueHolder), |
||
| 130 | ] |
||
| 131 | ) |
||
| 132 | ); |
||
| 133 | 8 | } |
|
| 134 | 8 | ||
| 150 |