Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/Bpack247.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Bpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/Bpost/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
58 changes: 0 additions & 58 deletions src/Bpost/Order/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
}
1 change: 1 addition & 0 deletions src/Bpost/Order/Box/International/ParcelContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bpost/Order/Box/National.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
8 changes: 6 additions & 2 deletions src/Bpost/ProductConfiguration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Geo6.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Geo6/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function getAmOpen(): ?string

public function setDay(string $day): void
{
$normalized = ucfirst(strtolower($day));
$this->day = $normalized;
}

Expand Down
Loading