Completed
Push — master ( cbfed7...c39fb6 )
by Rafael
05:06
created

AbstractResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 65
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createFormBuilder() 0 3 1
A getValidator() 0 3 1
A setContext() 0 3 1
A get() 0 3 1
A getContext() 0 3 1
A getManager() 0 3 1
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Resolver;
12
13
use Doctrine\ORM\EntityManager;
14
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
16
use Symfony\Component\Form\FormBuilderInterface;
17
use Symfony\Component\Validator\Validator\ValidatorInterface;
18
19
/**
20
 * AbstractResolver is a simple implementation of a Resolver.
21
 *
22
 * It provides methods to common features needed in resolvers.
23
 */
24
abstract class AbstractResolver implements ContainerAwareInterface
25
{
26
    use ContainerAwareTrait;
27
28
    /**
29
     * @var ResolverContext
30
     */
31
    protected $context;
32
33
    /**
34
     * @return ResolverContext
35
     */
36 5
    public function getContext(): ResolverContext
37
    {
38 5
        return $this->context;
39
    }
40
41
    /**
42
     * @param ResolverContext $context
43
     */
44 14
    public function setContext(ResolverContext $context)
45
    {
46 14
        $this->context = $context;
47 14
    }
48
49
    /**
50
     * Gets a container service by its id.
51
     *
52
     * @param string $id The service id
53
     *
54
     * @return mixed The service
55
     */
56 14
    protected function get($id)
57
    {
58 14
        return $this->container->get($id);
59
    }
60
61
    /**
62
     * @return EntityManager
63
     */
64 14
    protected function getManager(): EntityManager
65
    {
66 14
        return $this->get('doctrine')->getManager();
67
    }
68
69
    /**
70
     * @return ValidatorInterface
71
     */
72 2
    protected function getValidator(): ValidatorInterface
73
    {
74 2
        return $this->get('validator');
75
    }
76
77
    /**
78
     * Creates and returns a Form Builder instance from the type of the form.
79
     *
80
     * @param string $type    The fully qualified class name of the form type
81
     * @param mixed  $data    The initial data for the form
82
     * @param array  $options Options for the form
83
     *
84
     * @return FormBuilderInterface
85
     */
86 7
    protected function createFormBuilder($type, $data = null, array $options = [])
87
    {
88 7
        return $this->container->get('form.factory')->createBuilder($type, $data, $options);
89
    }
90
}
91