DataSet::run()   C
last analyzed

Complexity

Conditions 11
Paths 5

Size

Total Lines 50
Code Lines 29

Duplication

Lines 18
Ratio 36 %

Importance

Changes 0
Metric Value
dl 18
loc 50
rs 5.4893
c 0
b 0
f 0
cc 11
eloc 29
nc 5
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of the ReportBundle package
5
 * 
6
 * (c) symball <http://simonball.me>
7
 * 
8
 * For the full copyright and license information, please view the LICENSE file 
9
 * that was distributed with this source code.
10
 */
11
12
namespace Symball\ReportBundle\Patterns;
13
14
use Symball\ReportBundle\Interfaces\PatternInterface;
15
use Symball\ReportBundle\Service\ReportBuilder;
16
17
/**
18
 * This pattern fills in the values for the various data points within the
19
 * current set
20
 *
21
 * @author Simon Ball <simonball at simonball dot me>
22
 */
23
class DataSet implements PatternInterface
24
{
25
26
    public function run(ReportBuilder &$context)
27
    {
28
        $data = $context->meta()->getDataSet();
29
        $nav = $context->nav();
30
31
        foreach ($data as $key => $fields) {
32
            foreach ($fields as $fieldKey => $options) {
33
                // TODO Make sanity check and don't have it in the drawing code
34
                if (!isset($options['visible']) || $options['visible'] !== true) {
35
                    continue;
36
                }
37
38
                $value = $options['value'];
39
                $context->write($value);
40
41
                // TODO Move this
42
                if (isset($options['display_options'])) {
43
                    foreach ($options['display_options'] as $option) {
44
                        switch ($option) {
45 View Code Duplication
                            case 'highlight_positive':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
                                if (0 < $value) {
47
                                    
48
                                    $color = $context->meta()->getOption('positive_color');
49
                                    $context->style('bg', (string) $nav, [
50
                                        'color' => $color
51
                                    ]);
52
                                }
53
54
                                break;
55 View Code Duplication
                            case 'highlight_negative':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
                                if (0 > $value) {
57
                                    $color = $context->meta()->getOption('negative_color');
58
                                    $context->style('bg', (string) $nav, [
59
                                        'color' => $color
60
                                    ]);
61
                                }
62
                                break;
63
                        }
64
                    }
65
                }
66
                $nav->right();
67
            }
68
            $nav->next();
69
        }
70
        // Draw the edge line
71
        $start = $nav->coord('current', 'initial');
72
        $end = $nav->coord('current', ($nav->row() - 1));
73
74
        $context->style('border', $start.':'.$end, ['edge' => 'left']);
75
    }
76
}
77