Skip to content

Commit b60fdd5

Browse files
committed
throw IncompleteConfigException for mandatory configuration parameters
1 parent 490cfb0 commit b60fdd5

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

src/Config/ConfigTypeA.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@ protected function getAllowedKeys(): array
5454
/**
5555
* Get the host name of a specific SAP application server.
5656
* @return string The hostname of a specific SAP application server.
57+
* @throws IncompleteConfigException
5758
* @throws InvalidArgumentException
5859
*/
5960
public function getAshost(): string
6061
{
61-
return $this->get(self::JSON_ASHOST);
62+
$ashost = $this->get(self::JSON_ASHOST);
63+
if (!is_string($ashost)) {
64+
throw new IncompleteConfigException('Configuration is missing mandatory "ashost"!');
65+
}
66+
return $ashost;
6267
}
6368

6469
/**
@@ -77,10 +82,15 @@ public function setAshost(string $ashost): IConfigTypeA
7782
* Get the SAP system number.
7883
* @return string The SAP system number.
7984
* @throws InvalidArgumentException
85+
* @throws IncompleteConfigException
8086
*/
8187
public function getSysnr(): string
8288
{
83-
return $this->get(self::JSON_SYSNR);
89+
$sysnr = $this->get(self::JSON_SYSNR);
90+
if (!is_string($sysnr)) {
91+
throw new IncompleteConfigException('Configuration is missing mandatory "sysnr"!');
92+
}
93+
return $sysnr;
8494
}
8595

8696
/**
@@ -102,9 +112,6 @@ public function setSysnr(string $sysnr): IConfigTypeA
102112
*/
103113
public function getGwhost(): ?string
104114
{
105-
/**
106-
* InvalidArgumentException will never be thrown.
107-
*/
108115
return $this->get(self::JSON_GWHOST);
109116
}
110117

@@ -127,9 +134,6 @@ public function setGwhost(string $gwhost): IConfigTypeA
127134
*/
128135
public function getGwserv(): ?string
129136
{
130-
/**
131-
* InvalidArgumentException will never be thrown.
132-
*/
133137
return $this->get(self::JSON_GWSERV);
134138
}
135139

src/Config/ConfigTypeB.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ protected function getAllowedKeys(): array
5858
*/
5959
public function getMshost(): string
6060
{
61-
return $this->get(self::JSON_MSHOST);
61+
$mshost = $this->get(self::JSON_MSHOST);
62+
if (!is_string($mshost)) {
63+
throw new IncompleteConfigException('Configuration is missing mandatory "mshost"!');
64+
}
65+
return $mshost;
6266
}
6367

6468
/**
@@ -80,9 +84,6 @@ public function setMshost(string $mshost): IConfigTypeB
8084
*/
8185
public function getR3name(): ?string
8286
{
83-
/**
84-
* InvalidArgumentException will never be thrown.
85-
*/
8687
return $this->get(self::JSON_R3NAME);
8788
}
8889

@@ -105,9 +106,6 @@ public function setR3name(string $r3name): IConfigTypeB
105106
*/
106107
public function getGroup(): ?string
107108
{
108-
/**
109-
* InvalidArgumentException will never be thrown.
110-
*/
111109
return $this->get(self::JSON_GROUP);
112110
}
113111

src/Config/Traits/CommonTrait.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ protected function getCommonAllowedKeys(): array
3434
/**
3535
* Get the username to use for authentication.
3636
* @return string
37+
* @throws IncompleteConfigException
3738
* @throws InvalidArgumentException
3839
*/
3940
public function getUser(): string
4041
{
41-
return $this->get(self::JSON_USER);
42+
$user = $this->get(self::JSON_USER);
43+
if (!is_string($user)) {
44+
throw new IncompleteConfigException('Configuration is missing mandatory "user"!');
45+
}
46+
return $user;
4247
}
4348

4449
/**
@@ -57,10 +62,15 @@ public function setUser(string $user): IConfiguration
5762
* Get the password to use for authentication.
5863
* @return string
5964
* @throws InvalidArgumentException
65+
* @throws IncompleteConfigException
6066
*/
6167
public function getPasswd(): string
6268
{
63-
return $this->get(self::JSON_PASSWD);
69+
$passwd = $this->get(self::JSON_PASSWD);
70+
if (!is_string($passwd)) {
71+
throw new IncompleteConfigException('Configuration is missing mandatory "passwd"!');
72+
}
73+
return $passwd;
6474
}
6575

6676
/**
@@ -83,7 +93,11 @@ public function setPasswd(string $passwd): IConfiguration
8393
*/
8494
public function getClient(): string
8595
{
86-
return $this->get(self::JSON_CLIENT);
96+
$client = $this->get(self::JSON_CLIENT);
97+
if (!is_string($client)) {
98+
throw new IncompleteConfigException('Configuration is missing mandatory "client"!');
99+
}
100+
return $client;
87101
}
88102

89103
/**
@@ -107,9 +121,6 @@ public function setClient(string $client): IConfiguration
107121
*/
108122
public function getSaprouter(): ?string
109123
{
110-
/**
111-
* InvalidArgumentException will never be thrown.
112-
*/
113124
return $this->get(self::JSON_SAPROUTER);
114125
}
115126

@@ -140,9 +151,6 @@ public function setSaprouter(string $saprouter): IConfiguration
140151
*/
141152
public function getTrace(): ?int
142153
{
143-
/**
144-
* InvalidArgumentException will never be thrown.
145-
*/
146154
return $this->get(self::JSON_TRACE);
147155
}
148156

@@ -173,9 +181,6 @@ public function setTrace(int $trace): IConfiguration
173181
*/
174182
public function getCodepage(): ?int
175183
{
176-
/**
177-
* InvalidArgumentException will never be thrown.
178-
*/
179184
return $this->get(self::JSON_CODEPAGE);
180185
}
181186

@@ -201,9 +206,6 @@ public function setCodepage(int $codepage): IConfiguration
201206
*/
202207
public function getLang(): ?string
203208
{
204-
/**
205-
* InvalidArgumentException will never be thrown.
206-
*/
207209
return $this->get(self::JSON_LANG);
208210
}
209211

@@ -231,9 +233,6 @@ public function setLang(string $lang): IConfiguration
231233
*/
232234
public function getDest(): ?string
233235
{
234-
/**
235-
* InvalidArgumentException will never be thrown.
236-
*/
237236
return $this->get(self::JSON_DEST);
238237
}
239238

0 commit comments

Comments
 (0)