Completed
Push — master ( e7429e...db9c88 )
by Julito
11:10
created

ResourceFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRepository() 0 17 3
A __construct() 0 3 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Repository;
6
7
use Chamilo\CoreBundle\ToolChain;
8
use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
9
10
class ResourceFactory
11
{
12
    protected $mountManager;
13
    protected $toolChain;
14
    protected $slugify;
15
    protected $entityManager;
16
    protected $authorizationChecker;
17
18
    public function __construct(ToolChain $toolChain)
19
    {
20
        $this->toolChain = $toolChain;
21
    }
22
23
    public function getRepository(string $tool, string $type)
24
    {
25
        $tool = $this->toolChain->getToolFromName($tool);
26
27
        $resourceTypeList = $tool->getResourceTypes();
28
        if (!isset($resourceTypeList[$type])) {
29
            throw new InvalidArgumentException("Resource type doesn't exist: $type");
30
        }
31
32
        $typeConfig = $resourceTypeList[$type];
33
        $repo = $typeConfig['repository'];
34
35
        if (false === class_exists($repo)) {
36
            throw new InvalidArgumentException("Check that this classes exists: $repo");
37
        }
38
39
        return $repo;
40
    }
41
}
42