UserIdentifiers   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 98
Duplicated Lines 21.43 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 21
loc 98
rs 10
c 0
b 0
f 0
wmc 18
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 11 11 4
A allOfType() 10 11 5
A firstOfType() 0 8 5
A getBarcode() 0 4 1
A getBarcodes() 0 4 1
A getUniversityId() 0 4 1
A getUniversityIds() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Scriptotek\Alma\Users;
4
5
use Scriptotek\Alma\Model\Model;
6
7
/**
8
 * Collection of identifiers belonging to some User.
9
 */
10
class UserIdentifiers extends Model
11
{
12
    /**
13
     * Get a flat array of all the user IDs.
14
     *
15
     * @param string $status (Default: 'ACTIVE').
16
     *
17
     * @return string[]
18
     */
19 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...
20
    {
21
        $ids = [$this->data->primary_id];
22
        foreach ($this->data->user_identifier as $identifier) {
23
            if (is_null($status) || $identifier->status == $status) {
24
                $ids[] = $identifier->value;
25
            }
26
        }
27
28
        return $ids;
29
    }
30
31
    /**
32
     * Get all active user identifiers of a given type, like 'BARCODE' or 'UNIV_ID'.
33
     *
34
     * @param string $value
35
     * @param string $status
36
     *
37
     * @return array
38
     */
39 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...
40
    {
41
        $ids = [];
42
        foreach ($this->data->user_identifier as $identifier) {
43
            if ($identifier->id_type->value == $value && (is_null($status) || $identifier->status == $status)) {
44
                $ids[] = $identifier->value;
45
            }
46
        }
47
48
        return $ids;
49
    }
50
51
    /**
52
     * Get the first active user identifier of a given type, like 'BARCODE' or 'UNIV_ID'.
53
     *
54
     * @param string $value
55
     * @param string $status
56
     *
57
     * @return null|string
58
     */
59
    public function firstOfType($value, $status = 'ACTIVE')
60
    {
61
        foreach ($this->data->user_identifier as $identifier) {
62
            if ($identifier->id_type->value == $value && (is_null($status) || $identifier->status == $status)) {
63
                return $identifier->value;
64
            }
65
        }
66
    }
67
68
    /**
69
     * Get the first active barcode.
70
     *
71
     * @return null|string
72
     */
73
    public function getBarcode()
74
    {
75
        return $this->firstOfType('BARCODE');
76
    }
77
78
    /**
79
     * Get all active barcodes.
80
     *
81
     * @return string[]
82
     */
83
    public function getBarcodes()
84
    {
85
        return $this->allOfType('BARCODE');
86
    }
87
88
    /**
89
     * Get the first active university id.
90
     *
91
     * @return null|string
92
     */
93
    public function getUniversityId()
94
    {
95
        return $this->firstOfType('UNIV_ID');
96
    }
97
98
    /**
99
     * Get all active university ids.
100
     *
101
     * @return string[]
102
     */
103
    public function getUniversityIds()
104
    {
105
        return $this->allOfType('UNIV_ID');
106
    }
107
}
108