UnitOfWorkManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A save() 0 3 1
A fromQuery() 0 3 1
1
<?php
2
namespace vakata\orm;
3
4
use \vakata\database\DBInterface;
5
use \vakata\database\schema\TableQuery;
6
7
/**
8
 * Manager ORM class implementing Unit Of Work, so that all changes are persisted in a single transaction
9
 */
10
class UnitOfWorkManager extends Manager
11
{
12
    /**
13
     * @var UnitOfWork
14
     */
15
    protected $uow;
16
17
    /**
18
     * Create an instance
19
     *
20
     * @param DBInterface $db the database access object
21
     * @param UnitOfWork $uow the unit of work object
22
     */
23 1
    public function __construct(DBInterface $db, UnitOfWork $uow)
24
    {
25 1
        parent::__construct($db);
26 1
        $this->uow = $uow;
27 1
    }
28
    /**
29
     * Get a repository from a table query
30
     *
31
     * @param TableQuery $query
32
     * @return Repository
33
     */
34 1
    public function fromQuery(TableQuery $query) : Repository
35
    {
36 1
        return new UnitOfWorkRepository(parent::fromQuery($query), $this->uow);
37
    }
38
    /**
39
     * Save all the pending changes
40
     *
41
     * @return void
42
     */
43 1
    public function save()
44
    {
45 1
        $this->uow->save();
46 1
    }
47
}
48