SoqlOrderDirection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseOrder() 0 9 3
1
<?php
2
3
/**
4
 * This file contains an abstract class with constants defining the order a Soda query could be returned in.
5
 *
6
 * @copyright 2015 Vladimir Jimenez
7
 * @license   https://github.com/allejo/PhpSoda/blob/master/LICENSE.md MIT
8
 */
9
10
namespace allejo\Socrata;
11
12
/**
13
 * An abstract class with constants defining the order a Soda query could be return in.
14
 *
15
 * @package allejo\Socrata
16
 * @since   0.1.0
17
 */
18
abstract class SoqlOrderDirection
19
{
20
    /**
21
     * The ascending clause Socrata expects
22
     */
23
    const ASC  = 'ASC';
24
25
    /**
26
     * The descending clause Socrata expects
27
     */
28
    const DESC = 'DESC';
29
30
    /**
31
     * Ensure that we have a proper sorting order, so return only valid ordering options
32
     *
33
     * @param  string $string The order to be checked if valid
34
     *
35
     * @throws \InvalidArgumentException  If an unsupported sort order was given
36
     *
37
     * @return string                     Supported sorting order option
38
     */
39
    public static function parseOrder ($string)
40
    {
41
        if ($string === self::ASC || $string === self::DESC)
42
        {
43
            return $string;
44
        }
45
46
        throw new \InvalidArgumentException(sprintf("An invalid sort order (%s) was given; you may only sort using ASC or DESC.", $string));
47
    }
48
}
49