Completed
Push — develop ( d6a5df...b082c1 )
by René
02:36
created

ArrayUtility   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 5
Bugs 2 Features 1
Metric Value
wmc 7
c 5
b 2
f 1
lcom 0
cbo 1
dl 0
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildIndexActionArray() 0 13 2
B errorReport() 0 18 5
1
<?php
2
/**
3
 * Class ArrayUtility
4
 */
5
namespace HDNET\OnpageIntegration\Utility;
6
7
use TYPO3\CMS\Core\Utility\GeneralUtility;
8
9
/**
10
 * Class ArrayUtility
11
 */
12
class ArrayUtility
13
{
14
15
    /**
16
     * Append the errors of an api call to
17
     * metaDataArray
18
     *
19
     * @param $metaDataArray
20
     * @param $section
21
     */
22
    public static function buildIndexActionArray(&$metaDataArray, $section)
23
    {
24
        $loader = GeneralUtility::makeInstance(\HDNET\OnpageIntegration\Loader\ApiResultLoader::class);
25
26
        for ($i = 0; $i < count($metaDataArray[0]); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
27
28
            $graphDataArray = $loader->load('zoom_' . $section . '_' . $i . '_graph');
29
            $errorReportyKey = $metaDataArray[0][$i]['errors'];
30
31
            $metaDataArray[0][$i]['errors'] = self::errorReport($graphDataArray, $errorReportyKey);
32
            $metaDataArray[0][$i]['test'] = $graphDataArray;
33
        }
34
    }
35
36
    /**
37
     * Determine the error report of an aspect
38
     *
39
     * @param $graphApiCallResult
40
     * @param $errorReportKey
41
     *
42
     * @return int
43
     */
44
    protected static function errorReport($graphApiCallResult,$errorReportKey) {
45
        $totalErrors = 0;
46
47
        foreach($graphApiCallResult as $element) {
48
49
            if(in_array('sum', $errorReportKey)) {
50
                if(in_array($errorReportKey['hidden'], $element)) {
51
                    continue;
52
                }
53
                $totalErrors += $element['count'];
54
            }
55
56
            if(in_array($errorReportKey['show'], $element)) {
57
                $totalErrors += $element['count'];
58
            }
59
        }
60
        return $totalErrors;
61
    }
62
}
63