UserLinkedSources::getSource()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Canvas\Models;
5
6
class UserLinkedSources extends \Baka\Auth\Models\UserLinkedSources
0 ignored issues
show
Bug introduced by
The type Baka\Auth\Models\UserLinkedSources 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...
7
{
8
    /**
9
     *
10
     * @var integer
11
     */
12
    public $source_id;
13
14
    /**
15
     *
16
     * @var integer
17
     */
18
    public $users_id;
19
20
    /**
21
     *
22
     * @var string
23
     */
24
    public $source_users_id;
25
26
    /**
27
     *
28
     * @var string
29
     */
30
    public $source_users_id_text;
31
32
    /**
33
     *
34
     * @var string
35
     */
36
    public $source_username;
37
38
    /**
39
     *
40
     * @var integer
41
     */
42
    public $is_deleted;
43
44
    /**
45
     * Initialize method for model.
46
     */
47
    public function initialize()
48
    {
49
        parent::initialize();
50
51
        $this->setSource('user_linked_sources');
52
        $this->belongsTo('users_id', 'Canvas\Models\Users', 'id', ['alias' => 'user']);
53
    }
54
55
    /**
56
     * Returns table name mapped in the model.
57
     *
58
     * @return string
59
     */
60
    public function getSource(): string
61
    {
62
        return 'user_linked_sources';
63
    }
64
65
    /**
66
     * Get all user linked sources by user's id
67
     * @param int $usersId
68
     * @return array
69
     */
70
    public static function getMobileUserLinkedSources(int $usersId): array
71
    {
72
        $userDevicesArray = [
73
            2 => [],
74
            3 => []
75
        ];
76
77
        /**
78
         * @todo change this from ID's to use the actual definition of the android / ios apps
79
         */
80
        $linkedSource = UserLinkedSources::find([
81
            'conditions' => 'users_id = ?0 and source_id in (2,3)',
82
            'bind' => [$usersId]
83
        ]);
84
85
        if ($linkedSource) {
86
            //add to list of devices id
87
            foreach ($linkedSource as $device) {
88
                $userDevicesArray[$device->source_id][] = $device->source_users_id_text;
89
            }
90
        }
91
92
        return $userDevicesArray;
93
94
    }
95
}
96