| Conditions | 5 |
| Paths | 8 |
| Total Lines | 59 |
| Code Lines | 35 |
| 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 |
||
| 58 | public function __construct( |
||
| 59 | ClassReflection $classReflection, |
||
| 60 | Broker $broker, |
||
| 61 | string $propertyName |
||
| 62 | ) { |
||
| 63 | if ( |
||
| 64 | false === is_a( |
||
| 65 | $classReflection->getName(), |
||
| 66 | DaftObject::class, |
||
| 67 | true |
||
| 68 | ) |
||
| 69 | ) { |
||
| 70 | throw new InvalidArgumentException( |
||
| 71 | $classReflection->getName() . |
||
| 72 | ' is not an implementation of ' . |
||
| 73 | DaftObject::class |
||
| 74 | ); |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->broker = $broker; |
||
| 78 | |||
| 79 | $className = $classReflection->getName(); |
||
| 80 | |||
| 81 | $this->public = |
||
| 82 | in_array( |
||
| 83 | $propertyName, |
||
| 84 | $className::DaftObjectPublicGetters(), |
||
| 85 | true |
||
| 86 | ) || |
||
| 87 | in_array( |
||
| 88 | $propertyName, |
||
| 89 | $className::DaftObjectPublicSetters(), |
||
| 90 | true |
||
| 91 | ); |
||
| 92 | |||
| 93 | $type = new MixedType(); |
||
| 94 | |||
| 95 | $getter = 'Get' . ucfirst($propertyName); |
||
| 96 | $setter = 'Set' . ucfirst($propertyName); |
||
| 97 | |||
| 98 | $this->readableDeclaringClass = $classReflection; |
||
| 99 | $this->writeableDeclaringClass = $classReflection; |
||
| 100 | |||
| 101 | if ($classReflection->getNativeReflection()->hasMethod($getter)) { |
||
| 102 | $refMethod = new ReflectionMethod($className, $getter); |
||
| 103 | |||
| 104 | $this->readableDeclaringClass = $this->SetGetterProps($refMethod); |
||
| 105 | } |
||
| 106 | |||
| 107 | if ($classReflection->getNativeReflection()->hasMethod($setter)) { |
||
| 108 | $refMethod = new ReflectionMethod($className, $setter); |
||
| 109 | |||
| 110 | $this->writeableDeclaringClass = $this->SetSetterProps( |
||
| 111 | $className, |
||
| 112 | $refMethod |
||
| 113 | ); |
||
| 114 | } |
||
| 115 | |||
| 116 | $this->type = $type; |
||
| 117 | } |
||
| 224 |