Completed
Push — master ( 7a069b...4da1f4 )
by Paweł
11s
created

ThemeConfiguration::addOptionalPathField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Core Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 *
14
 *
15
 * This file is part of the Sylius package.
16
 *
17
 * (c) Paweł Jędrzejewski
18
 *
19
 * For the full copyright and license information, please view the LICENSE
20
 * file that was distributed with this source code.
21
 */
22
23
namespace SWP\Bundle\CoreBundle\Theme\Configuration;
24
25
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
26
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
27
use Symfony\Component\Config\Definition\ConfigurationInterface;
28
29
/**
30
 * @author Kamil Kokot <[email protected]>
31
 * @author Paweł Mikołajczuk <[email protected]>
32
 */
33
final class ThemeConfiguration implements ConfigurationInterface
34
{
35
    /**
36
     * {@inheritdoc}
37
     */
38 101
    public function getConfigTreeBuilder()
39
    {
40 101
        $treeBuilder = new TreeBuilder();
41 101
        $rootNodeDefinition = $treeBuilder->root('sylius_theme');
42
43 101
        $rootNodeDefinition->ignoreExtraKeys();
44
45 101
        $this->addRequiredNameField($rootNodeDefinition);
46 101
        $this->addOptionalTitleField($rootNodeDefinition);
47 101
        $this->addOptionalDescriptionField($rootNodeDefinition);
48 101
        $this->addOptionalPathField($rootNodeDefinition);
49 101
        $this->addOptionalParentsList($rootNodeDefinition);
50 101
        $this->addOptionalScreenshotsList($rootNodeDefinition);
51 101
        $this->addOptionalAuthorsList($rootNodeDefinition);
52 101
        $this->addOptionalConfig($rootNodeDefinition);
53
        $this->addOptionalGeneratedData($rootNodeDefinition);
54 101
55
        return $treeBuilder;
56
    }
57
58
    /**
59
     * @param ArrayNodeDefinition $rootNodeDefinition
60 101
     */
61
    private function addRequiredNameField(ArrayNodeDefinition $rootNodeDefinition)
62 101
    {
63 101
        $rootNodeDefinition->children()->scalarNode('name')->isRequired()->cannotBeEmpty();
64
    }
65
66
    /**
67
     * @param ArrayNodeDefinition $rootNodeDefinition
68 101
     */
69
    private function addOptionalTitleField(ArrayNodeDefinition $rootNodeDefinition)
70 101
    {
71 101
        $rootNodeDefinition->children()->scalarNode('title')->cannotBeEmpty();
72
    }
73
74
    /**
75
     * @param ArrayNodeDefinition $rootNodeDefinition
76 101
     */
77
    private function addOptionalDescriptionField(ArrayNodeDefinition $rootNodeDefinition)
78 101
    {
79 101
        $rootNodeDefinition->children()->scalarNode('description')->cannotBeEmpty();
80
    }
81
82
    /**
83
     * @param ArrayNodeDefinition $rootNodeDefinition
84 101
     */
85
    private function addOptionalPathField(ArrayNodeDefinition $rootNodeDefinition)
86 101
    {
87 101
        $rootNodeDefinition->children()->scalarNode('path')->cannotBeEmpty();
88
    }
89
90
    /**
91
     * @param ArrayNodeDefinition $rootNodeDefinition
92 101
     */
93
    private function addOptionalParentsList(ArrayNodeDefinition $rootNodeDefinition)
94 101
    {
95
        $parentsNodeDefinition = $rootNodeDefinition->children()->arrayNode('parents');
96 101
        $parentsNodeDefinition
97 101
            ->requiresAtLeastOneElement()
98 101
            ->performNoDeepMerging()
99 101
            ->prototype('scalar')
100
            ->cannotBeEmpty()
101 101
        ;
102
    }
103
104
    /**
105
     * @param ArrayNodeDefinition $rootNodeDefinition
106 101
     */
107
    private function addOptionalConfig(ArrayNodeDefinition $rootNodeDefinition)
108 101
    {
109
        $configNodeDefinition = $rootNodeDefinition->children()->arrayNode('config');
110 101
        $configNodeDefinition
111 101
            ->requiresAtLeastOneElement()
112 101
            ->performNoDeepMerging()
113
            ->prototype('variable')
114
        ;
115 101
116 101
        $configNodeDefinition->children()->variableNode('defaultTemplates');
117
    }
118
119
    /**
120
     * @param ArrayNodeDefinition $rootNodeDefinition
121 101
     */
122
    private function addOptionalGeneratedData(ArrayNodeDefinition $rootNodeDefinition)
123 101
    {
124
        $generatedDataNodeDefinition = $rootNodeDefinition->children()->arrayNode('generatedData');
125 101
        $this->addOptionalGeneratedRoutesData($generatedDataNodeDefinition);
126 101
        $this->addOptionalGeneratedMenusData($generatedDataNodeDefinition);
127
        $this->addOptionalGeneratedContainersData($generatedDataNodeDefinition);
128
        $this->addOptionalGeneratedWidgetsData($generatedDataNodeDefinition);
129
        $this->addOptionalGenerateContentListsData($generatedDataNodeDefinition);
130 101
    }
131
132
    /**
133 101
     * @param ArrayNodeDefinition $generatedDataNodeDefinition
134
     */
135
    private function addOptionalGeneratedRoutesData(ArrayNodeDefinition $generatedDataNodeDefinition)
136 101
    {
137 101
        $routesNodeDefinition = $generatedDataNodeDefinition->children()->arrayNode('routes');
138
        $routesNodeDefinition->requiresAtLeastOneElement();
139
140 101
        /** @var ArrayNodeDefinition $routeNodeDefinition */
141 101
        $routeNodeDefinition = $routesNodeDefinition->prototype('array');
142
        $routeNodeDefinition
143
            ->validate()
144 101
            ->ifTrue(function ($route) {
145
                return [] === $route;
146
            })
147 101
            ->thenInvalid('Route cannot be empty!')
148 101
        ;
149 101
150 101
        $routeNodeBuilder = $routeNodeDefinition->children();
151 101
        $routeNodeBuilder->scalarNode('name')->cannotBeEmpty();
152
        $routeNodeBuilder->scalarNode('slug')->cannotBeEmpty();
153
        $routeNodeBuilder->scalarNode('type')->cannotBeEmpty();
154
        $routeNodeBuilder->scalarNode('parent')->defaultNull();
155
        $routeNodeBuilder->scalarNode('templateName')->defaultNull();
156 101
        $routeNodeBuilder->scalarNode('articlesTemplateName')->defaultNull();
157
        $routeNodeBuilder->scalarNode('numberOfArticles')->defaultNull();
158 101
    }
159
160 101
    /**
161 101
     * @param ArrayNodeDefinition $generatedDataNodeDefinition
162
     */
163
    private function addOptionalGeneratedMenusData(ArrayNodeDefinition $generatedDataNodeDefinition)
164
    {
165 101
        $menusNodeDefinition = $generatedDataNodeDefinition->children()->arrayNode('menus');
166
        $menusNodeDefinition->requiresAtLeastOneElement();
167 101
168 101
        /** @var ArrayNodeDefinition $menuNodeDefinition */
169 101
        $menuNodeDefinition = $menusNodeDefinition->prototype('array');
170 101
        $menuNodeDefinition
171 101
            ->validate()
172
            ->ifTrue(function ($menu) {
173
                return [] === $menu;
174 101
            })
175 101
            ->thenInvalid('Menu cannot be empty!')
176 101
        ;
177 101
178 101
        $menuNodeBuilder = $menuNodeDefinition->children();
179 101
        $menuNodeBuilder->scalarNode('name')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
180
        $menuNodeBuilder->scalarNode('label')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
181
        $menuNodeBuilder->scalarNode('uri')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
182
        $menuNodeBuilder->scalarNode('route')->cannotBeEmpty()->defaultNull()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
183
184
        // 1st level of children
185
        $childrensNodeDefinition = $menuNodeBuilder->arrayNode('children');
186
        /** @var ArrayNodeDefinition $childrenNodeDefinition */
187
        $childrenNodeDefinition = $childrensNodeDefinition->prototype('array');
188
        $childrenNodeDefinition
189
            ->validate()
190
            ->ifTrue(function ($menu) {
191
                return [] === $menu;
192
            })
193
            ->thenInvalid('Menu cannot be empty!')
194
        ;
195
196
        $childrenNodeBuilder = $childrenNodeDefinition->children();
197
        $childrenNodeBuilder->scalarNode('name')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
198
        $childrenNodeBuilder->scalarNode('label')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
199
        $childrenNodeBuilder->scalarNode('uri')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
200
        $childrenNodeBuilder->scalarNode('route')->cannotBeEmpty()->defaultNull()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
201
202
        // 2nd level of children
203
        $childrensChildrensNodeDefinition = $childrenNodeBuilder->arrayNode('children');
204
        /** @var ArrayNodeDefinition $childrensChildrenNodeDefinition */
205
        $childrensChildrenNodeDefinition = $childrensChildrensNodeDefinition->prototype('array');
206
        $childrensChildrenNodeDefinition
207
            ->validate()
208
            ->ifTrue(function ($menu) {
209
                return [] === $menu;
210
            })
211
            ->thenInvalid('Menu cannot be empty!')
212
        ;
213
214
        $childrenNodeBuilder = $childrensChildrenNodeDefinition->children();
215
        $childrenNodeBuilder->scalarNode('name')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
216
        $childrenNodeBuilder->scalarNode('label')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
217
        $childrenNodeBuilder->scalarNode('uri')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
218
        $childrenNodeBuilder->scalarNode('route')->cannotBeEmpty()->defaultNull()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
219
    }
220
221
    /**
222
     * @param ArrayNodeDefinition $generatedDataNodeDefinition
223
     */
224
    private function addOptionalGeneratedContainersData(ArrayNodeDefinition $generatedDataNodeDefinition)
225
    {
226
        $containersNodeDefinition = $generatedDataNodeDefinition->children()->arrayNode('containers');
227
        $containersNodeDefinition->requiresAtLeastOneElement();
228
229
        /** @var ArrayNodeDefinition $containerNodeDefinition */
230
        $containerNodeDefinition = $containersNodeDefinition->prototype('array');
231
        $containerNodeDefinition
232
            ->validate()
233
            ->ifTrue(function ($widget) {
234
                return [] === $widget;
235
            })
236
            ->thenInvalid('Widget cannot be empty!')
237
        ;
238
239
        $widgetNodeBuilder = $containerNodeDefinition->children();
240
        $widgetNodeBuilder->scalarNode('name')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
241
        $widgetNodeBuilder->scalarNode('styles')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
242
        $widgetNodeBuilder->booleanNode('visible')->defaultTrue()->end();
243
        $widgetNodeBuilder->variableNode('data')->cannotBeEmpty()->end();
244
        $widgetNodeBuilder->scalarNode('cssClass')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
245
    }
246
247 View Code Duplication
    private function addOptionalGenerateContentListsData(ArrayNodeDefinition $generatedDataNodeDefinition)
0 ignored issues
show
Duplication introduced by
This method 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...
248
    {
249
        $containersNodeDefinition = $generatedDataNodeDefinition->children()->arrayNode('contentLists');
250
        $containersNodeDefinition->requiresAtLeastOneElement();
251
252
        /** @var ArrayNodeDefinition $containerNodeDefinition */
253
        $containerNodeDefinition = $containersNodeDefinition->prototype('array');
254
        $containerNodeDefinition
255
            ->validate()
256
            ->ifTrue(function ($widget) {
257
                return [] === $widget;
258
            })
259
            ->thenInvalid('Content List cannot be empty!')
260
        ;
261
262
        $widgetNodeBuilder = $containerNodeDefinition->children();
263
        $widgetNodeBuilder->scalarNode('name')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
264
        $widgetNodeBuilder->scalarNode('type')->cannotBeEmpty()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
265
        $widgetNodeBuilder->scalarNode('description')->defaultNull()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
266
        $widgetNodeBuilder->scalarNode('limit')->defaultNull()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
267
        $widgetNodeBuilder->scalarNode('cacheLifeTime')->defaultNull()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
268
        $widgetNodeBuilder->scalarNode('filters')->defaultNull()->end();
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...arNodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
269
    }
270
271 View Code Duplication
    private function addOptionalGeneratedWidgetsData(ArrayNodeDefinition $generatedDataNodeDefinition)
0 ignored issues
show
Duplication introduced by
This method 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...
272
    {
273
        $widgetsNodeDefinition = $generatedDataNodeDefinition->children()->arrayNode('widgets');
274
        $widgetsNodeDefinition->requiresAtLeastOneElement();
275
276
        /** @var ArrayNodeDefinition $menuNodeDefinition */
277
        $widgetNodeDefinition = $widgetsNodeDefinition->prototype('array');
278
        $widgetNodeDefinition
279
            ->validate()
280
            ->ifTrue(function ($widget) {
281
                return [] === $widget;
282
            })
283
            ->thenInvalid('Widget cannot be empty!')
284
        ;
285
286
        $widgetNodeBuilder = $widgetNodeDefinition->children();
287
        $widgetNodeBuilder->scalarNode('name')->cannotBeEmpty()->end();
288
        $widgetNodeBuilder->scalarNode('type')->cannotBeEmpty()->end();
289
        $widgetNodeBuilder->booleanNode('visible')->defaultTrue()->end();
290
        $widgetNodeBuilder->variableNode('parameters')->cannotBeEmpty()->end();
291
        $widgetNodeBuilder->arrayNode('containers')->requiresAtLeastOneElement()->prototype('scalar')->end();
292
    }
293
294
    /**
295
     * @param ArrayNodeDefinition $rootNodeDefinition
296
     */
297
    private function addOptionalScreenshotsList(ArrayNodeDefinition $rootNodeDefinition)
298
    {
299
        $screenshotsNodeDefinition = $rootNodeDefinition->children()->arrayNode('screenshots');
300
        $screenshotsNodeDefinition
301
            ->requiresAtLeastOneElement()
302
            ->performNoDeepMerging()
303
        ;
304
305
        /** @var ArrayNodeDefinition $screenshotNodeDefinition */
306
        $screenshotNodeDefinition = $screenshotsNodeDefinition->prototype('array');
307
308
        $screenshotNodeDefinition
309
            ->validate()
310
            ->ifTrue(function ($screenshot) {
311
                return [] === $screenshot || ['path' => ''] === $screenshot;
312
            })
313
            ->thenInvalid('Screenshot cannot be empty!')
314
        ;
315
        $screenshotNodeDefinition
316
            ->beforeNormalization()
317
            ->ifString()
318
            ->then(function ($value) {
319
                return ['path' => $value];
320
            })
321
        ;
322
323
        $screenshotNodeBuilder = $screenshotNodeDefinition->children();
324
        $screenshotNodeBuilder->scalarNode('path')->isRequired();
325
        $screenshotNodeBuilder->scalarNode('title')->cannotBeEmpty();
326
        $screenshotNodeBuilder->scalarNode('description')->cannotBeEmpty();
327
    }
328
329
    /**
330
     * @param ArrayNodeDefinition $rootNodeDefinition
331
     */
332
    private function addOptionalAuthorsList(ArrayNodeDefinition $rootNodeDefinition)
333
    {
334
        $authorsNodeDefinition = $rootNodeDefinition->children()->arrayNode('authors');
335
        $authorsNodeDefinition
336
            ->requiresAtLeastOneElement()
337
            ->performNoDeepMerging()
338
        ;
339
340
        /** @var ArrayNodeDefinition $authorNodeDefinition */
341
        $authorNodeDefinition = $authorsNodeDefinition->prototype('array');
342
        $authorNodeDefinition
343
            ->validate()
344
            ->ifTrue(function ($author) {
345
                return [] === $author;
346
            })
347
            ->thenInvalid('Author cannot be empty!')
348
        ;
349
350
        $authorNodeBuilder = $authorNodeDefinition->children();
351
        $authorNodeBuilder->scalarNode('name')->cannotBeEmpty();
352
        $authorNodeBuilder->scalarNode('email')->cannotBeEmpty();
353
        $authorNodeBuilder->scalarNode('homepage')->cannotBeEmpty();
354
        $authorNodeBuilder->scalarNode('role')->cannotBeEmpty();
355
    }
356
}
357