Skip to content

Commit

Permalink
Merge pull request #40 from FriendsOfCXML/php_8.4
Browse files Browse the repository at this point in the history
Php 8.4
  • Loading branch information
mathielen authored Dec 30, 2024
2 parents 14a7930 + 35297bd commit 6d80c20
Show file tree
Hide file tree
Showing 32 changed files with 73 additions and 66 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
php-version: [
'8.2',
'8.3',
'8.4'
]

steps:
Expand Down
12 changes: 9 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Config\RectorConfig;
use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\JMSSetList;
Expand All @@ -13,9 +14,13 @@
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpVersion(Rector\ValueObject\PhpVersion::PHP_84) //need this to enable PHP 8.4 features although lower requirement in composer
->withRules([
ExplicitNullableParamTypeRector::class, // php8.4 feature, compatible with php8.0
])
->withSets([
JMSSetList::ANNOTATIONS_TO_ATTRIBUTES,
PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::PHPUNIT_110,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
SetList::TYPE_DECLARATION,
Expand All @@ -33,9 +38,10 @@
\Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector::class,
//allow to use promoted properties that only purpose is to get serialized
\Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector::class,
//this is stupid and makes code unreadable
//this makes code unreadable
\Rector\Strict\Rector\Ternary\BooleanInTernaryOperatorRuleFixerRector::class,
\Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector::class
\Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector::class,
\Rector\Php81\Rector\Property\ReadOnlyPropertyRector::class,
])
->withFileExtensions(['php'])
->withCache(
Expand Down
8 changes: 4 additions & 4 deletions src/CXml/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ class Builder

private ?Status $status = null;

private function __construct(private ?string $senderUserAgent, private readonly ?string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null)
private function __construct(private ?string $senderUserAgent, private readonly ?string $locale = null, ?PayloadIdentityFactoryInterface $payloadIdentityFactory = null)
{
$this->payloadIdentityFactory = $payloadIdentityFactory ?? new DefaultPayloadIdentityFactory();
}

public static function create(string $senderUserAgent = 'cxml-php UserAgent', string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null): self
public static function create(string $senderUserAgent = 'cxml-php UserAgent', ?string $locale = null, ?PayloadIdentityFactoryInterface $payloadIdentityFactory = null): self
{
return new self($senderUserAgent, $locale, $payloadIdentityFactory);
}

public function payload(PayloadInterface $payload = null): self
public function payload(?PayloadInterface $payload = null): self
{
$this->payload = $payload;

Expand Down Expand Up @@ -199,7 +199,7 @@ private function buildHeader(): Header
/**
* @throws CXmlException
*/
public function build(string $deploymentMode = null): CXml
public function build(?string $deploymentMode = null): CXml
{
switch (true) {
case $this->payload instanceof RequestPayloadInterface:
Expand Down
26 changes: 13 additions & 13 deletions src/CXml/Builder/OrderRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public static function create(

public static function fromPunchOutOrderMessage(
PunchOutOrderMessage $punchOutOrderMessage,
string $currency = null,
string $orderId = null,
DateTimeInterface $orderDate = null,
?string $currency = null,
?string $orderId = null,
?DateTimeInterface $orderDate = null,
string $language = 'en',
): self {
if (($supplierOrderInfo = $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getSupplierOrderInfo()) instanceof SupplierOrderInfo) {
Expand Down Expand Up @@ -126,13 +126,13 @@ public static function fromPunchOutOrderMessage(

public function billTo(
string $name,
PostalAddress $postalAddress = null,
string $addressId = null,
string $addressIdDomain = null,
string $email = null,
Phone $phone = null,
string $fax = null,
string $url = null,
?PostalAddress $postalAddress = null,
?string $addressId = null,
?string $addressIdDomain = null,
?string $email = null,
?Phone $phone = null,
?string $fax = null,
?string $url = null,
): self {
$this->billTo = new BillTo(
new Address(
Expand All @@ -154,8 +154,8 @@ public function shipTo(
string $name,
PostalAddress $postalAddress,
array $carrierIdentifiers = [],
string $carrierAccountNo = null,
string $carrierShippingMethod = null,
?string $carrierAccountNo = null,
?string $carrierShippingMethod = null,
): self {
$transportInformation = null;
if (null !== $carrierAccountNo || null != $carrierShippingMethod) {
Expand Down Expand Up @@ -263,7 +263,7 @@ public function addItem(
return $item;
}

public function addComment(string $value = null, string $type = null, string $lang = null, string $attachmentUrl = null): self
public function addComment(?string $value = null, ?string $type = null, ?string $lang = null, ?string $attachmentUrl = null): self
{
$this->comments[] = new Comment(
$value,
Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Builder/ProductActivityMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function create(string $messageId, string $warehouseCodeDomain): s
return new self($messageId, $warehouseCodeDomain);
}

public function addProductActivityDetail(string $sku, string $warehouseCode, int $stockLevel, array $extrinsics = null): self
public function addProductActivityDetail(string $sku, string $warehouseCode, int $stockLevel, ?array $extrinsics = null): self
{
$inventory = Inventory::create()
->setStockOnHandQuantity(new InventoryQuantity($stockLevel, 'EA'));
Expand Down
16 changes: 8 additions & 8 deletions src/CXml/Builder/PunchOutOrderMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ private function __construct(private readonly string $language, private readonly
{
}

public static function create(string $language, string $buyerCookie, string $currency, string $operationAllowed = null): self
public static function create(string $language, string $buyerCookie, string $currency, ?string $operationAllowed = null): self
{
return new self($language, $buyerCookie, $currency, $operationAllowed);
}

public function orderReference(string $orderId, DateTimeInterface $orderDate = null): self
public function orderReference(string $orderId, ?DateTimeInterface $orderDate = null): self
{
$this->orderId = $orderId;
$this->orderDate = $orderDate;
Expand All @@ -64,8 +64,8 @@ public function shipTo(
string $name,
PostalAddress $postalAddress,
array $carrierIdentifiers = [],
string $carrierAccountNo = null,
string $carrierShippingMethod = null,
?string $carrierAccountNo = null,
?string $carrierShippingMethod = null,
): self {
$transportInformation = null;
if (null !== $carrierAccountNo || null != $carrierShippingMethod) {
Expand Down Expand Up @@ -124,10 +124,10 @@ public function addPunchoutOrderMessageItem(
string $unitOfMeasure,
int $unitPrice,
array $classifications,
string $manufacturerPartId = null,
string $manufacturerName = null,
int $leadTime = null,
array $extrinsics = null,
?string $manufacturerPartId = null,
?string $manufacturerName = null,
?int $leadTime = null,
?array $extrinsics = null,
): self {
$itemDetail = ItemDetail::create(
new Description(
Expand Down
4 changes: 2 additions & 2 deletions src/CXml/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
private Serializer $serializer,
private DtdValidator $dtdValidator,
private Processor $processor,
LoggerInterface $logger = null,
?LoggerInterface $logger = null,
) {
$this->logger = $logger ?? new NullLogger();
}
Expand All @@ -30,7 +30,7 @@ public function __construct(
* @throws CXmlException
* @throws CXmlInvalidException
*/
public function parseAndProcessStringAsCXml(string $xml, Context $context = null): ?CXml
public function parseAndProcessStringAsCXml(string $xml, ?Context $context = null): ?CXml
{
$this->logger->info('Processing incoming CXml message', ['xml' => $xml]);

Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Exception/CXmlCredentialInvalidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class CXmlCredentialInvalidException extends CXmlExpectationFailedException
{
public function __construct(string $message, private readonly ?Credential $credential = null, Throwable $previous = null)
public function __construct(string $message, private readonly ?Credential $credential = null, ?Throwable $previous = null)
{
parent::__construct($message . ($credential instanceof Credential ? "\nCredential was:" . $credential : ''), $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Exception/CXmlException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class CXmlException extends Exception
{
public function __construct(string $message, Throwable $previous = null)
public function __construct(string $message, ?Throwable $previous = null)
{
parent::__construct($message, 0, $previous);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class CXmlHandlerNotFoundException extends CXmlNotImplementedException
{
public function __construct(string $handlerId, Throwable $previous = null)
public function __construct(string $handlerId, ?Throwable $previous = null)
{
parent::__construct(sprintf('Handler for %s not found. Register first.', $handlerId), $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Handler/HandlerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class HandlerRegistry implements HandlerRegistryInterface
*/
private array $registry = [];

public function register(HandlerInterface $handler, string $handlerId = null): void
public function register(HandlerInterface $handler, ?string $handlerId = null): void
{
if (null === $handlerId || '' === $handlerId || '0' === $handlerId) {
$handlerId = $handler::getRequestName();
Expand Down
6 changes: 3 additions & 3 deletions src/CXml/Model/CXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ protected function __construct(
) {
}

public static function forMessage(PayloadIdentity $payloadIdentity, Message $message, Header $header, string $lang = null): self
public static function forMessage(PayloadIdentity $payloadIdentity, Message $message, Header $header, ?string $lang = null): self
{
return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), null, null, $message, $header, $lang);
}

public static function forRequest(PayloadIdentity $payloadIdentity, Request $request, Header $header, string $lang = null): self
public static function forRequest(PayloadIdentity $payloadIdentity, Request $request, Header $header, ?string $lang = null): self
{
return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), $request, null, null, $header, $lang);
}

public static function forResponse(PayloadIdentity $payloadIdentity, Response $response, string $lang = null): self
public static function forResponse(PayloadIdentity $payloadIdentity, Response $response, ?string $lang = null): self
{
return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), null, $response, null, null, $lang);
}
Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Model/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
private ?string $type = null,
#[Serializer\XmlAttribute(namespace: 'http://www.w3.org/XML/1998/namespace')]
private ?string $lang = null,
string $attachment = null,
?string $attachment = null,
) {
$this->attachment = null !== $attachment && '' !== $attachment && '0' !== $attachment ? new Url($attachment) : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Model/CommentsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait CommentsTrait
#[Serializer\Type('array<CXml\Model\Comment>')]
private ?array $comments = null;

public function addCommentAsString(string $comment, string $type = null, string $lang = null): self
public function addCommentAsString(string $comment, ?string $type = null, ?string $lang = null): self
{
if (null === $this->comments) {
$this->comments = [];
Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Model/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
) {
}

public static function create(MultilanguageString $name, string $role = null): self
public static function create(MultilanguageString $name, ?string $role = null): self
{
return new self($name, $role);
}
Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Model/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Date extends DateTime
{
public static function createFromFormat($format, $datetime, DateTimeZone $timezone = null): DateTime|false|Date
public static function createFromFormat($format, $datetime, ?DateTimeZone $timezone = null): DateTime|false|Date
{
$dateTime = parent::createFromFormat($format, $datetime, $timezone);
if (false === $dateTime) {
Expand Down
4 changes: 2 additions & 2 deletions src/CXml/Model/Description.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class Description extends MultilanguageString
#[Serializer\XmlElement(cdata: false)]
private ?string $shortName = null;

public function __construct(?string $value, string $type = null, string $lang = 'en')
public function __construct(?string $value, ?string $type = null, string $lang = 'en')
{
parent::__construct($value, $type, $lang);
}

public static function createWithShortName(string $shortName, string $type = null, string $lang = 'en'): self
public static function createWithShortName(string $shortName, ?string $type = null, string $lang = 'en'): self
{
$new = new self(null, $type, $lang);
$new->setShortname($shortName);
Expand Down
4 changes: 2 additions & 2 deletions src/CXml/Model/ItemOut.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static function create(
int $quantity,
ItemId $itemId,
ItemDetail $itemDetail,
DateTimeInterface $requestedDeliveryDate = null,
int $parentLineNumber = null,
?DateTimeInterface $requestedDeliveryDate = null,
?int $parentLineNumber = null,
): self {
return new self(
$lineNumber,
Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Model/Message/ProductActivityDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private function __construct(
) {
}

public static function create(ItemId $itemId, Inventory $inventory = null, Contact $contact = null, MultilanguageString $description = null): self
public static function create(ItemId $itemId, ?Inventory $inventory = null, ?Contact $contact = null, ?MultilanguageString $description = null): self
{
return new self($itemId, $inventory, $contact, $description);
}
Expand Down
4 changes: 2 additions & 2 deletions src/CXml/Model/Message/ProductActivityMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class ProductActivityMessage implements MessagePayloadInterface
#[Serializer\Type('array<CXml\Model\Message\ProductActivityDetail>')]
private array $productActivityDetails = [];

private function __construct(string $messageId, string $processType = null, DateTimeInterface $creationDate = null)
private function __construct(string $messageId, ?string $processType = null, ?DateTimeInterface $creationDate = null)
{
$this->productActivityHeader = new ProductActivityHeader($messageId, $processType, $creationDate);
}

public static function create(string $messageId, string $processType = null, DateTimeInterface $creationDate = null): self
public static function create(string $messageId, ?string $processType = null, ?DateTimeInterface $creationDate = null): self
{
return new self($messageId, $processType, $creationDate);
}
Expand Down
4 changes: 2 additions & 2 deletions src/CXml/Model/Message/PunchOutOrderMessageHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
private readonly ?Shipping $shipping = null,
#[Serializer\SerializedName('Tax')]
private readonly ?Tax $tax = null,
string $operationAllowed = null,
?string $operationAllowed = null,
) {
Assertion::inArray($operationAllowed, [self::OPERATION_CREATE, self::OPERATION_EDIT, self::OPERATION_INSPECT, null]);
$this->operationAllowed = $operationAllowed ?? self::OPERATION_CREATE;
Expand All @@ -56,7 +56,7 @@ public function getShipTo(): ?ShipTo
return $this->shipTo;
}

public function setSupplierOrderInfo(string $orderId, DateTimeInterface $orderDate = null): self
public function setSupplierOrderInfo(string $orderId, ?DateTimeInterface $orderDate = null): self
{
$this->supplierOrderInfo = new SupplierOrderInfo($orderId, $orderDate);

Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Model/PayloadIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{
private DateTimeInterface $timestamp;

public function __construct(private string $payloadId, DateTimeInterface $timestamp = null)
public function __construct(private string $payloadId, ?DateTimeInterface $timestamp = null)
{
$this->timestamp = $timestamp ?? new DateTime();
}
Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Model/Request/OrderRequestHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function create(
MoneyWrapper $total,
string $type = self::TYPE_NEW,
?DateTimeInterface $requestedDeliveryDate = null,
array $contacts = null,
?array $contacts = null,
): self {
return new self($orderId, $orderDate, $shipTo, $billTo, $total, $type, $requestedDeliveryDate, $contacts);
}
Expand Down
6 changes: 3 additions & 3 deletions src/CXml/Model/Request/ShipNoticeHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ public function __construct(
#[Serializer\XmlAttribute]
#[Serializer\SerializedName('shipmentID')]
private readonly string $shipmentId,
DateTimeInterface $noticeDate = null,
?DateTimeInterface $noticeDate = null,
#[Serializer\XmlAttribute]
private readonly ?DateTimeInterface $shipmentDate = null,
#[Serializer\XmlAttribute]
private readonly ?DateTimeInterface $deliveryDate = null,
string $documentReference = null,
?string $documentReference = null,
) {
$this->noticeDate = $noticeDate ?? new DateTime();
$this->documentReference = null !== $documentReference && '' !== $documentReference && '0' !== $documentReference ? new DocumentReference($documentReference) : null;
}

public static function create(string $shipmentId, DateTimeInterface $noticeDate = null, DateTimeInterface $shipmentDate = null, DateTimeInterface $deliveryDate = null, string $documentReference = null): self
public static function create(string $shipmentId, ?DateTimeInterface $noticeDate = null, ?DateTimeInterface $shipmentDate = null, ?DateTimeInterface $deliveryDate = null, ?string $documentReference = null): self
{
return new self($shipmentId, $noticeDate, $shipmentDate, $deliveryDate, $documentReference);
}
Expand Down
Loading

0 comments on commit 6d80c20

Please sign in to comment.