Passed
Push — master ( c39fb6...9e9a0d )
by Rafael
04:42
created

DefinitionExtensionManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 3
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 3
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Definition\Extension;
12
13
use Ynlo\GraphQLBundle\Component\TaggedServices\TaggedServices;
14
use Ynlo\GraphQLBundle\Component\TaggedServices\TagSpecification;
15
16
/**
17
 * ExtensionManager
18
 */
19 View Code Duplication
class DefinitionExtensionManager
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    /**
22
     * @var DefinitionExtensionInterface[]
23
     */
24
    protected $extensions;
25
26
    /**
27
     * @var bool
28
     */
29
    protected $loaded = false;
30
31
    /**
32
     * @var TaggedServices
33
     */
34
    protected $taggedServices;
35
36
    /**
37
     * ExtensionManager constructor.
38
     *
39
     * @param TaggedServices $taggedServices
40
     */
41 21
    public function __construct(TaggedServices $taggedServices)
42
    {
43 21
        $this->taggedServices = $taggedServices;
44 21
    }
45
46
    /**
47
     * @return array|DefinitionExtensionInterface[]
48
     */
49 1
    public function getExtensions()
50
    {
51 1
        if ($this->loaded) {
52
            return $this->extensions;
53
54
        }
55 1
        $this->extensions = [];
56
57
        /** @var TagSpecification $extensions */
58 1
        $taggedServices = $this->taggedServices->findTaggedServices('graphql.definition_extension');
59 1
        foreach ($taggedServices as $tagSpecification) {
60
            /** @var DefinitionExtensionInterface $extension */
61 1
            $extension = $tagSpecification->getService();
62 1
            $this->extensions[$extension->getName()] = $extension;
63
        }
64
65 1
        $this->loaded = true;
66
67 1
        return $this->extensions;
68
    }
69
}
70