Passed
Push — master ( 456cc4...4a5fe5 )
by Hector Luis
22:19
created

ServiceLocator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 27
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 3 1
A get() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Service Locator Class
6
 * @category    Ticaje
7
 * @package     Ticaje_Base
8
 * @author      Hector Luis Barrientos <[email protected]>
9
 */
10
11
namespace Ticaje\Base\Application\Service;
12
13
use Magento\Framework\ObjectManagerInterface as MagentoObjectManagerInterface;
14
15
/**
16
 * Class ServiceLocator
17
 * @package Ticaje\Base\Application\Service
18
 * This class kind of performs gateway pattern design in order to provide consistency to our Model Domain
19
 * According to DI principle it complies to separate the Model Domain from the current framework.
20
 * We're gonna play Magento rules since this is a Gateway, so our Domain does not get touched by Magento's
21
 */
22
class ServiceLocator implements ServiceLocatorInterface
23
{
24
    protected $objectManager;
25
26
    /**
27
     * ServiceLocator constructor.
28
     * @param MagentoObjectManagerInterface $objectManager
29
     * Using composition over inheritance of course
30
     */
31
    public function __construct(
32
        MagentoObjectManagerInterface $objectManager
33
    ) {
34
        $this->objectManager = $objectManager;
35
    }
36
37
    /**
38
     * @param $class
39
     * @return mixed
40
     */
41
    public function get($class)
42
    {
43
        return $this->objectManager->get($class);
44
    }
45
46
    public function create($class, array $arguments = [])
47
    {
48
        return $this->objectManager->create($class, $arguments);
49
    }
50
}
51