InteractorProxyTrait::__call()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CCT\Component\Collections\Traits;
6
7
use CCT\Component\Collections\CollectionProxy;
8
9
trait InteractorProxyTrait
10
{
11
    /**
12
     * Gets the possible proxies for the class.
13
     *
14
     * @return array
15
     */
16
    protected abstract function getInteractorProxies(): array;
17
18
    /**
19
     * Dynamically access collection proxies.
20
     *
21
     * @param string $proxy
22
     * @param mixed $args
23
     *
24
     * @return CollectionProxy
25
     *
26
     * @throws \Exception
27
     */
28 13
    public function __call($proxy, $args = null)
29
    {
30 13
        $possibleProxies = CollectionProxy::$proxies;
31 13
        $proxies = array_intersect($possibleProxies, $this->getInteractorProxies());
32
33 13
        if (false === array_key_exists($proxy, $proxies)) {
34 1
            throw new \BadMethodCallException("Method [{$proxy}] does not exist on this collection instance.");
35
        }
36
37 12
        return new CollectionProxy($this, $proxy);
0 ignored issues
show
Bug introduced by
$this of type CCT\Component\Collection...ts\InteractorProxyTrait is incompatible with the type CCT\Component\Collections\CollectionInterface expected by parameter $collection of CCT\Component\Collection...ionProxy::__construct(). ( Ignorable by Annotation )

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

37
        return new CollectionProxy(/** @scrutinizer ignore-type */ $this, $proxy);
Loading history...
38
    }
39
}
40