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