Completed
Push — master ( 381bc0...2b9053 )
by Lars
05:55 queued 02:03
created

RegistrationsCreateResponse::getBody()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * SDK to communicate with EDBBrugs
4
 *
5
 * PHP Version 5
6
 *
7
 * @category EDBBrugs
8
 * @package  EDBBrugs
9
 * @author   Lars Olesen <[email protected]>
10
 * @license  MIT Open Source License https://opensource.org/licenses/MIT
11
 * @version  GIT: <git_id>
12
 */
13
14
namespace EDBBrugs;
15
16
use EDBBrugs\Response;
17
18
/**
19
 * Service Communicator with EDB-Brugs
20
 *
21
 * @category EDBBrugs
22
 * @package  EDBBrugs
23
 * @author   Lars Olesen <[email protected]>
24
 * @license  MIT Open Source License https://opensource.org/licenses/MIT
25
 * @version  GIT: <git_id>
26
 */
27
class RegistrationsCreateResponse extends Response
28
{
29
    protected $response;
30
31
    /**
32
     * Constructor
33
     *
34
     * @param object $response Actual response from SOAP
35
     */
36 1
    public function __construct($response)
37
    {
38 1
        $this->response = $response;
39 1
    }
40
41
    /**
42
     * Add new registration to EDBBrugs
43
     *
44
     * @return mixed (number of successful registrations) or
45
     * @throws \Exception
46
     */
47
    public function getBody()
48
    {
49
        if (!$this->isOk()) {
50
            throw new \Exception($this->response->NyTilmelding2Result);
51
        }
52
        return $this->response->NyTilmelding2Result;
53
    }
54
55
    /**
56
     * Checks whether the communication is a success
57
     *
58
     * @return boolean
59
     */
60
    public function isOk()
61
    {
62
        $string = 'Oprettelse Ok, nye tilmeldinger';
63
        $result = strpos($this->response->NyTilmelding2Result, $string);
64
        return ($result !== false);
65
    }
66
67
    /**
68
     * Returns how many registrations has been created
69
     *
70
     * @return mixed
71
     */
72 1
    public function getCount()
73
    {
74 1
        return str_replace(
75 1
            'Oprettelse Ok, nye tilmeldinger: ',
76 1
            '',
77 1
            $this->response->NyTilmelding2Result
78 1
        );
79
    }
80
}
81