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

NewRegistrationsResponse::getCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
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 NewRegistrationsResponse implements ResponseInterface
28
{
29
    protected $response;
30
31
    /**
32
     * Constructor
33
     *
34
     * @param object $response Actual response from SOAP
35
     */
36
    public function __construct($response)
37
    {
38
        $this->response = $response;
39
    }
40
41
    public function getCount()
42
    {
43
        return str_replace(
44
            'Oprettelse Ok, nye tilmeldinger: ',
45
            '',
46
            $this->response->NyTilmelding2Result
47
        );
48
    }
49
50
    /**
51
     * Add new registration to EDBBrugs
52
     *
53
     * @return mixed (number of successful registrations) or throws Exception
54
     */
55
    public function getBody()
56
    {
57
        if (!$this->isOk()) {
58
            throw new \Exception($this->response->NyTilmelding2Result);
59
        }
60
        return $this->response->NyTilmelding2Result;
61
    }
62
63
    /**
64
     * Checks whether the communication is OK
65
     *
66
     * @return boolean
67
     */
68
    public function isOk()
69
    {
70
        $string = 'Oprettelse Ok, nye tilmeldinger';
71
        $result = strpos($this->response->NyTilmelding2Result, $string);
72
        return ($result !== false);
73
74
    }
75
}
76