Completed
Pull Request — develop (#153)
by
unknown
02:22 queued 16s
created

CriterionException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A wrongCriterionType() 0 7 2
A classNotImplementContract() 0 4 1
A wrongArraySignature() 0 6 1
A missingPackage() 0 4 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. '.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 150 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
29
            'Array with length "'.count($criterion).'" given');
30
    }
31
32
    public static function missingPackage($methodName, $packageName)
33
    {
34
        return new static('Method '.$methodName.' is only available with "'.$packageName .'" package installed');
35
    }
36
}
37