diff --git a/src/Bpack247.php b/src/Bpack247.php index c57fa5f..e5ac32f 100644 --- a/src/Bpack247.php +++ b/src/Bpack247.php @@ -33,9 +33,6 @@ class Bpack247 private string $accountId; private string $passPhrase; - /** @var CurlHandle|null */ - private ?CurlHandle $curl = null; - /** * The port to use. */ private ?int $port = null; @@ -82,15 +79,15 @@ private function doCall(string $url, ?string $body = null, string $method = 'GET $options[CURLOPT_POSTFIELDS] = $body ?? ''; } - $this->curl = curl_init(); - curl_setopt_array($this->curl, $options); + $curl = curl_init(); + curl_setopt_array($curl, $options); try { - $response = curl_exec($this->curl); - $info = curl_getinfo($this->curl); + $response = curl_exec($curl); + $info = curl_getinfo($curl); - $errorNumber = curl_errno($this->curl); - $errorMessage = curl_error($this->curl); + $errorNumber = curl_errno($curl); + $errorMessage = curl_error($curl); if ($errorNumber !== 0) { throw new BpostCurlException($errorMessage, $errorNumber); @@ -133,10 +130,8 @@ private function doCall(string $url, ?string $body = null, string $method = 'GET return $xml; } finally { - if (is_resource($this->curl) || $this->curl instanceof CurlHandle) { - curl_close($this->curl); - } - $this->curl = null; + curl_close($curl); + $curl = null; } } diff --git a/src/Bpost.php b/src/Bpost.php index 76b4805..4bb8155 100644 --- a/src/Bpost.php +++ b/src/Bpost.php @@ -26,6 +26,7 @@ use Bpost\BpostApiClient\Exception\BpostNotImplementedException; use Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException; use Bpost\BpostApiClient\Exception\XmlException\BpostXmlNoReferenceFoundException; +use Bpost\BpostApiClient\Bpost\HttpRequestBuilder\ModifyOrderBuilder; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use SimpleXMLElement; diff --git a/src/Bpost/Labels.php b/src/Bpost/Labels.php index a75abde..91f966f 100644 --- a/src/Bpost/Labels.php +++ b/src/Bpost/Labels.php @@ -20,7 +20,9 @@ public static function createFromXML(SimpleXMLElement $xml): array if (isset($xml->label)) { foreach ($xml->label as $labelXml) { - $labels[] = Label::createFromXML($labelXml); + if ($labelXml instanceof \SimpleXMLElement) { + $labels[] = Label::createFromXML($labelXml); + } } } diff --git a/src/Bpost/Order/Address.php b/src/Bpost/Order/Address.php index 1e9cb92..0417a8b 100644 --- a/src/Bpost/Order/Address.php +++ b/src/Bpost/Order/Address.php @@ -224,62 +224,4 @@ public static function createFromXML(SimpleXMLElement $xml): Address } return $address; } - - /** - * @throws \DOMException - */ - private function streetToXML(DOMDocument $document, string $prefix, DOMElement $address): void - { - if ($this->streetName !== null) { - $address->appendChild( - $document->createElement(XmlHelper::getPrefixedTagName('streetName', $prefix), $this->streetName) - ); - } - } - - /** - * @throws \DOMException - */ - private function localityToXML(DOMDocument $document, string $prefix, DOMElement $address): void - { - if ($this->postalCode !== null) { - $address->appendChild( - $document->createElement(XmlHelper::getPrefixedTagName('postalCode', $prefix), $this->postalCode) - ); - } - if ($this->locality !== null) { - $address->appendChild( - $document->createElement(XmlHelper::getPrefixedTagName('locality', $prefix), $this->locality) - ); - } - } - - /** - * @throws \DOMException - */ - private function countryToXML(DOMDocument $document, string $prefix, DOMElement $address): void - { - if ($this->countryCode !== null) { - $address->appendChild( - $document->createElement(XmlHelper::getPrefixedTagName('countryCode', $prefix), $this->countryCode) - ); - } - } - - /** - * @throws \DOMException - */ - private function streetNumbersToXML(DOMDocument $document, string $prefix, DOMElement $address): void - { - if ($this->number !== null) { - $address->appendChild( - $document->createElement(XmlHelper::getPrefixedTagName('number', $prefix), $this->number) - ); - } - if ($this->box !== null) { - $address->appendChild( - $document->createElement(XmlHelper::getPrefixedTagName('box', $prefix), $this->box) - ); - } - } } \ No newline at end of file diff --git a/src/Bpost/Order/Box/International/ParcelContent.php b/src/Bpost/Order/Box/International/ParcelContent.php index 5c675c1..bad1a80 100644 --- a/src/Bpost/Order/Box/International/ParcelContent.php +++ b/src/Bpost/Order/Box/International/ParcelContent.php @@ -82,6 +82,7 @@ public function getItemDescription(): ?string public function setItemDescription(?string $itemDescription): void { + $itemDescription = (string) $itemDescription; if (strlen($itemDescription) > 30) { $itemDescription = substr($itemDescription, 0, 30); } diff --git a/src/Bpost/Order/Box/National.php b/src/Bpost/Order/Box/National.php index ed12293..14bb7a8 100644 --- a/src/Bpost/Order/Box/National.php +++ b/src/Bpost/Order/Box/National.php @@ -172,7 +172,7 @@ public static function createFromXML(SimpleXMLElement $xml, National $self = nul $self->setProduct((string)$nationalXml->product); } - if (isset($nationalXml->options) && !empty($nationalXml->options)) { + if (!empty($nationalXml->options)) { foreach ($nationalXml->options as $optionData) { $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common'); diff --git a/src/Bpost/ProductConfiguration/Option.php b/src/Bpost/ProductConfiguration/Option.php index 4425387..90b16e6 100644 --- a/src/Bpost/ProductConfiguration/Option.php +++ b/src/Bpost/ProductConfiguration/Option.php @@ -42,11 +42,15 @@ public static function createFromXML(SimpleXMLElement $xml): self // characteristics (supporte l’ancienne faute "chracteristic") if (isset($children->characteristic)) { foreach ($children->characteristic as $charXml) { - $self->addCharacteristic(Characteristic::createFromXML($charXml)); + if ($charXml instanceof \SimpleXMLElement) { + $self->addCharacteristic(Characteristic::createFromXML($charXml)); + } } } elseif (isset($children->chracteristic)) { foreach ($children->chracteristic as $charXml) { - $self->addCharacteristic(Characteristic::createFromXML($charXml)); + if ($charXml instanceof \SimpleXMLElement) { + $self->addCharacteristic(Characteristic::createFromXML($charXml)); + } } } diff --git a/src/Geo6.php b/src/Geo6.php index 16e03e1..cf0ab34 100644 --- a/src/Geo6.php +++ b/src/Geo6.php @@ -48,18 +48,18 @@ class Geo6 /** Suffixe d’UA applicatif */ private string $userAgent = ''; - private Logger $logger; + private LoggerInterface $logger; /** * @param string $partner Paramètre statique de protection/statistiques * @param string $appId Paramètre statique de protection/statistiques * @param LoggerInterface|null $psrLogger Logger PSR optionnel (NullLogger par défaut) */ - public function __construct(string $partner, string $appId, ?LoggerInterface $psrLogger = null) + public function __construct(string $partner, string $appId, ?LoggerInterface $logger = null) { $this->setPartner($partner); $this->setAppId($appId); - $this->logger = new Logger($psrLogger ?? new NullLogger()); + $this->logger = $logger ?? new NullLogger(); } public function getApiCaller(): ApiCaller diff --git a/src/Geo6/Day.php b/src/Geo6/Day.php index 24cacf3..3acd544 100644 --- a/src/Geo6/Day.php +++ b/src/Geo6/Day.php @@ -72,6 +72,7 @@ public function getAmOpen(): ?string public function setDay(string $day): void { + $normalized = ucfirst(strtolower($day)); $this->day = $normalized; }