| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| Code Lines | 19 |
| 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 |
||
| 30 | protected function createClient(Container $container, $token) |
||
| 31 | { |
||
| 32 | $loop = Factory::create(); |
||
| 33 | $client = new class($loop, $token) extends Client { |
||
| 34 | /** |
||
| 35 | * @var bool |
||
| 36 | */ |
||
| 37 | protected $fallbackMode = false; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var array |
||
| 41 | */ |
||
| 42 | protected $fallbackSubscribers = []; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param bool $value |
||
| 46 | * @return $this |
||
| 47 | */ |
||
| 48 | public function setFallbackMode(bool $value = true) |
||
| 49 | { |
||
| 50 | if ($this->fallbackMode !== $value) { |
||
| 51 | foreach ($this->fallbackSubscribers as $subscriber) { |
||
| 52 | $subscriber($value); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | $this->fallbackMode = $value; |
||
| 56 | return $this; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return bool |
||
| 61 | */ |
||
| 62 | public function isFallbackMode() |
||
| 63 | { |
||
| 64 | return $this->fallbackMode; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param \Closure $callback |
||
| 69 | * @return $this |
||
| 70 | */ |
||
| 71 | public function onChangeFallbackMode(\Closure $callback) |
||
| 72 | { |
||
| 73 | $this->fallbackSubscribers[] = $callback; |
||
| 74 | return $this; |
||
| 75 | } |
||
| 76 | }; |
||
| 77 | |||
| 78 | // Bind container |
||
| 79 | $container->instance(LoopInterface::class, $loop); |
||
| 80 | $container->instance(Client::class, $client); |
||
| 81 | |||
| 82 | return $client; |
||
| 83 | } |
||
| 84 | |||
| 101 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.