Passed
Pull Request — master (#87)
by Dmitriy
03:13
created

PostRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 22
ccs 11
cts 11
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 5 1
A findAll() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Application\Blog\Entity\Post;
6
7
use Cycle\ORM\ORMInterface;
8
use Cycle\ORM\Select;
9
use Cycle\ORM\Transaction;
10
use Yiisoft\Yii\Cycle\Data\Reader\EntityReader;
11
12
final class PostRepository extends Select\Repository
13
{
14
    private ORMInterface $orm;
15
16 4
    public function __construct(Select $select, ORMInterface $orm)
17
    {
18 4
        $this->orm = $orm;
19 4
        parent::__construct($select);
20 4
    }
21
22 1
    public function findAll(array $scope = [], array $orderBy = []): EntityReader
23
    {
24 1
        return new EntityReader(
25 1
            $this->select()->where($scope)->orderBy($orderBy)
26
        );
27
    }
28
29 2
    public function save(Post $user): void
30
    {
31 2
        $transaction = new Transaction($this->orm);
32 2
        $transaction->persist($user);
33 2
        $transaction->run();
34 2
    }
35
}
36