CriterionException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A wrongCriterionType() 0 7 2
A classNotImplementContract() 0 4 1
A wrongArraySignature() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Repository\Exceptions;
6
7
use Exception;
8
use Rinvex\Repository\Contracts\CriterionContract;
9
10
class CriterionException extends Exception
11
{
12
    public static function wrongCriterionType($criterion)
13
    {
14
        $type = gettype($criterion);
15
        $value = $type === 'object' ? get_class($criterion) : $criterion;
16
17
        return new static('Given criterion with type '.$type.' and value '.$value.' is not allowed');
18
    }
19
20
    public static function classNotImplementContract($criterionClassName)
21
    {
22
        return new static('Given '.$criterionClassName.' class is not implement '.CriterionContract::class.'contract');
23
    }
24
25
    public static function wrongArraySignature(array $criterion)
26
    {
27
        return new static(
28
            'Array signature for criterion instantiating must contain only two elements in case of sequential array and one in case of assoc array. '.
29
            'Array with length "'.count($criterion).'" given');
30
    }
31
}
32