SortException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invalidDirectionSupplied() 0 8 1
A wrongRelationToSort() 0 7 1
1
<?php
2
3
namespace Neurony\Sort\Exceptions;
4
5
use Neurony\Sort\Objects\Sort;
6
7
class SortException extends \Exception
8
{
9
    /**
10
     * The exception to be thrown when an invalid direction is supplied as the argument.
11
     *
12
     * @param string $direction
13
     * @return static
14
     */
15
    public static function invalidDirectionSupplied($direction)
16
    {
17
        return new static(
18
            'Invalid sorting direction.'.PHP_EOL.
19
            'You provided the direction: "'.$direction.'".'.PHP_EOL.
20
            'Please provide one of these directions: '.implode('|', Sort::$directions).'.'
21
        );
22
    }
23
24
    /**
25
     * The exception to be thrown when trying to sort by an invalid relation type.
26
     *
27
     * @param string$relation
28
     * @param string $type
29
     * @return static
30
     * @internal param string $direction
31
     */
32
    public static function wrongRelationToSort($relation, $type)
33
    {
34
        return new static(
35
            'You can only sort records by the following relations: HasOne, BelongsTo.'.PHP_EOL.
36
            'The relation "'.$relation.'" is of type '.$type.' and cannot be sorted by.'
37
        );
38
    }
39
}
40