| Conditions | 9 |
| Paths | 18 |
| Total Lines | 94 |
| Code Lines | 56 |
| 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 |
||
| 54 | public function __construct( |
||
| 55 | ClassReflection $classReflection, |
||
| 56 | Broker $broker, |
||
| 57 | string $propertyName |
||
| 58 | ) { |
||
| 59 | if ( |
||
| 60 | false === is_a( |
||
| 61 | $classReflection->getName(), |
||
| 62 | DaftObject::class, |
||
| 63 | true |
||
| 64 | ) |
||
| 65 | ) { |
||
| 66 | throw new InvalidArgumentException( |
||
| 67 | $classReflection->getName() . |
||
| 68 | ' is not an implementation of ' . |
||
| 69 | DaftObject::class |
||
| 70 | ); |
||
| 71 | } |
||
| 72 | |||
| 73 | $className = $classReflection->getName(); |
||
| 74 | |||
| 75 | $this->public = |
||
| 76 | in_array( |
||
| 77 | $propertyName, |
||
| 78 | $className::DaftObjectPublicGetters(), |
||
| 79 | true |
||
| 80 | ) || |
||
| 81 | in_array( |
||
| 82 | $propertyName, |
||
| 83 | $className::DaftObjectPublicSetters(), |
||
| 84 | true |
||
| 85 | ); |
||
| 86 | |||
| 87 | $type = new MixedType(); |
||
| 88 | |||
| 89 | $getter = 'Get' . ucfirst($propertyName); |
||
| 90 | $setter = 'Set' . ucfirst($propertyName); |
||
| 91 | |||
| 92 | if ($classReflection->getNativeReflection()->hasMethod($getter)) { |
||
| 93 | $this->readable = true; |
||
| 94 | |||
| 95 | $refMethod = new ReflectionMethod($className, $getter); |
||
| 96 | |||
| 97 | if ($refMethod->isStatic()) { |
||
| 98 | throw new InvalidArgumentException( |
||
| 99 | 'Implementations of ' . |
||
| 100 | DaftObject::class . |
||
| 101 | ' must not contain static getters.' |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($refMethod->hasReturnType()) { |
||
| 106 | $type = TypehintHelper::decideTypeFromReflection( |
||
| 107 | $refMethod->getReturnType() |
||
| 108 | ); |
||
| 109 | } |
||
| 110 | |||
| 111 | $this->readableDeclaringClass = $broker->getClassFromReflection( |
||
| 112 | $refMethod->getDeclaringClass(), |
||
| 113 | $refMethod->getDeclaringClass()->getName() |
||
| 114 | ); |
||
| 115 | } |
||
| 116 | |||
| 117 | if ($classReflection->getNativeReflection()->hasMethod($setter)) { |
||
| 118 | $this->writeable = true; |
||
| 119 | |||
| 120 | $refMethod = new ReflectionMethod($className, $setter); |
||
| 121 | |||
| 122 | if ($refMethod->getNumberOfRequiredParameters() < 1) { |
||
| 123 | throw new InvalidArgumentException( |
||
| 124 | 'Implementations of ' . |
||
| 125 | DaftObject::class . |
||
| 126 | ' must require at least one parameter on all setters!' |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | |||
| 130 | $refParam = $refMethod->getParameters()[0]; |
||
| 131 | |||
| 132 | if ($refParam->hasType()) { |
||
|
|
|||
| 133 | $type = TypehintHelper::decideTypeFromReflection( |
||
| 134 | $refParam->getType(), |
||
| 135 | null, |
||
| 136 | $className, |
||
| 137 | false |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | |||
| 141 | $this->writeableDeclaringClass = $broker->getClassFromReflection( |
||
| 142 | $refMethod->getDeclaringClass(), |
||
| 143 | $refMethod->getDeclaringClass()->getName() |
||
| 144 | ); |
||
| 145 | } |
||
| 146 | |||
| 147 | $this->type = $type; |
||
| 148 | } |
||
| 189 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.