Passed
Push — master ( d79a37...05d8cd )
by Dan Michael O.
01:59
created

User::getBarcodes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace App\Alma;
4
5
use Scriptotek\Alma\Client as AlmaClient;
0 ignored issues
show
Bug introduced by
The type Scriptotek\Alma\Client 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...
6
use Scriptotek\Alma\Exception\ResourceNotFound;
0 ignored issues
show
Bug introduced by
The type Scriptotek\Alma\Exception\ResourceNotFound 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
use Scriptotek\Alma\Users\User as AlmaUser;
0 ignored issues
show
Bug introduced by
The type Scriptotek\Alma\Users\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...
8
9
class User
10
{
11
    public $primaryId;
12
    public $barcodes;
13
    public $universityIds;
14
    public $group;
15
    public $email;
16
    public $phone;
17
    public $lang;
18
    public $firstName;
19
    public $lastName;
20
    public $name;
21
    public $blocks;
22
    public $type = 'alma';
23
24
    protected $user;
25
26
    public function __construct(AlmaUser $user)
27
    {
28
        $this->user = $user;
29
30
        foreach ($user->contact_info->email as $e) {
31
            if ($e->preferred) {
32
                $this->email = $e->email_address;
33
            }
34
        }
35
        foreach ($user->contact_info->phone as $e) {
36
            if ($e->preferred) {
37
                $this->phone = $e->phone_number;
38
            }
39
        }
40
        if (in_array($user->preferred_language->value, ['no', 'nb', 'nob'])) {
41
            $this->lang = 'nob';
42
        } elseif (in_array($user->preferred_language->value, ['nn', 'nno'])) {
43
            $this->lang = 'nno';
44
        } else {
45
            $this->lang = 'eng';
46
        }
47
48
        $this->firstName = $user->first_name;
49
        $this->lastName = $user->last_name;
50
        $this->primaryId = $user->primary_id;
51
        $this->group = $user->user_group->desc;
52
        $this->name = $this->lastName . ', ' . $this->firstName;
53
        $this->blocks = $user->user_block ?: [];
54
    }
55
56
    /**
57
     * Lookup user by primary or non-primary identifier.
58
     *
59
     * @param AlmaClient $alma
60
     * @param $identifier
61
     * @return User|null
62
     */
63
    public static function lookup(AlmaClient $alma, $identifier)
64
    {
65
        if (empty($identifier)) {
66
            return null;
67
        }
68
        try {
69
            return new self($alma->users->get($identifier)->init());
70
        } catch (ResourceNotFound $e) {
71
            throw $e;
72
            return null;
0 ignored issues
show
Unused Code introduced by
return null is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
73
        }
74
    }
75
76
    public static function isUserBarcode($value)
77
    {
78
        // 2-5 letters followed by 5-8 digits, making up 10 characters in total.
79
        return preg_match('/^[a-zA-Z]{2}[0-9a-zA-Z]{3}[0-9a-zA-Z]{5}$/', $value);
80
    }
81
82
    public function getBarcodes()
83
    {
84
//        if (self::isUserBarcode($this->primaryId)) {
85
//            return $this->primaryId;
86
//        }
87
        return $this->user->barcodes;
88
    }
89
90
    public function getUniversityIds()
91
    {
92
        return $this->user->universityIds;
93
    }
94
95
    public function getFees()
96
    {
97
        return $this->user->fees->total_sum;
98
    }
99
100
    public function getIdentifiers()
101
    {
102
        return $this->user->identifiers;
103
    }
104
}
105