Test Failed
Push — master ( b480ce...8fe18f )
by Terzi
03:48
created

AbstractDetector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setNext() 0 3 1
A __invoke() 0 11 3
1
<?php
2
3
namespace Terranet\Administrator\Field\Detectors;
4
5
use Doctrine\DBAL\Schema\Column;
6
use Illuminate\Database\Eloquent\Model;
7
use Terranet\Administrator\Contracts\Chainable;
8
9
abstract class AbstractDetector implements Chainable
10
{
11
    /** @var Chainable */
12
    protected $successor;
13
14
    /**
15
     * @param FieldDetector $successor
0 ignored issues
show
Bug introduced by
The type Terranet\Administrator\F...Detectors\FieldDetector 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...
16
     */
17
    public function setNext(Chainable $successor)
18
    {
19
        $this->successor = $successor;
20
    }
21
22
    /**
23
     * Execute the chain.
24
     *
25
     * @param string $column
26
     * @param Column $metadata
27
     * @param Model $model
28
     *
29
     * @return null|mixed
30
     */
31
    public function __invoke(string $column, Column $metadata, Model $model)
32
    {
33
        if ($this->authorize($column, $metadata, $model)) {
34
            return $this->detect($column, $metadata, $model);
35
        }
36
37
        if ($this->successor) {
38
            return call_user_func_array($this->successor, compact('column', 'metadata', 'model'));
0 ignored issues
show
Bug introduced by
$this->successor of type Terranet\Administrator\Contracts\Chainable is incompatible with the type callable expected by parameter $function of call_user_func_array(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
            return call_user_func_array(/** @scrutinizer ignore-type */ $this->successor, compact('column', 'metadata', 'model'));
Loading history...
39
        }
40
41
        return null;
42
    }
43
44
    /**
45
     * Authorize execution.
46
     *
47
     * @param string $column
48
     * @param Column $metadata
49
     * @param Model $model
50
     *
51
     * @return bool
52
     */
53
    abstract protected function authorize(string $column, Column $metadata, Model $model): bool;
54
55
    /**
56
     * Detect field class.
57
     *
58
     * @param string $column
59
     * @param Column $metadata
60
     * @param Model $model
61
     *
62
     * @return mixed
63
     */
64
    abstract protected function detect(string $column, Column $metadata, Model $model);
65
}