Passed
Push — master ( 24c12a...33eab4 )
by Marcio
03:56
created

InvalidArgumentException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Ballybran\Core\Http\Middleware\Exception;
4
use Throwable;
5
6
class InvalidArgumentException extends InvalidArgumentException {
7
8
    public const ERROR_MESSAGE = 'The middleware is not a valid %s and is not passed in the Container. Given: %s';
9
10
    /**
11
     * @var mixed|null 
12
     */
13
    private $invalidMiddleware;
14
15
    public function __construct( $invalidMiddleware = null, $code = 0, Throwable $previous = null )
16
    {
17
        $message = \sprintf(self::ERROR_MESSAGE, MiddlewareInterface::class, $this->castStageToString($invalidMiddleware));
0 ignored issues
show
Bug introduced by
The type Ballybran\Core\Http\Midd...ion\MiddlewareInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
        parent::__construct( $message, $code, $previous);
19
        $this->invalidMiddleware = $invalidMiddleware;
20
    }
21
22
    /**
23
     *  return the invalid middleware
24
     * @return mixed|null
25
     */
26
    public function getInvalidMiddleware(){
27
        return $this->invalidMiddleware;
28
    }
29
    private function castStageToString(string $stage) : string{
30
        
31
        if(\is_scalar($stage)){
0 ignored issues
show
introduced by
The condition is_scalar($stage) is always true.
Loading history...
32
            return (string) $stage;
33
        }
34
35
        if(\is_scalar($stage)){
36
            return \json_encode($stage) ?: 'array';
37
        }
38
        
39
        if(\is_object($stage)){
40
            return \get_class($stage) ?: 'array';
41
        }
42
43
        return \json_encode($stage) ?: 'Closure';
44
        
45
    }
46
47
}