Passed
Pull Request — master (#401)
by
unknown
05:03
created

BlockFixture::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\Fixture;
12
13
use BitBag\SyliusCmsPlugin\Fixture\Factory\FixtureFactoryInterface;
14
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
15
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
16
use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition;
17
use Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition;
18
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
19
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
20
21
final class BlockFixture extends AbstractFixture
22
{
23
    /** @var FixtureFactoryInterface */
24
    private $blockFixtureFactory;
25
26
    public function __construct(FixtureFactoryInterface $blockFixtureFactory)
27
    {
28
        $this->blockFixtureFactory = $blockFixtureFactory;
29
    }
30
31
    public function load(array $options): void
32
    {
33
        $this->blockFixtureFactory->load($options['custom']);
34
    }
35
36
    public function getName(): string
37
    {
38
        return 'block';
39
    }
40
41
    protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
42
    {
43
        $optionsNode
44
            ->children()
45
                ->arrayNode('custom')
46
                    ->arrayPrototype()
47
                        ->children()
48
                            ->booleanNode('remove_existing')->defaultTrue()->end()
49
                            ->integerNode('number')->defaultNull()->end()
0 ignored issues
show
Bug introduced by
The method integerNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
                            ->/** @scrutinizer ignore-call */ integerNode('number')->defaultNull()->end()
Loading history...
50
                            ->booleanNode('last_four_products')->defaultFalse()->end()
51
                            ->booleanNode('enabled')->defaultTrue()->end()
52
                            ->integerNode('products')->defaultNull()->end()
53
                            ->append($this->createArrayOfScalars('productCodes'))
54
                            ->append($this->createArrayOfScalars('taxons'))
55
                            ->append($this->createArrayOfScalars('sections'))
56
                            ->append($this->createArrayOfScalars('channels'))
57
                            ->append($this->translationsConfiguration())
58
                        ->end()
59
                    ->end()
60
                ->end()
61
            ->end()
62
        ;
63
    }
64
65
    private function createArrayOfScalars(string $name): NodeDefinition
66
    {
67
        $nodeDefinition = new ScalarNodeDefinition($name);
68
        $nodeDefinition->defaultNull()->end();
69
        return $nodeDefinition;
70
    }
71
72
    private function translationsConfiguration(): NodeDefinition
73
    {
74
        $translationsNodeDefinition = new ArrayNodeDefinition('translations');
75
        $translationsNodeDefinition
76
            ->arrayPrototype()
77
                ->children()
78
                    ->scalarNode('name')->end()
79
                    ->scalarNode('content')->end()
0 ignored issues
show
Bug introduced by
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
                    ->/** @scrutinizer ignore-call */ scalarNode('content')->end()
Loading history...
80
                    ->scalarNode('link')->end()
81
                    ->scalarNode('image_path')->end()
82
                ->end()
83
            ->end()
84
        ;
85
86
        return $translationsNodeDefinition;
87
    }
88
}
89