Test Failed
Push — master ( fe954a...0e0ddf )
by Mike
02:18
created

UserQueryContainer::getUserFromEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.216

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 2
cts 5
cp 0.4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1.216
1
<?php
2
3
4
namespace Xervice\User;
5
6
7
use DataProvider\UserDataProvider;
8
use Orm\Xervice\User\Persistence\User;
0 ignored issues
show
Bug introduced by
The type Orm\Xervice\User\Persistence\User 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 Orm\Xervice\User\Persistence\UserQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Xervice\User\Persistence\UserQuery 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 Propel\Runtime\Map\TableMap;
11
use Xervice\Core\ServiceClass\XerviceInterface;
12
13
class UserQueryContainer implements XerviceInterface, UserQueryContainerInterface
14
{
15
    /**
16
     * @return \Orm\Xervice\User\Persistence\UserQuery
17
     */
18 3
    public function getUserQuery(): UserQuery
19
    {
20 3
        return UserQuery::create();
21
    }
22
23
    /**
24
     * @param int $userId
25
     *
26
     * @return UserDataProvider
27
     */
28
    public function getUserFromId(int $userId): UserDataProvider
29
    {
30
        $userQuery = $this->getUserQueryFromUserId($userId);
31
        $users = $userQuery->find();
0 ignored issues
show
Bug introduced by
The method find() does not exist on Xervice\User\UserQueryContainer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        /** @scrutinizer ignore-call */ 
32
        $users = $userQuery->find();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
        $user = $users[0] ?? null;
33
34
        return $this->getUserDataProviderFromEntity($user);
35
    }
36
37
    /**
38
     * @param string $email
39
     *
40
     * @return UserDataProvider
41
     */
42 3
    public function getUserFromEmail(string $email): UserDataProvider
43
    {
44 3
        $userQuery = $this->getUserQueryFromEmail($email);
45
        $users = $userQuery->find();
46
        $user = $users[0] ?? null;
47
48
        return $this->getUserDataProviderFromEntity($user);
49
    }
50
51
    /**
52
     * @param int $userId
53
     *
54
     * @return $this|\Propel\Runtime\ActiveQuery\ModelCriteria
55
     */
56
    public function getUserQueryFromUserId(int $userId)
57
    {
58
        return $this->getUserQuery()
59
                          ->filterByUserId($userId)
60
                          ->joinWith('User.UserLogin')
61
                          ->joinWith('UserLogin.UserCredential');
62
    }
63
64
    /**
65
     * @param string $email
66
     *
67
     * @return $this|\Propel\Runtime\ActiveQuery\ModelCriteria
68
     */
69 3
    public function getUserQueryFromEmail(string $email)
70
    {
71 3
        return $this->getUserQuery()
72
                          ->filterByEmail($email)
73
                          ->joinWith('User.UserLogin')
74
                          ->joinWith('UserLogin.UserCredential');
75
    }
76
77
    /**
78
     * @param \Orm\Xervice\User\Persistence\User $user
79
     *
80
     * @return \DataProvider\UserDataProvider
81
     */
82
    private function getUserDataProviderFromEntity(User $user = null): UserDataProvider
83
    {
84
        $userDataProvider = new UserDataProvider();
85
        if ($user) {
86
            $userDataProvider->fromArray(
87
                $user->toArray(
88
                    TableMap::TYPE_PHPNAME,
89
                    true,
90
                    [],
91
                    true
92
                )
93
            );
94
        }
95
96
        return $userDataProvider;
97
}
98
}