Completed
Pull Request — master (#9)
by Lars
02:33
created

RegistrationsCreateResponse::isOk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

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 1
eloc 4
nc 1
nop 0
crap 2
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 throws Exception
45
     */
46
    public function getBody()
47
    {
48
        if (!$this->isOk()) {
49
            throw new \Exception($this->response->NyTilmelding2Result);
50
        }
51
        return $this->response->NyTilmelding2Result;
52
    }
53
54
    /**
55
     * Checks whether the communication is a success
56
     *
57
     * @return boolean
58
     */
59
    public function isOk()
60
    {
61
        $string = 'Oprettelse Ok, nye tilmeldinger';
62
        $result = strpos($this->response->NyTilmelding2Result, $string);
63
        return ($result !== false);
64
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