Test Failed
Push — master ( c6b6d3...528954 )
by Dan Michael O.
03:21
created

UserIdentifiers::__get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Scriptotek\Alma\Users;
4
5
use Scriptotek\Alma\Model;
6
7
class UserIdentifiers extends Model
8
{
9
    /**
10
     * Get a flat array of all the user IDs.
11
     *
12
     * @param string $status (Default: 'ACTIVE').
13
     * @return string[]
14
     */
15 View Code Duplication
    public function all($status='ACTIVE')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17
        $ids = [$this->data->primary_id];
18
        foreach ($this->data->user_identifier as $identifier) {
19
            if (is_null($status) || $identifier->status == $status) {
20
                $ids[] = $identifier->value;
21
            }
22
        }
23
24
        return $ids;
25
    }
26
27
    /**
28
     * Get all active user identifiers of a given type, like 'BARCODE' or 'UNIV_ID'.
29
     *
30
     * @param string $value
31
     * @param string $status
32
     * @return array
33
     */
34 View Code Duplication
    public function allOfType($value, $status = 'ACTIVE')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        $ids = [];
37
        foreach ($this->data->user_identifier as $identifier) {
38
            if ($identifier->id_type->value == $value && (is_null($status) || $identifier->status == $status)) {
39
                $ids[] = $identifier->value;
40
            }
41
        }
42
        return $ids;
43
    }
44
45
    /**
46
     * Get the first active user identifier of a given type, like 'BARCODE' or 'UNIV_ID'.
47
     *
48
     * @param string $value
49
     * @param string $status
50
     * @return null|string
51
     */
52
    public function firstOfType($value, $status = 'ACTIVE')
53
    {
54
        foreach ($this->data->user_identifier as $identifier) {
55
            if ($identifier->id_type->value == $value && (is_null($status) || $identifier->status == $status)) {
56
                return $identifier->value;
57
            }
58
        }
59
    }
60
61
    /**
62
     * Get the first active barcode.
63
     *
64
     * @return null|string
65
     */
66
    public function getBarcode()
67
    {
68
        return $this->firstOfType('BARCODE');
69
    }
70
71
    /**
72
     * Get all active barcodes.
73
     *
74
     * @return string[]
75
     */
76
    public function getBarcodes()
77
    {
78
        return $this->allOfType('BARCODE');
79
    }
80
81
    /**
82
     * Get the first active university id.
83
     *
84
     * @return null|string
85
     */
86
    public function getUniversityId()
87
    {
88
        return $this->firstOfType('UNIV_ID');
89
    }
90
91
    /**
92
     * Get all active university ids.
93
     *
94
     * @return string[]
95
     */
96
    public function getUniversityIds()
97
    {
98
        return $this->allOfType('UNIV_ID');
99
    }
100
}
101