Completed
Push — master ( ead026...e06fe9 )
by Michał
302:23 queued 302:00
created

CoreBundle/Fixture/StickerProductFixture.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\CoreBundle\Fixture;
13
14
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
15
use Sylius\Component\Attribute\AttributeType\TextAttributeType;
16
use Sylius\Component\Resource\Repository\RepositoryInterface;
17
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
/**
21
 * @author Kamil Kokot <[email protected]>
22
 */
23
final class StickerProductFixture extends AbstractFixture
24
{
25
    /**
26
     * @var TaxonFixture
27
     */
28
    private $taxonFixture;
29
30
    /**
31
     * @var RepositoryInterface
32
     */
33
    private $taxonRepository;
34
35
    /**
36
     * @var ProductAttributeFixture
37
     */
38
    private $productAttributeFixture;
39
40
    /**
41
     * @var ProductOptionFixture
42
     */
43
    private $productOptionFixture;
44
45
    /**
46
     * @var ProductArchetypeFixture
47
     */
48
    private $productArchetypeFixture;
49
50
    /**
51
     * @var ProductFixture
52
     */
53
    private $productFixture;
54
55
    /**
56
     * @var \Faker\Generator
57
     */
58
    private $faker;
59
60
    /**
61
     * @var OptionsResolver
62
     */
63
    private $optionsResolver;
64
65
    /**
66
     * @param TaxonFixture $taxonFixture
67
     * @param RepositoryInterface $taxonRepository
68
     * @param ProductAttributeFixture $productAttributeFixture
69
     * @param ProductOptionFixture $productOptionFixture
70
     * @param ProductArchetypeFixture $productArchetypeFixture
71
     * @param ProductFixture $productFixture
72
     */
73
    public function __construct(
74
        TaxonFixture $taxonFixture,
75
        RepositoryInterface $taxonRepository,
76
        ProductAttributeFixture $productAttributeFixture,
77
        ProductOptionFixture $productOptionFixture,
78
        ProductArchetypeFixture $productArchetypeFixture,
79
        ProductFixture $productFixture
80
    ) {
81
        $this->taxonFixture = $taxonFixture;
82
        $this->taxonRepository = $taxonRepository;
83
        $this->productAttributeFixture = $productAttributeFixture;
84
        $this->productOptionFixture = $productOptionFixture;
85
        $this->productArchetypeFixture = $productArchetypeFixture;
86
        $this->productFixture = $productFixture;
87
88
        $this->faker = \Faker\Factory::create();
89
        $this->optionsResolver =
90
            (new OptionsResolver())
91
                ->setRequired('amount')
92
                ->setAllowedTypes('amount', 'int')
93
        ;
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    public function getName()
100
    {
101
        return 'sticker_product';
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function load(array $options)
108
    {
109
        $options = $this->optionsResolver->resolve($options);
110
111
        $this->taxonFixture->load(['custom' => [[
112
            'code' => 'category',
113
            'name' => 'Category',
114
            'children' => [
115
                [
116
                    'code' => 'stickers',
117
                    'name' => 'Stickers',
118
                ]
119
            ]
120
        ]]]);
121
122
        $this->productAttributeFixture->load(['custom' => [
123
            ['name' => 'Sticker paper', 'code' => 'STICKER-PAPER', 'type' => TextAttributeType::TYPE],
124
            ['name' => 'Sticker resolution', 'code' => 'STICKER-RESOLUTION', 'type' => TextAttributeType::TYPE],
125
        ]]);
126
127
        $this->productOptionFixture->load(['custom' => [
128
            [
129
                'name' => 'Sticker SIZE',
130
                'code' => 'STICKER-SIZE',
131
                'values' => [
132
                    'STICKER-SIZE-3' => '3"',
133
                    'STICKER-SIZE-5' => '5"',
134
                    'STICKER-SIZE-7' => '7"',
135
                ],
136
            ],
137
        ]]);
138
139
        $this->productArchetypeFixture->load(['custom' => [
140
            [
141
                'name' => 'Sticker',
142
                'code' => 'STICKER',
143
                'product_attributes' => ['STICKER-PAPER', 'STICKER-RESOLUTION'],
144
                'product_options' => ['STICKER-SIZE'],
145
            ],
146
        ]]);
147
148
        $products = [];
149
        for ($i = 0; $i < $options['amount']; ++$i) {
150
            $products[] = [
151
                'name' => sprintf('Sticker "%s"', $this->faker->word),
152
                'code' => $this->faker->uuid,
153
                'main_taxon' => 'stickers',
154
                'product_archetype' => 'STICKER',
155
                'taxons' => ['stickers'],
156
                'product_attributes' => [
157
                    'STICKER-PAPER' => sprintf('Paper from tree %s', $this->faker->randomElement(['Wung', 'Tanajno', 'Lemon-San', 'Me-Gusta'])),
0 ignored issues
show
The call to randomElement() misses some required arguments starting with $'b'.
Loading history...
158
                    'STICKER-RESOLUTION' => $this->faker->randomElement(['JKM XD', '476DPI', 'FULL HD', '200DPI']),
0 ignored issues
show
The call to randomElement() misses some required arguments starting with $'b'.
Loading history...
159
                ],
160
                'images' => [sprintf('%s/../Resources/fixtures/%s', __DIR__, 'stickers.jpg')],
161
            ];
162
        }
163
164
        $this->productFixture->load(['custom' => $products]);
165
    }
166
167
    /**
168
     * {@inheritdoc}
169
     */
170
    protected function configureOptionsNode(ArrayNodeDefinition $optionsNode)
171
    {
172
        $optionsNode
173
            ->children()
174
                ->integerNode('amount')->isRequired()->min(0)->end()
175
        ;
176
    }
177
}
178