Completed
Pull Request — master (#86)
by Loïc
02:03
created

ArticleExampleFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 6
dl 0
loc 55
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A configureOptions() 0 7 1
A create() 0 10 1
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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\Article;
15
use Sylius\Component\Resource\Factory\FactoryInterface;
16
use Symfony\Component\OptionsResolver\Options;
17
use Symfony\Component\OptionsResolver\OptionsResolver;
18
19
class ArticleExampleFactory extends AbstractExampleFactory
20
{
21
    /**
22
     * @var FactoryInterface
23
     */
24
    private $addressFactory;
25
26
    /**
27
     * @var \Faker\Generator
28
     */
29
    private $faker;
30
31
    /**
32
     * @var OptionsResolver
33
     */
34
    private $optionsResolver;
35
36
    /**
37
     * @param FactoryInterface $addressFactory
38
     */
39
    public function __construct(FactoryInterface $addressFactory)
40
    {
41
        $this->addressFactory = $addressFactory;
42
43
        $this->faker = \Faker\Factory::create();
44
        $this->optionsResolver = new OptionsResolver();
45
46
        $this->configureOptions($this->optionsResolver);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    protected function configureOptions(OptionsResolver $resolver)
53
    {
54
        $resolver
55
            ->setDefault('title', function (Options $options) {
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
                return ucfirst($this->faker->words(3, true));
57
            });
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function create(array $options = [])
64
    {
65
        $options = $this->optionsResolver->resolve($options);
66
67
        /** @var Article $article */
68
        $article = $this->addressFactory->createNew();
69
        $article->setTitle($options['title']);
70
71
        return $article;
72
    }
73
}
74