Configuration   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 69
c 3
b 1
f 0
dl 0
loc 79
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 77 2
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\SyliusWishlistPlugin\DependencyInjection;
12
13
use BitBag\SyliusWishlistPlugin\Entity\Wishlist;
14
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
15
use BitBag\SyliusWishlistPlugin\Entity\WishlistProduct;
16
use BitBag\SyliusWishlistPlugin\Entity\WishlistProductInterface;
17
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepository;
18
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
19
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
20
use Sylius\Component\Resource\Factory\Factory;
21
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
22
use Symfony\Component\Config\Definition\ConfigurationInterface;
23
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
24
25
final class Configuration implements ConfigurationInterface
26
{
27
    public function getConfigTreeBuilder(): TreeBuilder
28
    {
29
        $treeBuilder = new TreeBuilder('bitbag_sylius_wishlist_plugin');
30
        $rootNode = $treeBuilder->getRootNode();
31
        /** @phpstan-ignore-next-line  */
32
        $rootNode
33
            ->children()
34
                ->scalarNode('wishlist_cookie_token')
35
                    ->defaultValue('wishlist_cookie_token')
36
                    ->cannotBeEmpty()
37
                    ->validate()
38
                        ->always(function ($value) {
39
                            if (!is_string($value)) {
40
                                throw new InvalidConfigurationException('wishlist_cookie_token must be string');
41
                            }
42
43
                            return $value;
44
                        })
45
                    ->end()
46
                ->end()
47
                ->arrayNode('allowed_mime_types')
48
                    ->defaultValue([
49
                        'text/csv',
50
                        'text/plain',
51
                        'application/csv',
52
                        'text/comma-separated-values',
53
                        'application/excel',
54
                        'application/vnd.ms-excel',
55
                        'application/vnd.msexcel',
56
                        'text/anytext',
57
                        'application/octet-stream',
58
                        'application/txt',
59
                    ])
60
                    ->requiresAtLeastOneElement()
61
                    ->scalarPrototype()->end()
62
                ->end()
63
                ->arrayNode('resources')
64
                    ->addDefaultsIfNotSet()
65
                    ->children()
66
                        ->arrayNode('wishlist')
67
                            ->addDefaultsIfNotSet()
68
                            ->children()
69
                                ->variableNode('options')->end()
70
                                ->arrayNode('classes')
71
                                    ->addDefaultsIfNotSet()
72
                                    ->children()
73
                                        ->scalarNode('model')->defaultValue(Wishlist::class)->cannotBeEmpty()->end()
74
                                        ->scalarNode('interface')->defaultValue(WishlistInterface::class)->cannotBeEmpty()->end()
75
                                        ->scalarNode('repository')->defaultValue(WishlistRepository::class)->cannotBeEmpty()->end()
76
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
77
                                        ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
78
                                    ->end()
79
                                ->end()
80
                            ->end()
81
                        ->end()
82
                        ->arrayNode('wishlist_product')
83
                            ->addDefaultsIfNotSet()
84
                            ->children()
85
                                ->variableNode('options')->end()
86
                                ->arrayNode('classes')
87
                                    ->addDefaultsIfNotSet()
88
                                    ->children()
89
                                        ->scalarNode('model')->defaultValue(WishlistProduct::class)->cannotBeEmpty()->end()
90
                                        ->scalarNode('interface')->defaultValue(WishlistProductInterface::class)->cannotBeEmpty()->end()
91
                                        ->scalarNode('repository')->defaultValue(EntityRepository::class)->cannotBeEmpty()->end()
92
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
93
                                        ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
94
                                    ->end()
95
                                ->end()
96
                            ->end()
97
                        ->end()
98
                    ->end()
99
                ->end()
100
            ->end()
101
        ;
102
103
        return $treeBuilder;
104
    }
105
}
106