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

UserQueryContainer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 18.75%

Importance

Changes 0
Metric Value
wmc 7
eloc 26
dl 0
loc 84
ccs 6
cts 32
cp 0.1875
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserQueryFromUserId() 0 6 1
A getUserQuery() 0 3 1
A getUserFromId() 0 7 1
A getUserQueryFromEmail() 0 6 1
A getUserDataProviderFromEntity() 0 15 2
A getUserFromEmail() 0 7 1
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
}