Passed
Push — main ( 3f5d4e...df4575 )
by James Ekow Abaka
01:53
created

DatabaseItemFactory::getEncapsulatedStack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
namespace yentu\factories;
3
4
use yentu\database\DatabaseItem;
5
use yentu\database\ItemType;
6
use yentu\database\EncapsulatedStack;
7
use yentu\ChangeLogger;
8
9
10
class DatabaseItemFactory
11
{
12
    private string $home;
13
    private EncapsulatedStack $stack;
14
    private ChangeLogger $driver;
15
    
16
    public function __construct(EncapsulatedStack $stack, array $arguments)
17
    {
18
        $this->home = $arguments['home'] ?? './yentu';
19
        $this->stack = $stack;
20
    }
21
    
22
    public function setDriver(ChangeLogger $driver): void
23
    {
24
        $this->driver = $driver;
25
    }
26
    
27
    public function create(ItemType $itemType, mixed ... $args): DatabaseItem
28
    {
29
        $class = new \ReflectionClass($itemType->value);
30
        $item = $class->newInstanceArgs($args);
31
        $item->setDriver($this->driver);    
32
        $item->init();              
33
        $item->setFactory($this);
34
        $item->setStack($this->stack);
35
        $item->setHome($this->home);
36
        $this->stack->push($item);          
37
        return $item;
38
    }   
39
    
40
    public function getEncapsulatedStack(): EncapsulatedStack
41
    {
42
        return $this->stack;
43
    }
44
}
45