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

AbstractConditionalLikelihood   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __call() 0 17 3
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