DatabaseUtils::parseTaskPriority()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
rs 9.2
nc 4
cc 4
eloc 11
nop 1
1
<?php
2
3
namespace Machdas\Utils;
4
5
class DatabaseUtils
6
{
7
8
    /**
9
     * @param string $direction
10
     * @return string
11
     */
12
    public static function ensureOrderDirection(string $direction) : string
13
    {
14
        $direction = strtolower($direction);
15
16
        if (!in_array($direction, ['asc', 'desc'])) {
17
            $direction = 'asc';
18
        }
19
20
        return $direction;
21
    }
22
23
    /**
24
     * @param string|int $priority
25
     * @return int
26
     */
27
    public static function parseTaskPriority($priority) : int
28
    {
29
        switch ($priority) {
30
            case 'normal':
31
                $priority = 500;
32
                break;
33
            case 'low':
34
                $priority = 100;
35
                break;
36
            case 'high':
37
                $priority = 900;
38
        }
39
40
        return (int) $priority;
41
    }
42
}
43