GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#140)
by Max
24:34
created

GeneratorAssembler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * MageSpec
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the MIT License, that is bundled with this
8
 * package in the file LICENSE.
9
 * It is also available through the world-wide-web at this URL:
10
 *
11
 * http://opensource.org/licenses/MIT
12
 *
13
 * If you did not receive a copy of the license and are unable to obtain it
14
 * through the world-wide-web, please send an email
15
 * to <[email protected]> so we can send you a copy immediately.
16
 *
17
 * @category   MageTest
18
 * @package    PhpSpec_MagentoExtension
19
 *
20
 * @copyright  Copyright (c) 2012-2013 MageTest team and contributors.
21
 */
22
namespace MageTest\PhpSpec\MagentoExtension\Extension;
23
24
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\BlockGenerator;
25
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ControllerGenerator;
26
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ControllerSpecificationGenerator;
27
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\HelperGenerator;
28
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ModelGenerator;
29
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\ConfigGenerator;
30
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element\BlockElement;
31
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element\ControllerElement;
32
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element\HelperElement;
33
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element\ModelElement;
34
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\ModuleGenerator;
35
use PhpSpec\Process\Context\JsonExecutionContext;
36
use PhpSpec\ServiceContainer;
37
38
class GeneratorAssembler implements Assembler
39
{
40
    /**
41
     * @var array
42
     */
43
    private $params;
44
45
    public function __construct(array $params = [])
46
    {
47
        $this->params = $params;
48
    }
49
50
    /**
51
     * @param ServiceContainer $container
52
     */
53
    public function build(ServiceContainer $container)
54
    {
55
        $this->setCodeGenerators($container);
56
        $this->setXmlModuleGenerator($container);
57
        $this->setXmlConfigGenerator($container);
58
        $this->setXmlElementGenerators($container);
59
    }
60
61
    /**
62
     * @param ServiceContainer $container
63
     */
64
    private function setCodeGenerators(ServiceContainer $container)
65
    {
66
        $container->define('code_generator.generators.mage_model', function ($c) {
67
            return new ModelGenerator(
68
                $c->get('console.io'),
69
                $c->get('code_generator.templates'),
70
                $c->get('filesystem'),
71
                new JsonExecutionContext()
72
            );
73
        }, ['code_generator.generators']);
74
75
        $container->define('code_generator.generators.mage_block', function ($c) {
76
            return new BlockGenerator(
77
                $c->get('console.io'),
78
                $c->get('code_generator.templates'),
79
                $c->get('filesystem'),
80
                new JsonExecutionContext()
81
            );
82
        }, ['code_generator.generators']);
83
84
        $container->define('code_generator.generators.mage_helper', function ($c) {
85
            return new HelperGenerator(
86
                $c->get('console.io'),
87
                $c->get('code_generator.templates'),
88
                $c->get('filesystem'),
89
                new JsonExecutionContext()
90
            );
91
        }, ['code_generator.generators']);
92
93
        $container->define('code_generator.generators.mage_controller', function($c) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
94
            return new ControllerGenerator(
95
                $c->get('console.io'),
96
                $c->get('code_generator.templates'),
97
                $c->get('filesystem'),
98
                new JsonExecutionContext()
99
            );
100
        }, ['code_generator.generators']);
101
102
        $container->define('code_generator.generators.controller_specification', function($c) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
103
            return new ControllerSpecificationGenerator(
104
                $c->get('console.io'),
105
                $c->get('code_generator.templates'),
106
                $c->get('filesystem'),
107
                new JsonExecutionContext()
108
            );
109
        }, ['code_generator.generators']);
110
    }
111
112
    /**
113
     * @param ServiceContainer $container
114
     */
115
    private function setXmlModuleGenerator(ServiceContainer $container)
116
    {
117
        $params = $this->params;
118
        $container->define('xml_generator.generators.module', function ($c) use ($params) {
119
            $suite = $config = isset($params['mage_locator']) ? $params['mage_locator'] : $c->getParam('mage_locator',  array('main' => ''));
1 ignored issue
show
Unused Code introduced by
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
120
            if (isset($suite['src_path'])) {
121
                $etcPath = rtrim($suite['src_path'], '/') . DIRECTORY_SEPARATOR . '..'
122
                    . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR;
123
            } else {
124
                $etcPath = 'app/etc/';
125
            }
126
            $codePool = isset($suite['code_pool']) ? $suite['code_pool'] : 'local';
127
            return new ModuleGenerator(
128
                $etcPath,
129
                $c->get('filesystem'),
130
                $codePool
131
            );
132
        }, ['xml_generator.generators']);
133
    }
134
135
    /**
136
     * @param ServiceContainer $container
137
     */
138
    private function setXmlConfigGenerator(ServiceContainer $container)
139
    {
140
        $params = $this->params;
141
        $container->define('xml_generator.generators.config', function($c) use ($params) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
142
            $suite = $config = isset($params['mage_locator']) ? $params['mage_locator'] : $c->getParam('mage_locator',  array('main' => ''));
0 ignored issues
show
Unused Code introduced by
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
143
            $srcPath = isset($suite['src_path']) ? rtrim($suite['src_path'], '/') . DIRECTORY_SEPARATOR : 'src';
144
            $codePool = isset($suite['code_pool']) ? $suite['code_pool'] : 'local';
145
            $generator = new ConfigGenerator(
146
                $srcPath,
147
                $c->get('filesystem'),
148
                $c->get('xml.formatter'),
149
                $codePool
150
            );
151
152
            array_map(
153
                array($generator, 'addElementGenerator'),
154
                $c->getByTag('xml_generator.generators.config.element')
155
            );
156
157
            return $generator;
158
        }, ['xml_generator.generators']);
159
    }
160
161
    /**
162
     * @param ServiceContainer $container
163
     */
164
    private function setXmlElementGenerators(ServiceContainer $container)
165
    {
166
        $container->define('xml_generator.generators.config.element.block', function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
167
            return new BlockElement();
168
        }, ['xml_generator.generators.config.element']);
169
170
        $container->define('xml_generator.generators.config.element.helper', function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
171
            return new HelperElement();
172
        }, ['xml_generator.generators.config.element']);
173
174
        $container->define('xml_generator.generators.config.element.controller', function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
175
            return new ControllerElement();
176
        }, ['xml_generator.generators.config.element']);
177
178
        $container->define('xml_generator.generators.config.element.model', function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
179
            return new ModelElement();
180
        }, ['xml_generator.generators.config.element']);
181
    }
182
}
183