Passed
Pull Request — master (#572)
by Dmitriy
01:33
created

UserRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Application\User\Entity;
6
7
use Cycle\ORM\ORMInterface;
0 ignored issues
show
Bug introduced by
The type Cycle\ORM\ORMInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Cycle\ORM\Select;
0 ignored issues
show
Bug introduced by
The type Cycle\ORM\Select was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Cycle\ORM\Transaction;
0 ignored issues
show
Bug introduced by
The type Cycle\ORM\Transaction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Yiisoft\Auth\IdentityInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Auth\IdentityInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Yiisoft\Auth\IdentityRepositoryInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Auth\IdentityRepositoryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Yiisoft\Auth\IdentityWithTokenRepositoryInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Auth\IdentityWithTokenRepositoryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Yiisoft\Data\Reader\Sort;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Data\Reader\Sort was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Yiisoft\Yii\Cycle\Data\Reader\EntityReader;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Cycle\Data\Reader\EntityReader was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
final class UserRepository extends Select\Repository implements IdentityWithTokenRepositoryInterface, IdentityRepositoryInterface
0 ignored issues
show
Bug introduced by
The type Cycle\ORM\Select\Repository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
{
18
    private ORMInterface $orm;
19
20
    public function __construct(Select $select, ORMInterface $orm)
21
    {
22
        $this->orm = $orm;
23
        parent::__construct($select);
24
    }
25
26
    public function findAllOrderByLogin(): EntityReader
27
    {
28
        return (new EntityReader($this->select()))
29
            ->withSort(
30
                Sort::only(['login'])->withOrderString('login')
31
            );
32
    }
33
34
    public function findIdentity(string $id): ?IdentityInterface
35
    {
36
        return $this->findIdentityBy('id', $id);
37
    }
38
39
    public function findIdentityByToken(string $token, string $type = null): ?IdentityInterface
40
    {
41
        return $this->findIdentityBy('token', $token);
42
    }
43
44
    public function findByLogin(string $login): ?IdentityInterface
45
    {
46
        return $this->findIdentityBy('login', $login);
47
    }
48
49
    public function save(IdentityInterface $user): void
50
    {
51
        $transaction = new Transaction($this->orm);
52
        $transaction->persist($user);
53
        $transaction->run();
54
    }
55
56
    private function findIdentityBy(string $field, string $value): ?IdentityInterface
57
    {
58
        /**
59
         * @var $identity IdentityInterface|null
60
         */
61
        return $this->findOne([$field => $value]);
62
    }
63
}
64