| Conditions | 14 |
| Paths | 181 |
| Total Lines | 92 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 37 | protected function checkImplementation($middleware) |
||
| 38 | { |
||
| 39 | if (false === class_exists($middleware)) { |
||
| 40 | $this->addError( |
||
| 41 | 'Class name given was not found: "%s".', |
||
| 42 | 1489070202, |
||
| 43 | [$middleware] |
||
| 44 | ); |
||
| 45 | } else { |
||
| 46 | $interfaces = class_implements($middleware); |
||
| 47 | |||
| 48 | if (false === in_array(MiddlewareInterface::class, $interfaces)) { |
||
| 49 | $this->addError( |
||
| 50 | 'Class "%s" must implement "%s".', |
||
| 51 | 1489070282, |
||
| 52 | [$middleware, MiddlewareInterface::class] |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | |||
| 56 | $signalsFound = []; |
||
| 57 | foreach ($interfaces as $interface) { |
||
| 58 | if (in_array(MiddlewareSignal::class, class_implements($interface))) { |
||
| 59 | $signalsFound[] = $interface; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | if (empty($signalsFound)) { |
||
| 64 | $this->addError( |
||
| 65 | 'Class "%s" must implement one interface that extends "%s".', |
||
| 66 | 1489074248, |
||
| 67 | [$middleware, MiddlewareSignal::class] |
||
| 68 | ); |
||
| 69 | } elseif (count($signalsFound) > 1) { |
||
| 70 | $this->addError( |
||
| 71 | 'Class "%s" must implement only one interface that extends "%s"; %s were found: "%s"', |
||
| 72 | 1489074852, |
||
| 73 | [ |
||
| 74 | $middleware, |
||
| 75 | MiddlewareSignal::class, |
||
| 76 | count($signalsFound), |
||
| 77 | implode('", "', $signalsFound) |
||
| 78 | ] |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | |||
| 82 | if (false === in_array(Before::class, $interfaces) |
||
| 83 | && false === in_array(After::class, $interfaces) |
||
| 84 | ) { |
||
| 85 | $this->addError( |
||
| 86 | 'Class "%s" must implement at least one of these interfaces: "%s", "%s".', |
||
| 87 | 1489074986, |
||
| 88 | [ |
||
| 89 | $middleware, |
||
| 90 | Before::class, |
||
| 91 | After::class |
||
| 92 | ] |
||
| 93 | ); |
||
| 94 | } |
||
| 95 | |||
| 96 | if (false === $this->result->hasErrors()) { |
||
| 97 | if (in_array(BeginSignal::class, $interfaces) |
||
| 98 | && in_array(Before::class, $interfaces) |
||
| 99 | ) { |
||
| 100 | $this->addError( |
||
| 101 | 'Class "%s" implements interfaces "%s" and "%s", but the signal "before beginning" is (obviously) invalid. Please remove "%s" dependency.', |
||
| 102 | 1489075185, |
||
| 103 | [ |
||
| 104 | $middleware, |
||
| 105 | Before::class, |
||
| 106 | BeginSignal::class, |
||
| 107 | Before::class, |
||
| 108 | ] |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | |||
| 112 | if (in_array(EndSignal::class, $interfaces) |
||
| 113 | && in_array(After::class, $interfaces) |
||
| 114 | ) { |
||
| 115 | $this->addError( |
||
| 116 | 'Class "%s" implements interfaces "%s" and "%s", but the signal "after the end" is (obviously) invalid. Please remove "%s" dependency.', |
||
| 117 | 1489075242, |
||
| 118 | [ |
||
| 119 | $middleware, |
||
| 120 | After::class, |
||
| 121 | EndSignal::class, |
||
| 122 | After::class, |
||
| 123 | ] |
||
| 124 | ); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 |