| Conditions | 5 |
| Paths | 4 |
| Total Lines | 58 |
| Code Lines | 27 |
| 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 |
||
| 108 | protected function build(): AmqpConnectionFactory |
||
| 109 | { |
||
| 110 | $config = $this->config; |
||
| 111 | |||
| 112 | if ($diff = array_diff(array_keys($config), array_keys(static::DEFAULTS))) { |
||
| 113 | throw new InvalidConfigException( |
||
| 114 | vsprintf( |
||
| 115 | 'Cannot create driver %s, received unknown arguments: %s!', |
||
| 116 | [ |
||
| 117 | (string) self::class, |
||
| 118 | implode(', ', $diff), |
||
| 119 | ] |
||
| 120 | ) |
||
| 121 | ); |
||
| 122 | } |
||
| 123 | |||
| 124 | $config = Collection::make(static::DEFAULTS)->merge($config)->all(); |
||
| 125 | |||
| 126 | $extension = $config['extension']; |
||
| 127 | |||
| 128 | if (empty($extension) || ! isset($this->extensions[$extension])) { |
||
| 129 | throw new InvalidConfigException( |
||
| 130 | vsprintf( |
||
| 131 | 'The given extension "%s" is not supported. Extensions supported are "%s"', |
||
| 132 | [ |
||
| 133 | $extension, |
||
| 134 | implode('", "', array_keys($this->extensions)), |
||
| 135 | ] |
||
| 136 | ) |
||
| 137 | ); |
||
| 138 | } |
||
| 139 | |||
| 140 | $config['user'] = $config['username']; |
||
| 141 | $config['pass'] = $config['password']; |
||
| 142 | |||
| 143 | // Remove unused properties. |
||
| 144 | unset($config['extension'], $config['username'], $config['password']); |
||
| 145 | |||
| 146 | // Remove the attributes with null value. |
||
| 147 | $config = array_filter( |
||
| 148 | $config, |
||
| 149 | function ($value) { |
||
| 150 | return null !== $value; |
||
| 151 | } |
||
| 152 | ); |
||
| 153 | |||
| 154 | $class = $this->extensions[$extension]; |
||
| 155 | |||
| 156 | if (! class_exists($class)) { |
||
| 157 | throw new ClassNotFoundException(vsprintf('Class %s not found.', [$class])); |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @var AmqpConnectionFactory $connection |
||
| 162 | */ |
||
| 163 | $connection = new $class($config); |
||
| 164 | |||
| 165 | return $connection; |
||
| 166 | } |
||
| 169 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths