Skip to content

Commit 1b9ac41

Browse files
odanodan
authored andcommitted
Fix cs
1 parent acb821e commit 1b9ac41

14 files changed

+44
-113
lines changed

src/Factory/NovaHttpClientFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Psr\Http\Message\ResponseInterface;
1313

1414
/**
15-
* NOVA HTTP Client Factory
15+
* NOVA HTTP Client Factory.
1616
*/
1717
final class NovaHttpClientFactory
1818
{
@@ -85,8 +85,10 @@ public function createLoggedInHttpClient(): NovaHttpClient
8585
* Create a guzzle client for the API to use.
8686
*
8787
* @param array $settings The settings
88-
* @return NovaHttpClient The http client
88+
*
8989
* @throws InvalidArgumentException
90+
*
91+
* @return NovaHttpClient The http client
9092
*/
9193
private function createHttpClient(array $settings): NovaHttpClient
9294
{

src/Method/CheckSwissPassValidityMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function createResult(XmlDocument $xml): NovaCheckSwissPassValidityResul
129129
{
130130
$result = new NovaCheckSwissPassValidityResult();
131131
$xml = $xml->withoutNamespaces();
132-
//$content = $xml->getXml();
132+
// $content = $xml->getXml();
133133

134134
// Find and append all messages
135135
foreach ($this->novaMessageParser->findNovaMessages($xml) as $message) {

src/Method/NovaPurchaseServicesMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private function createRequestBody(NovaPurchaseServicesParameter $parameter): st
140140
$amount = $dom->createElement('ns18:geldBetrag');
141141
$paymentInformation->appendChild($amount);
142142

143-
$amount->setAttribute('base:betrag', $parameter->price);
143+
$amount->setAttribute('base:betrag', (string)$parameter->price);
144144
$amount->setAttribute('base:waehrung', $parameter->currency);
145145

146146
return (string)$dom->saveXML();

src/Parameter/NovaPurchaseServicesParameter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ final class NovaPurchaseServicesParameter extends NovaIdentifierParameter
1717
/**
1818
* The SBB article price.
1919
*
20-
* @var string
20+
* @var float
2121
*/
22-
public $price = '';
22+
public $price = 0.00;
2323

2424
/**
2525
* The currency.

src/Parser/NovaApiSoapErrorParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use OrcaServices\NovaApi\Xml\XmlDocument;
99

1010
/**
11-
* Class.
11+
* Error parser.
1212
*/
1313
final class NovaApiSoapErrorParser
1414
{
@@ -120,7 +120,7 @@ private function getSoapValidationErrors(XmlDocument $xml): NovaApiErrorList
120120

121121
/** @var DOMNode $errorDetail */
122122
foreach ($errorList as $errorDetail) {
123-
$errors = $errors->withError($errorDetail->localName, $errorDetail->nodeValue);
123+
$errors = $errors->withError($errorDetail->localName ?? '', $errorDetail->nodeValue ?? '');
124124
}
125125

126126
return $errors;

src/Parser/NovaMessageParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function appendNovaMessages(XmlDocument $xml, array $namespace, array $m
6262
// Check for action response errors
6363
$messageNodes = $xml->queryNodes(sprintf('//%smeldungen/%smeldung', $ns1, $ns2));
6464

65-
if (empty($messageNodes) || $messageNodes->length === 0) {
65+
if ($messageNodes->length === 0) {
6666
return $messages;
6767
}
6868

src/Type/GenderType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ final class GenderType
1010
/**
1111
* Men Gender Type.
1212
*/
13-
const MEN = 1;
13+
public const MEN = 1;
1414

1515
/**
1616
* Women Gender Type.
1717
*/
18-
const WOMEN = 2;
18+
public const WOMEN = 2;
1919

2020
/**
2121
* Reserved for later Gender Type.
2222
*/
23-
const RESERVED = 3;
23+
public const RESERVED = 3;
2424

2525
/**
2626
* Unknown Gender Type.
2727
*/
28-
const UNKNOWN = 4;
28+
public const UNKNOWN = 4;
2929
}

src/Type/NovaSavReasonType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ final class NovaSavReasonType
1010
/**
1111
* Return before the 1st day of validity (20 CHF).
1212
*/
13-
const RETURN_BEFORE_1VALIDITY = 'RUECKGABE_VOR_1GELTUNGSTAG';
13+
public const RETURN_BEFORE_1VALIDITY = 'RUECKGABE_VOR_1GELTUNGSTAG';
1414

1515
/**
1616
* Partly used (10 CHF).
1717
*/
18-
const PARTLY_USED = 'TEILWEISE_BENUTZT';
18+
public const PARTLY_USED = 'TEILWEISE_BENUTZT';
1919
}

src/Xml/XmlDocument.php

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,6 @@ public static function createFromDom(DOMDocument $dom): self
7272
return new self(new DOMXPath($dom));
7373
}
7474

75-
/**
76-
* Add all namespaces automatically.
77-
*
78-
* @return void
79-
*/
80-
public function registerAllNamespaces()
81-
{
82-
foreach ($this->xpath->query('//namespace::*') ?: [] as $namespaceNode) {
83-
$prefix = str_replace('xmlns:', '', $namespaceNode->nodeName);
84-
$namespaceUri = $namespaceNode->nodeValue;
85-
$this->xpath->registerNamespace($prefix, $namespaceUri);
86-
}
87-
}
88-
8975
/**
9076
* Check if namespace exists.
9177
*
@@ -114,15 +100,14 @@ public function getNodeValue(string $expression, $contextNode = null): string
114100
{
115101
$nodes = $this->queryNodes($expression, $contextNode);
116102

117-
if (empty($nodes)
118-
|| $nodes->length === 0
119-
|| !($nodes->item(0) instanceof DOMElement)
120-
|| !($nodes->item(0) instanceof DOMNode)
103+
if ($nodes->length === 0 ||
104+
!($nodes->item(0) instanceof DOMElement) ||
105+
!($nodes->item(0) instanceof DOMNode)
121106
) {
122107
throw new InvalidXmlException(sprintf('XML DOM node [%s] not found.', $expression));
123108
}
124109

125-
return $nodes->item(0)->nodeValue;
110+
return $nodes->item(0)->nodeValue ?? '';
126111
}
127112

128113
/**
@@ -134,7 +119,7 @@ public function getNodeValue(string $expression, $contextNode = null): string
134119
*
135120
* @return string|null The node value
136121
*/
137-
private function findSingleNodeValue(string $expression, DOMXPath $xpath, $contextNode = null)
122+
private function findSingleNodeValue(string $expression, DOMXPath $xpath, $contextNode = null): ?string
138123
{
139124
if ($contextNode === null) {
140125
$node = $xpath->query($expression);
@@ -161,14 +146,13 @@ private function findSingleNodeValue(string $expression, DOMXPath $xpath, $conte
161146
*
162147
* @return string|null The node value
163148
*/
164-
public function findNodeValue(string $expression, $contextNode = null)
149+
public function findNodeValue(string $expression, $contextNode = null): ?string
165150
{
166151
$nodes = $this->queryNodes($expression, $contextNode);
167152

168-
if (empty($nodes)
169-
|| $nodes->length === 0
170-
|| !($nodes->item(0) instanceof DOMElement)
171-
|| !($nodes->item(0) instanceof DOMNode)
153+
if ($nodes->length === 0 ||
154+
!($nodes->item(0) instanceof DOMElement) ||
155+
!($nodes->item(0) instanceof DOMNode)
172156
) {
173157
return null;
174158
}
@@ -190,7 +174,7 @@ public function getAttributeValue(string $expression, $contextNode = null): stri
190174
{
191175
$nodes = $this->queryNodes($expression, $contextNode);
192176

193-
if (empty($nodes) || $nodes->length === 0 || !($nodes instanceof DOMNodeList)) {
177+
if ($nodes->length === 0) {
194178
throw new InvalidXmlException(sprintf('XML DOM attribute [%s] not found.', $expression));
195179
}
196180

@@ -199,7 +183,7 @@ public function getAttributeValue(string $expression, $contextNode = null): stri
199183
throw new InvalidXmlException(sprintf('XML DOM attribute [%s] not found.', $expression));
200184
}
201185

202-
return $attribute->nodeValue;
186+
return $attribute->nodeValue ?? '';
203187
}
204188

205189
/**

tests/TestCase/Client/NovaApiClientTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ public function testSearchPartnerByTkid()
6868
$this->assertSame('max.mustermann@example.com', $partner->email);
6969
$this->assertSame('Mustermann', $partner->firstName); // should be the lastName
7070
$this->assertSame('Max', $partner->lastName); // should be the firstName
71-
$this->assertSame('1982-03-28 00:00:00', $partner->dateOfBirth->toDateTimeString());
71+
$this->assertSame(
72+
'1982-03-28 00:00:00',
73+
$partner->dateOfBirth ? $partner->dateOfBirth->toDateTimeString() : ''
74+
);
7275
$this->assertSame(1, $partner->genderTypeId);
73-
$this->assertSame('2019-09-02 08:13:28', $partner->changedAt->toDateTimeString());
76+
$this->assertSame('2019-09-02 08:13:28', $partner->changedAt ? $partner->changedAt->toDateTimeString() : '');
7477
}
7578

7679
/**
@@ -227,7 +230,7 @@ public function testCreateOffersClass2()
227230
$parameter = new NovaCreateOffersParameter();
228231
$this->setIdentifier($parameter);
229232
$parameter->tkId = '949e2e6a-fdd1-4f07-8784-201e588ae834';
230-
$parameter->novaProductNumber = '51648';
233+
$parameter->novaProductNumber = 51648;
231234
$parameter->dateOfBirth = Chronos::createFromDate(1982, 03, 28);
232235
$parameter->genderTypeId = GenderType::MEN;
233236
$parameter->travelClass = 2;

0 commit comments

Comments
 (0)