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 Jedisjeux. |
||
5 | * |
||
6 | * (c) Loïc Frémont |
||
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 App\Fixture\Factory; |
||
13 | |||
14 | use App\Entity\ProductFile; |
||
15 | use App\Fixture\OptionsResolver\LazyOption; |
||
16 | use Sylius\Component\Customer\Model\CustomerInterface; |
||
17 | use Sylius\Component\Product\Model\ProductInterface; |
||
18 | use Sylius\Component\Resource\Factory\FactoryInterface; |
||
19 | use Sylius\Component\Resource\Repository\RepositoryInterface; |
||
20 | use Symfony\Component\OptionsResolver\Options; |
||
21 | use Symfony\Component\OptionsResolver\OptionsResolver; |
||
22 | |||
23 | class ProductFileExampleFixture extends AbstractExampleFactory |
||
24 | { |
||
25 | /** |
||
26 | * @var FactoryInterface |
||
27 | */ |
||
28 | private $productFileFactory; |
||
29 | |||
30 | /** |
||
31 | * @var RepositoryInterface |
||
32 | */ |
||
33 | private $productRepository; |
||
34 | |||
35 | /** |
||
36 | * @var RepositoryInterface |
||
37 | */ |
||
38 | private $customerRepository; |
||
39 | |||
40 | /** |
||
41 | * @var \Faker\Generator |
||
42 | */ |
||
43 | private $faker; |
||
44 | |||
45 | /** |
||
46 | * @var OptionsResolver |
||
47 | */ |
||
48 | private $optionsResolver; |
||
49 | |||
50 | /** |
||
51 | * @param FactoryInterface $productFileFactory |
||
52 | * @param RepositoryInterface $productRepository |
||
53 | * @param RepositoryInterface $customerRepository |
||
54 | */ |
||
55 | public function __construct( |
||
56 | FactoryInterface $productFileFactory, |
||
57 | RepositoryInterface $productRepository, |
||
58 | RepositoryInterface $customerRepository |
||
59 | ) { |
||
60 | $this->productFileFactory = $productFileFactory; |
||
61 | $this->productRepository = $productRepository; |
||
62 | $this->customerRepository = $customerRepository; |
||
63 | |||
64 | $this->faker = \Faker\Factory::create(); |
||
65 | $this->optionsResolver = new OptionsResolver(); |
||
66 | |||
67 | $this->configureOptions($this->optionsResolver); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | protected function configureOptions(OptionsResolver $resolver) |
||
74 | { |
||
75 | $resolver |
||
76 | ->setDefault('title', function (Options $options) { |
||
0 ignored issues
–
show
|
|||
77 | return ucfirst($this->faker->unique()->words(3, true)); |
||
78 | }) |
||
79 | |||
80 | ->setDefault('path', function (Options $options) { |
||
0 ignored issues
–
show
|
|||
81 | return sprintf('%s.%s', $this->faker->word, $this->faker->fileExtension); |
||
82 | }) |
||
83 | |||
84 | ->setDefault('status', function (Options $options) { |
||
0 ignored issues
–
show
|
|||
85 | return $this->faker->randomElement([ |
||
86 | ProductFile::STATUS_NEW, |
||
87 | ProductFile::STATUS_ACCEPTED, |
||
88 | ProductFile::STATUS_REJECTED, |
||
89 | ]); |
||
90 | }) |
||
91 | |||
92 | ->setDefault('product', LazyOption::randomOne($this->productRepository)) |
||
93 | ->setAllowedTypes('product', ['null', 'string', ProductInterface::class]) |
||
94 | ->setNormalizer('product', LazyOption::findOneBy($this->productRepository, 'code')) |
||
95 | |||
96 | ->setDefault('author', LazyOption::randomOne($this->customerRepository)) |
||
97 | ->setAllowedTypes('author', ['null', 'string', CustomerInterface::class]) |
||
98 | ->setNormalizer('author', LazyOption::findOneBy($this->customerRepository, 'email')) |
||
99 | ; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public function create(array $options = []) |
||
106 | { |
||
107 | $options = $this->optionsResolver->resolve($options); |
||
108 | |||
109 | /** @var ProductFile $productFile */ |
||
110 | $productFile = $this->productFileFactory->createNew(); |
||
111 | $productFile->setTitle($options['title']); |
||
112 | $productFile->setPath($options['path']); |
||
113 | $productFile->setProduct($options['product']); |
||
114 | $productFile->setAuthor($options['author']); |
||
115 | $productFile->setStatus($options['status']); |
||
116 | |||
117 | return $productFile; |
||
118 | } |
||
119 | } |
||
120 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.