ReportStyle::addStyle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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\Service;
13
14
use Symball\ReportBundle\Service\ReportBuilder;
15
use Symball\ReportBundle\Interfaces\StyleInterface;
16
17
/**
18
 * The report style service acts as a front-end for predefined style operations
19
 * using a plug-in architecture
20
 *
21
 * @author Simon Ball <simonball at simonball dot me>
22
 */
23 View Code Duplication
class ReportStyle
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
24
{
25
    private $styles = array();
26
27
    /**
28
     * Add an extra styler object to the stack for later use
29
     *
30
     * @param StyleInterface $style
31
     * @param string         $alias
32
     */
33
    public function addStyle(StyleInterface $style, $alias)
34
    {
35
        $this->styles[$alias] = $style;
36
    }
37
38
    /**
39
     * A front-end for running style operations that are loaded on to the stack
40
     *
41
     * @param string        $alias
42
     * @param ReportBuilder $context
43
     * @param string        $coordString
44
     * @param array         $options
45
     * @return boolean Success condition
46
     * @throws \Exception when style function not available
47
     */
48
    public function run($alias, ReportBuilder &$context, $coordString, $options = array())
49
    {
50
51
        if (isset($this->styles[$alias])) {
52
            $this->styles[$alias]->run($context, $coordString, $options);
53
54
            return true;
55
        } else {
56
            throw new \Exception('Report style is not registered: ' . $alias);
57
        }
58
    }
59
60
    /**
61
     * Get a simple array list of the currently loaded style objects
62
     *
63
     * @return array
64
     */
65
    public function getStylesLoaded()
66
    {
67
        return array_keys($this->styles);
68
    }
69
}
70