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