RbacContainer::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Potievdev\SlimRbac\Component;
4
5
use Potievdev\SlimRbac\Component\Config\RbacConfig;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
9
10
/**
11
 * Class RbacContainer
12
 * @package Potievdev\SlimRbac\Component
13
 */
14
class RbacContainer
15
{
16
    /** @var  ContainerBuilder $containerBuilder */
17
    protected $containerBuilder;
18
19
    /**
20
     * RbacContainer constructor.
21
     */
22
    public function __construct(?RbacConfig $rbacConfig = null)
23
    {
24
        $this->containerBuilder = new ContainerBuilder();
25
26
        if (isset($rbacConfig)) {
27
            $this->containerBuilder->set('rbacConfig', $rbacConfig);
28
        }
29
30
        $loader = new YamlFileLoader($this->containerBuilder, new FileLocator(__DIR__));
31
        $loader->load('services.yaml');
32
    }
33
34
    public function getRbacMiddleware(): RbacMiddleware
35
    {
36
        return $this->containerBuilder->get('middleware');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->containerBuilder->get('middleware') could return the type null which is incompatible with the type-hinted return Potievdev\SlimRbac\Component\RbacMiddleware. Consider adding an additional type-check to rule them out.
Loading history...
37
    }
38
39
    public function getRbacManager(): RbacManager
40
    {
41
        return $this->containerBuilder->get('manager');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->containerBuilder->get('manager') could return the type null which is incompatible with the type-hinted return Potievdev\SlimRbac\Component\RbacManager. Consider adding an additional type-check to rule them out.
Loading history...
42
    }
43
44
    public function getInnerContainer(): ContainerBuilder
45
    {
46
        return $this->containerBuilder;
47
    }
48
}
49