Completed
Push — master ( 704cc1...66345b )
by FX
05:52
created

GraphCampaignsValues::getValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 1
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright (c) 2017 Francois-Xavier Soubirou.
5
 *
6
 * This file is part of ci-report.
7
 *
8
 * ci-report is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * ci-report is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with ci-report. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
declare(strict_types=1);
22
23
namespace AppBundle\Twig;
24
25
use Twig_Extension;
26
use Twig_SimpleFunction;
27
28
/**
29
 * graph.js values from campaigns array class Twig extension.
30
 *
31
 * @category  ci-report app
32
 *
33
 * @author    Francois-Xavier Soubirou <[email protected]>
34
 * @copyright 2017 Francois-Xavier Soubirou
35
 * @license   http://www.gnu.org/licenses/   GPLv3
36
 *
37
 * @see      https://www.ci-report.io
38
 */
39
class GraphCampaignsValues extends Twig_Extension
40
{
41
    /**
42
     * Returns a list of functions to add to the existing list.
43
     *
44
     * @return array
45
     */
46
    public function getFunctions(): array
47
    {
48
        return array(
49
            new Twig_SimpleFunction('graphLineCampaignsValues', array($this, 'getValues')),
50
        );
51
    }
52
53
    /**
54
     * Return values of graph lines for campaigns.
55
     *
56
     * @param array $campaigns Array of campaigns
57
     *
58
     * @return array
59
     */
60
    public function getValues(array $campaigns): array
61
    {
62
        $xAxisValues = '';
63
        $redValues = '';
64
        $yellowValues = '';
65
        $greenValues = '';
66
67
        $index = count($campaigns);
68
        while ($index) {
69
            $campaign = $campaigns[--$index];
70
            $xAxisValues .= '"#'.$campaign->getRefid().'",';
71
            $redValues .= $campaign->getErrored() + $campaign->getFailed().',';
72
            $yellowValues .= $campaign->getErrored() + $campaign->getFailed() + $campaign->getSkipped().',';
73
            $greenValues .= $campaign->getErrored() + $campaign->getFailed() + $campaign->getSkipped() + $campaign->getPassed().',';
74
        }
75
76
        return array(
77
            'xAxis' => $xAxisValues,
78
            'red' => $redValues,
79
            'yellow' => $yellowValues,
80
            'green' => $greenValues,
81
        );
82
    }
83
}
84