Completed
Pull Request — develop (#76)
by
unknown
02:12
created

CriterionException   A

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
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Repository Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Repository Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Repository\Exceptions;
17
18
use Exception;
19
use Rinvex\Repository\Contracts\CriterionContract;
20
21
class CriterionException extends Exception
22
{
23
    public static function wrongCriterionType($criterion)
24
    {
25
        $type  = gettype($criterion);
26
        $value = $type === 'object' ? get_class($criterion) : $criterion;
27
28
        return new static('Given criterion with type ' . $type . " ane value " . $value . ' is not allowed');
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ane value does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
29
    }
30
31
    public static function classNotImplementContract($criterionClassName)
32
    {
33
        return new static('Given ' . $criterionClassName . ' class is not implement ' . CriterionContract::class . 'contract');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 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...
34
    }
35
36
    public static function wrongArraySignature(array $criterion)
37
    {
38
        return new static(
39
            '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 151 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...
40
            'Array with length "' . count($criterion) . '" given' );
41
    }
42
}
43