LoginsTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 19
c 1
b 0
f 1
dl 0
loc 52
rs 10
ccs 0
cts 22
cp 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initRelations() 0 4 1
A getUserByProvider() 0 17 2
A createForProvider() 0 9 1
A initRelationsTrait() 0 3 1
1
<?php
2
3
namespace ByTIC\Hello\Models\Users\Logins\Traits;
4
5
use ByTIC\Hello\Models\Users\Logins\UsersLogin;
6
use ByTIC\Hello\Models\Users\Traits\UsersTrait;
7
use ByTIC\Hello\Models\Users\Traits\UserTrait;
8
use Nip\Records\Locator\ModelLocator;
9
use Nip\Records\RecordManager;
10
11
/**
12
 * Trait LoginsTrait
13
 * @package ByTIC\Hello\Models\Users\Logins\Traits
14
 *
15
 * @method LoginTrait|UsersLogin getNew
16
 */
17
trait LoginsTrait
18
{
19
    protected function initRelations()
20
    {
21
        parent::initRelations();
22
        $this->initRelationsTrait();
23
    }
24
25
    protected function initRelationsTrait()
26
    {
27
        $this->belongsTo('User');
0 ignored issues
show
Bug introduced by
It seems like belongsTo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

27
        $this->/** @scrutinizer ignore-call */ 
28
               belongsTo('User');
Loading history...
28
    }
29
30
    /**
31
     * @param $providerName
32
     * @param $user
33
     * @param $userProfile
34
     * @return LoginTrait
35
     */
36
    public function createForProvider($providerName, $user, $userProfile)
37
    {
38
        $userLogin = $this->getNew();
39
        $userLogin->populateFromUser($user);
40
        $userLogin->populateFromUserProfile($userProfile);
41
        $userLogin->provider_name = $providerName;
42
        $userLogin->insert();
0 ignored issues
show
Bug introduced by
It seems like insert() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

42
        $userLogin->/** @scrutinizer ignore-call */ 
43
                    insert();
Loading history...
43
44
        return $userLogin;
45
    }
46
47
    /**
48
     * @param $provider
49
     * @param $uid
50
     * @return bool|UserTrait
51
     */
52
    public function getUserByProvider($provider, $uid)
53
    {
54
        $params = [
55
            'where' => [
56
                ['provider_name = ?', $provider],
57
                ['provider_uid = ?', $uid]
58
            ]
59
        ];
60
61
        $item = $this->findOneByParams($params);
0 ignored issues
show
Bug introduced by
It seems like findOneByParams() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

61
        /** @scrutinizer ignore-call */ 
62
        $item = $this->findOneByParams($params);
Loading history...
62
63
        if ($item) {
64
            /** @var UsersTrait|RecordManager $userManager */
65
            $userManager = $this->getRelation('User')->getWith();
0 ignored issues
show
Bug introduced by
It seems like getRelation() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

65
            $userManager = $this->/** @scrutinizer ignore-call */ getRelation('User')->getWith();
Loading history...
66
            return $userManager->findOne($item->id_user);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $userManager->findOne($item->id_user) returns the type Nip\Records\AbstractModels\Record which is incompatible with the documented return type ByTIC\Hello\Models\Users\Traits\UserTrait|boolean.
Loading history...
Bug introduced by
The method findOne() does not exist on ByTIC\Hello\Models\Users\Traits\UsersTrait. Did you maybe mean findOneByEmail()? ( Ignorable by Annotation )

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

66
            return $userManager->/** @scrutinizer ignore-call */ findOne($item->id_user);

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...
67
        }
68
        return false;
69
    }
70
}
71