Completed
Push — location_references ( 47d67d )
by
unknown
13:55
created

LocationReferenceConfigParser::mapConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser;
6
7
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\AbstractParser;
8
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
9
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
10
11
/**
12
 * Configuration parser for Location References.
13
 *
14
 * Example configuration:
15
 *
16
 * ```yaml
17
 * ezpublish:
18
 *   system:
19
 *      default: # configuration per siteaccess or siteaccess group
20
 *          location_references:
21
 *              media: remote_id("babe4a915b1dd5d369e79adb9d6c0c6a")
22
 *              # ...
23
 * ```
24
 */
25
final class LocationReferenceConfigParser extends AbstractParser
26
{
27
    private const ROOT_NODE_KEY = 'location_references';
28
29
    public function addSemanticConfig(NodeBuilder $nodeBuilder): void
30
    {
31
        $nodeBuilder
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...
32
            ->arrayNode(self::ROOT_NODE_KEY)
33
                ->useAttributeAsKey('name')
34
                ->scalarPrototype()
35
            ->end();
36
    }
37
38
    public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void
39
    {
40
        $contextualizer->setContextualParameter(
41
            'location_references',
42
            $currentScope,
43
            $scopeSettings['location_references'] ?? []
44
        );
45
    }
46
47
    public function postMap(array $config, ContextualizerInterface $contextualizer): void
48
    {
49
        $contextualizer->mapConfigArray('location_references', $config);
50
    }
51
}
52