Passed
Push — main ( f1d53c...b55a20 )
by Ahmad
02:35
created

AbstractConditionalLikelihood::__call()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 17
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AhmadMayahi\Vision\Support;
6
7
use AhmadMayahi\Vision\Enums\Likelihood;
8
use Exception;
9
10
abstract class AbstractConditionalLikelihood
11
{
12
    public function __call(string $name, array $arguments)
13
    {
14
        if (false === str_starts_with($name, 'is')) {
15
            return ;
16
        }
17
18
        $property = lcfirst(substr($name, 2));
19
20
        $property = $this->conditionals()[$property] ?? $property;
21
22
        if (false === property_exists($this, $property)) {
23
            throw new Exception('Method not found!');
24
        }
25
26
        $likelihood = $arguments[0] ?? Likelihood::VERY_LIKELY;
27
28
        return $this->{$property} === Likelihood::fromKey($likelihood);
29
    }
30
31
    abstract protected function conditionals(): array;
32
}
33