Completed
Push — locale-in-url ( 6d9eda...81052c )
by Kamil
57:16 queued 38:25
created

ApiClientExampleFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A create() 0 14 1
A configureOptions() 0 13 1
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\ApiBundle\Fixture\Factory;
13
14
use FOS\OAuthServerBundle\Model\ClientManagerInterface;
15
use Sylius\Bundle\ApiBundle\Model\ClientInterface;
16
use Sylius\Bundle\CoreBundle\Fixture\Factory\AbstractExampleFactory;
17
use Symfony\Component\OptionsResolver\Options;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
/**
21
 * @author Łukasz Chruściel <[email protected]>
22
 */
23
class ApiClientExampleFactory extends AbstractExampleFactory
24
{
25
    /**
26
     * @var ClientManagerInterface
27
     */
28
    private $clientManager;
29
30
    /**
31
     * @var \Faker\Generator
32
     */
33
    private $faker;
34
35
    /**
36
     * @var OptionsResolver
37
     */
38
    private $optionsResolver;
39
40
    /**
41
     * @param ClientManagerInterface $clientManager
42
     */
43
    public function __construct(ClientManagerInterface $clientManager)
44
    {
45
        $this->clientManager = $clientManager;
46
47
        $this->faker = \Faker\Factory::create();
48
        $this->optionsResolver = new OptionsResolver();
49
50
        $this->configureOptions($this->optionsResolver);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function create(array $options = [])
57
    {
58
        $options = $this->optionsResolver->resolve($options);
59
60
        /** @var ClientInterface $client */
61
        $client = $this->clientManager->createClient();
62
63
        $client->setRandomId($options['random_id']);
64
        $client->setSecret($options['secret']);
65
66
        $client->setAllowedGrantTypes($options['allowed_grant_types']);
67
68
        return $client;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    protected function configureOptions(OptionsResolver $resolver)
75
    {
76
        $resolver
77
            ->setDefault('random_id', 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...
78
                return $this->faker->unique()->randomNumber(8);
79
            })
80
            ->setDefault('secret', 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...
81
                return $this->faker->uuid;
82
            })
83
            ->setDefault('allowed_grant_types', [])
84
            ->setAllowedTypes('allowed_grant_types', ['array'])
85
        ;
86
    }
87
}
88