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\ResponseInterface; |
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 Response implements ResponseInterface |
28
|
|
|
{ |
29
|
|
|
protected $responseType; |
30
|
|
|
protected $response; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor |
34
|
|
|
* |
35
|
|
|
* @param object $responseType Response type |
36
|
|
|
* @param object $response Actual response from SOAP |
37
|
|
|
*/ |
38
|
1 |
|
public function __construct($responseType, $response) |
39
|
|
|
{ |
40
|
1 |
|
$this->responseType = $responseType; |
41
|
1 |
|
$this->response = $response; |
42
|
1 |
|
} |
43
|
|
|
|
44
|
1 |
|
public function getCount() |
45
|
|
|
{ |
46
|
1 |
|
return str_replace( |
47
|
1 |
|
'Oprettelse Ok, nye tilmeldinger: ', |
48
|
1 |
|
'', |
49
|
1 |
|
$this->response->NyTilmelding2Result |
50
|
1 |
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Add new registration to EDBBrugs |
55
|
|
|
* |
56
|
|
|
* @return mixed (number of successful registrations) or throws Exception |
57
|
|
|
*/ |
58
|
|
|
public function getBody() |
59
|
|
|
{ |
60
|
|
|
switch ($this->responseType) { |
61
|
|
View Code Duplication |
case 'NyTilmelding2': |
|
|
|
|
62
|
|
|
if (!$this->isOk()) { |
63
|
|
|
throw new \Exception($this->response->NyTilmelding2Result); |
64
|
|
|
} |
65
|
|
|
return str_replace( |
66
|
|
|
'Oprettelse Ok, nye tilmeldinger: ', |
67
|
|
|
'', |
68
|
|
|
$this->response->NyTilmelding2Result |
69
|
|
|
); |
70
|
|
|
break; |
|
|
|
|
71
|
|
View Code Duplication |
case 'SletTilmeldingerV2': |
|
|
|
|
72
|
|
|
if (!$this->isOk()) { |
73
|
|
|
throw new \Exception($this->response->SletTilmeldingerV2Result); |
74
|
|
|
} |
75
|
|
|
return str_replace( |
76
|
|
|
'Oprettelse Ok, nye tilmeldinger: ', |
77
|
|
|
'', |
78
|
|
|
$this->response->SletTilmeldingerV2Response |
79
|
|
|
); |
80
|
|
|
break; |
|
|
|
|
81
|
|
|
case 'HentNyeTilmeldingerV2': |
82
|
|
|
return $this->response->HentNyeTilmeldingerV2Result; |
83
|
|
|
break; |
|
|
|
|
84
|
|
|
default: |
85
|
|
|
throw new \Exception($this->responseType . ' is not a valid response type'); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Checks whether the communication is OK |
91
|
|
|
* |
92
|
|
|
* @return boolean |
93
|
|
|
*/ |
94
|
|
|
public function isOk() |
95
|
|
|
{ |
96
|
|
|
switch ($this->responseType) { |
97
|
|
|
case 'NyTilmelding2': |
98
|
|
|
$string = 'Oprettelse Ok, nye tilmeldinger'; |
99
|
|
|
$result = strpos($this->response->NyTilmelding2Result, $string); |
100
|
|
|
return ($result !== false); |
101
|
|
|
case 'SletTilmeldingerV2': |
102
|
|
|
$string = 'Oprettelse Ok, nye tilmeldinger'; |
103
|
|
|
$result = strpos($this->response->SletTilmeldingerV2Result, $string); |
104
|
|
|
return ($result !== false); |
105
|
|
|
case 'HentNyeTilmeldingerV2': |
106
|
|
|
$string = 'Oprettelse Ok, nye tilmeldinger'; |
107
|
|
|
$result = strpos($this->response->HentNyeTilmeldingerV2Result, $string); |
108
|
|
|
return ($result !== false); |
109
|
|
|
default: |
110
|
|
|
throw new \Exception('Not a valid response type'); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.