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

Service::addNewRegistration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0023

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
ccs 11
cts 12
cp 0.9167
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
crap 2.0023
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
/**
17
 * Service Communicator with EDB-Brugs
18
 *
19
 * @category EDBBrugs
20
 * @package  EDBBrugs
21
 * @author   Lars Olesen <[email protected]>
22
 * @license  MIT Open Source License https://opensource.org/licenses/MIT
23
 * @version  GIT: <git_id>
24
 */
25
class Service
26
{
27
    protected $soap;
28
    protected $response;
29
30
    /**
31
     * Constructor
32
     *
33
     * @param object $soap Soap Client
34
     */
35 1
    public function __construct($soap)
36
    {
37 1
        $this->soap = $soap;
38 1
    }
39
40
    /**
41
     * Add new registration to EDBBrugs
42
     *
43
     * @param object $request The XML request to use when adding a new registration
44
     *
45
     * @return mixed (number of successful registrations) or throws Exception
46
     */
47 1
    public function addNewRegistration(Request $request)
48
    {
49 1
        $this->response = $this->soap->NyTilmelding2(
50
            array(
51 1
                'XmlData' => new \SoapVar($request->getRequest()->asXml(), XSD_STRING)
52 1
            )
53 1
        );
54 1
        if (!$this->isOk()) {
55
            throw new \Exception($this->response->NyTilmelding2Result);
56
        }
57 1
        return str_replace(
58 1
            'Oprettelse Ok, nye tilmeldinger: ',
59 1
            '',
60 1
            $this->response->NyTilmelding2Result
61 1
        );
62
    }
63
64
    /**
65
     * Checks whether the communication is OK
66
     *
67
     * @return boolean
68
     */
69 1
    protected function isOk()
70
    {
71 1
        $string = 'Oprettelse Ok, nye tilmeldinger';
72 1
        $result = strpos($this->response->NyTilmelding2Result, $string);
73 1
        return ($result !== false);
74
    }
75
}
76