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

UserRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findByLogin() 0 3 1
A findIdentity() 0 3 1
A findIdentityBy() 0 6 1
A save() 0 5 1
A findIdentityByToken() 0 3 1
A findAllOrderByLogin() 0 6 1
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
    /**
27
     * @psalm-return EntityReader<array-key, User>
28
     */
29
    public function findAllOrderByLogin(): EntityReader
30
    {
31
        /** @psalm-var EntityReader<array-key, User> */
32
        return (new EntityReader($this->select()))
33
            ->withSort(
34
                Sort::only(['login'])->withOrderString('login')
35
            );
36
    }
37
38
    public function findIdentity(string $id): ?IdentityInterface
39
    {
40
        return $this->findIdentityBy('id', $id);
41
    }
42
43
    public function findIdentityByToken(string $token, string $type = null): ?IdentityInterface
44
    {
45
        return $this->findIdentityBy('token', $token);
46
    }
47
48
    public function findByLogin(string $login): ?IdentityInterface
49
    {
50
        return $this->findIdentityBy('login', $login);
51
    }
52
53
    public function save(IdentityInterface $user): void
54
    {
55
        $transaction = new Transaction($this->orm);
56
        $transaction->persist($user);
57
        $transaction->run();
58
    }
59
60
    private function findIdentityBy(string $field, string $value): ?IdentityInterface
61
    {
62
        /**
63
         * @var $identity IdentityInterface|null
64
         */
65
        return $this->findOne([$field => $value]);
66
    }
67
}
68