Passed
Push — master ( faa861...d7c7ec )
by Will
05:37
created

AlmaUserData::getFirstLastName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Service;
4
5
use GuzzleHttp\Psr7\Response;
6
use SimpleXMLElement;
7
8
class AlmaUserData
9
{
10
    /**
11
     * Given a guzzle response from Alma, return the list of fees as an associative array with each
12
     * fee and each fees properties
13
     *
14
     * @param Response $response
15
     * @return array
16
     */
17
    public function listFees(Response $response)
18
    {
19
        $sxml = new SimpleXMLElement($response->getBody());
20
21
        $list_fees = [];
22
23
        // "fee" is an array that includes each individual fee in the user "fees" object in Alma
24
        foreach ($sxml->fee as $indv_fee) {
25
            $list_fees[] = [
26
                'id' => (string)$indv_fee->id,
27
                'label' => (string)$indv_fee->type->attributes()->desc,
28
                'balance' => (string)$indv_fee->balance,
29
                'title' => (string)$indv_fee->title,
30
                'date' => new \DateTime($indv_fee->creation_time)
31
            ];
32
        }
33
        return $list_fees;
34
    }
35
36
    /**
37
     * Get the full name of user from Alma API response
38
     *
39
     * @param Response $response
40
     * @return string
41
     */
42
    public function getFullNameAsString(Response $response)
43
    {
44
        $sxml = new SimpleXMLElement($response->getBody());
45
        return $sxml->full_name->__toString();
46
    }
47
48
    /**
49
     * Checks that there is exactly one user has primary_id set to 'Shib-uaId' property (the user UA id)
50
     *
51
     * @param Response $response
52
     * @return bool
53
     */
54
    public function isValidUser(Response $response)
55
    {
56
        $sxml = new SimpleXMLElement($response->getBody());
57
        return $sxml->attributes()->total_record_count == '1';
58
    }
59
}
60