SortException::invalidDirectionSupplied()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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