Passed
Push — master ( a30cf1...9051a7 )
by Gabriel
14:38
created

HasFactoryTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFactory() 0 7 2
A setFactory() 0 3 1
A factory() 0 3 1
1
<?php
2
3
namespace ByTIC\Payments\Gateways\Manager\Traits;
4
5
use ByTIC\Payments\Gateways\GatewayFactory;
6
7
/**
8
 * Trait HasFactoryTrait
9
 * @package ByTIC\Payments\Gateways\Manager\Traits
10
 */
11
trait HasFactoryTrait
12
{
13
    /**
14
     * Internal factory storage
15
     *
16
     * @var GatewayFactory
17
     */
18
    protected $factory;
19
20
    /**
21
     * Get the gateway factory
22
     *
23
     * Creates a new empty GatewayFactory if none has been set previously.
24
     *
25
     * @return GatewayFactory A GatewayFactory instance
26
     */
27
    public static function factory(): GatewayFactory
28
    {
29
        return static::instance()->getFactory();
30
    }
31
32
    /**
33
     * Get the gateway factory
34
     *
35
     * Creates a new empty GatewayFactory if none has been set previously.
36
     *
37
     * @return GatewayFactory A GatewayFactory instance
38
     */
39
    public function getFactory(): GatewayFactory
40
    {
41
        if (is_null($this->factory)) {
42
            $this->setFactory(new GatewayFactory);
43
        }
44
45
        return $this->factory;
46
    }
47
48
    /**
49
     * @param GatewayFactory $factory
50
     */
51
    public function setFactory(GatewayFactory $factory): void
52
    {
53
        $this->factory = $factory;
54
    }
55
}
56