Passed
Push — master ( 1fd74f...a7048c )
by Dan Michael O.
03:15
created

User::getFees()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Alma;
4
5
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...
6
7
class User
8
{
9
    public $primaryId;
10
    public $barcode;
11
    public $universityId;
12
    public $group;
13
    public $email;
14
    public $phone;
15
    public $lang;
16
    public $firstName;
17
    public $lastName;
18
    public $name;
19
    public $blocks;
20
    public $type = 'alma';
21
22
    protected $user;
23
24
    public static function isUserBarcode($value)
25
    {
26
        // 2-5 letters followed by 5-8 digits, making up 10 characters in total.
27
        return preg_match('/^[a-zA-Z]{2}[0-9a-zA-Z]{3}[0-9a-zA-Z]{5}$/', $value);
28
    }
29
30
    public function __construct(AlmaUser $user)
31
    {
32
        $this->user = $user;
33
34
        foreach ($user->contact_info->email as $e) {
35
            if ($e->preferred) {
36
                $this->email = $e->email_address;
37
            }
38
        }
39
        foreach ($user->contact_info->phone as $e) {
40
            if ($e->preferred) {
41
                $this->phone = $e->phone_number;
42
            }
43
        }
44
        if (in_array($user->preferred_language->value, ['no', 'nb', 'nob'])) {
45
            $this->lang = 'nob';
46
        } elseif (in_array($user->preferred_language->value, ['nn', 'nno'])) {
47
            $this->lang = 'nno';
48
        } else {
49
            $this->lang = 'eng';
50
        }
51
52
        $this->firstName = $user->first_name;
53
        $this->lastName = $user->last_name;
54
        $this->primaryId = $user->primary_id;
55
        $this->group = $user->user_group->desc;
56
        $this->name = $this->lastName . ', ' . $this->firstName;
57
        $this->blocks = $user->user_block ?: [];
58
    }
59
60
    public function getBarcode()
61
    {
62
        if (self::isUserBarcode($this->primaryId)) {
63
            return $this->primaryId;
64
        }
65
        return $this->user->barcode;
66
    }
67
68
    public function getUniversityId()
69
    {
70
        return $this->user->universityId;
71
    }
72
73
    public function getFees()
74
    {
75
        return $this->user->fees->total_sum;
76
    }
77
}
78