SortService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 6
c 4
b 0
f 1
lcom 0
cbo 3
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B cmp() 0 14 5
A sortArray() 0 8 1
1
<?php
2
/**
3
 * Class description
4
 *
5
 * @package HDNET\CacheCheck\Service
6
 * @author  Julian Seitz
7
 */
8
9
namespace HDNET\CacheCheck\Service;
10
11
use HDNET\CacheCheck\Domain\Model\Cache;
12
use TYPO3\CMS\Core\Utility\MathUtility;
13
14
/**
15
 * Class SortService
16
 *
17
 */
18
class SortService extends AbstractService
19
{
20
21
    /**
22
     * First sorting of caches
23
     *
24
     * @param Cache $a
25
     * @param Cache $b
26
     *
27
     * @return int
28
     */
29
    public function cmp(Cache $a, Cache $b)
30
    {
31
        // current in analyse mode
32
        if ($a->getIsInAnalyseMode() !== $b->getIsInAnalyseMode()) {
33
            return $a->getIsInAnalyseMode() ? -1 : 1;
34
        }
35
36
        // check if the item has Dynamic information
37
        if ((bool)$a->getDynamicKpi() !== (bool)$b->getDynamicKpi()) {
38
            return (bool)$a->getDynamicKpi() ? -1 : 1;
39
        }
40
41
        return MathUtility::forceIntegerInRange(strcmp($a->getName(), $b->getName()), -1, 1, 0);
42
    }
43
44
    /**
45
     * Sorting of given array
46
     *
47
     * @param array $array
48
     *
49
     * @return array
50
     */
51
    public function sortArray($array)
52
    {
53
        usort($array, [
54
            $this,
55
            'cmp'
56
        ]);
57
        return $array;
58
    }
59
}
60