|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Lakion\CmsPlugin\Fixture\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use Lakion\CmsPlugin\Document\StringBlock; |
|
6
|
|
|
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface; |
|
7
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
|
8
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
|
9
|
|
|
use Symfony\Component\OptionsResolver\Options; |
|
10
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
11
|
|
|
|
|
12
|
|
|
final class StringBlockExampleFactory implements ExampleFactoryInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var FactoryInterface |
|
16
|
|
|
*/ |
|
17
|
|
|
private $factory; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Faker\Generator |
|
21
|
|
|
*/ |
|
22
|
|
|
private $faker; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var OptionsResolver |
|
26
|
|
|
*/ |
|
27
|
|
|
private $optionsResolver; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param FactoryInterface $factory |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(FactoryInterface $factory) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->factory = $factory; |
|
35
|
|
|
|
|
36
|
|
|
$this->faker = \Faker\Factory::create(); |
|
37
|
|
|
$this->optionsResolver = |
|
38
|
|
|
(new OptionsResolver()) |
|
39
|
|
|
->setDefault('name', function (Options $options) { |
|
|
|
|
|
|
40
|
|
|
return StringInflector::nameToCode($this->faker->words(3, true)); |
|
|
|
|
|
|
41
|
|
|
}) |
|
42
|
|
|
->setAllowedTypes('name', 'string') |
|
43
|
|
|
|
|
44
|
|
|
->setDefault('body', function (Options $options) { |
|
|
|
|
|
|
45
|
|
|
return $this->faker->sentence(); |
|
46
|
|
|
}) |
|
47
|
|
|
->setAllowedTypes('body', 'string') |
|
48
|
|
|
; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
public function create(array $options = []) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$options = $this->optionsResolver->resolve($options); |
|
57
|
|
|
|
|
58
|
|
|
/** @var StringBlock $stringBlock */ |
|
59
|
|
|
$stringBlock = $this->factory->createNew(); |
|
60
|
|
|
$stringBlock->setName($options['name']); |
|
61
|
|
|
$stringBlock->setBody($options['body']); |
|
62
|
|
|
|
|
63
|
|
|
return $stringBlock; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.