diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 707908f..f680be0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,4 +1,4 @@
-name: CI
+name: CI / Static
on:
push:
@@ -17,9 +17,6 @@ jobs:
fail-fast: false
matrix:
php-version: [
- '7.4',
- '8.0',
- '8.1',
'8.2',
'8.3',
]
@@ -31,7 +28,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
- coverage: none
+ coverage: pcov
extensions: dom, libxml, simplexml
tools: composer:v2
@@ -58,13 +55,16 @@ jobs:
run: vendor/bin/parallel-lint src/
- name: Run CodeStyle checks
- run: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer check --allow-risky=yes --diff
+ run: composer run cs-check
- name: Run PHPStan
- run: vendor/bin/phpstan analyze -clear-result-cache -c phpstan.neon src/ --no-progress
+ run: composer run phpstan
+
+ - name: Run Rector
+ run: composer run rector-check
- name: Run Tests
- run: vendor/bin/phpunit --testdox tests
+ run: composer run test
- name: Run Security check
- run: vendor/bin/security-checker security:check composer.lock
+ run: composer run security-check
diff --git a/.gitignore b/.gitignore
index 42913ff..c831d98 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,6 @@
vendor
composer.lock
.idea
-.phpunit.result.cache
+/.phpunit.result.cache
+/.phpunit.cache
+/.phpstan/
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
new file mode 100644
index 0000000..4bac94b
--- /dev/null
+++ b/.php-cs-fixer.dist.php
@@ -0,0 +1,44 @@
+in(__DIR__ . '/src')
+ ->in(__DIR__ . '/tests');
+
+$config = new Config();
+
+return $config
+ ->setParallelConfig((new ParallelConfig()))
+ ->setRiskyAllowed(true)
+ ->setRules([
+ '@PSR2' => true,
+ '@PSR1' => true,
+ '@PhpCsFixer' => true,
+ '@PhpCsFixer:risky' => false,
+ '@Symfony' => true,
+ '@Symfony:risky' => false,
+ 'nullable_type_declaration_for_default_null_value' => false,
+ 'void_return' => true,
+ 'random_api_migration' => true,
+ 'pow_to_exponentiation' => true,
+ 'combine_nested_dirname' => true,
+ 'phpdoc_separation' => false,
+ 'phpdoc_align' => ['align' => 'left'],
+ '@PHP82Migration' => true,
+ 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true],
+ 'modernize_strpos' => true,
+ 'function_declaration' => ['closure_function_spacing' => 'one', 'closure_fn_spacing' => 'one'],
+ 'phpdoc_to_comment' => ['ignored_tags' => ['todo', 'var', 'property']],
+ 'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']],
+ 'array_syntax' => ['syntax' => 'short'],
+ 'cast_spaces' => ['space' => 'none'],
+ 'concat_space' => ['spacing' => 'one'],
+ 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
+ 'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']],
+ ])
+ ->setFinder($finder);
diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
deleted file mode 100644
index be19d30..0000000
--- a/.php-cs-fixer.php
+++ /dev/null
@@ -1,35 +0,0 @@
-in(__DIR__.'/src')
- ->in(__DIR__.'/tests')
-;
-
-$config = new PhpCsFixer\Config();
-
-return $config
- ->setRiskyAllowed(true)
- ->setRules([
- '@PSR2' => true,
- '@PSR1' => true,
- '@PhpCsFixer' => true,
- '@Symfony' => true,
- '@Symfony:risky' => false,
- 'native_function_invocation' => [
- 'include' => [\PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer::SET_INTERNAL],
- 'scope' => 'namespaced',
- 'strict' => false,
- ],
- 'nullable_type_declaration_for_default_null_value' => false,
- 'void_return' => true,
- 'random_api_migration' => true,
- 'pow_to_exponentiation' => true,
- 'combine_nested_dirname' => true,
- 'phpdoc_separation' => false,
- '@PHP74Migration' => true,
- 'global_namespace_import' => [
- 'import_classes' => false,
- ],
- ])
- ->setFinder($finder)
-;
diff --git a/composer.json b/composer.json
index 9d92771..73087a8 100644
--- a/composer.json
+++ b/composer.json
@@ -24,26 +24,31 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.2",
"ext-simplexml": "*",
"ext-dom": "*",
"ext-libxml": "*",
"beberlei/assert": "@stable",
- "jms/serializer": "^3.28.0",
+ "jms/serializer": "^3.30.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
- "psr/event-dispatcher": "^1.0.0",
- "doctrine/annotations": "@stable"
+ "psr/event-dispatcher": "^1.0.0"
},
"suggest": {
"symfony/routing": "If you want to use SelfAwareProfileRequestHandler"
},
"require-dev": {
- "phpunit/phpunit": "^9.6.13",
- "phpstan/phpstan": "^1.10.41",
+ "phpunit/phpunit": "^11",
+ "phpstan/phpstan": "^1.11.0",
"friendsofphp/php-cs-fixer": "*",
"php-parallel-lint/php-parallel-lint": "*",
"enlightn/security-checker": "*",
- "symfony/routing": "^4.4.44 || ^5.0.0 || ^6.0.0"
+ "symfony/routing": "^4.4.44 || ^5.0.0 || ^6.0.0",
+ "rector/rector": "^1.1",
+ "phpstan/extension-installer": "^1.3",
+ "phpstan/phpstan-strict-rules": "^1.6",
+ "phpstan/phpstan-deprecation-rules": "^1.2",
+ "goetas/jms-serializer-phpstan-extension": "^1.0",
+ "tomasvotruba/type-coverage": "^0.3.0"
},
"autoload": {
"psr-4": {
@@ -57,8 +62,16 @@
},
"scripts": {
"test": "vendor/bin/phpunit --testdox tests",
- "sniff": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer check --allow-risky=yes --diff",
- "sniff-fix": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --allow-risky=yes --diff",
- "phpstan": "vendor/bin/phpstan analyze"
+ "cs-check": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer check --diff",
+ "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --diff",
+ "phpstan": "vendor/bin/phpstan analyze",
+ "rector-check": "vendor/bin/rector process --dry-run",
+ "rector": "vendor/bin/rector process",
+ "security-check": "vendor/bin/security-checker security:check composer.lock"
+ },
+ "config": {
+ "allow-plugins": {
+ "phpstan/extension-installer": true
+ }
}
}
diff --git a/phpstan.neon b/phpstan.dist.neon
similarity index 59%
rename from phpstan.neon
rename to phpstan.dist.neon
index f1720bf..094e630 100644
--- a/phpstan.neon
+++ b/phpstan.dist.neon
@@ -1,7 +1,25 @@
parameters:
+ type_coverage:
+ return_type: 100
+ param_type: 98
+ property_type: 100
+ constant_type: 0
+ print_suggestions: true
+ declare: 100
+
+ parallel:
+ # this should be LESS than you total number of cores to prevent clogging your system
+ maximumNumberOfProcesses: 2
+
+ tmpDir: .phpstan
+
level: max
+
paths:
- src/
+ - tests/
+
+ editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
excludePaths:
- %rootDir%/../../../vendor/*
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..df8747c
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+ tests/
+
+
+
+
+
+ src
+
+
+
diff --git a/readme.md b/readme.md
index 5aa59d5..f2f6c2e 100644
--- a/readme.md
+++ b/readme.md
@@ -97,7 +97,7 @@ $documentRegistory->register($cXml);
### Process incoming cXML documents
```php
-$headerProcessor = new \CXml\Processor\HeaderProcessor($credentialRegistry, $credentialRegistry, $credentialRegistry);
+$headerProcessor = new \CXml\Processor\HeaderProcessor($credentialRegistry, $credentialRegistry);
$cXmlProcessor = new \CXml\Processor\Processor(
$headerProcessor,
@@ -119,7 +119,7 @@ $handlerRegistry = new \CXml\Handler\HandlerRegistry();
$builder = \CXml\Builder::create();
-$headerProcessor = new \CXml\Processor\HeaderProcessor($credentialRegistry, $credentialRegistry, $credentialRegistry);
+$headerProcessor = new \CXml\Processor\HeaderProcessor($credentialRegistry, $credentialRegistry);
$cXmlProcessor = new \CXml\Processor\Processor(
$headerProcessor,
$handlerRegistry,
@@ -153,19 +153,19 @@ With some fields the actual time of day is not relevant and could lead to confus
`requestedDeliveryDate` field in `ItemOut`. Real-world experience shows that here it is common to only specify the date.
Althout one could argue that the time of day is still relevant here for real tight on-point deliveries.
-To solve this problem we introduced a determined `CXml\Mode\Date` class in case of using an explicit
+To solve this problem we introduced a determined `CXml\Model\Date` class in case of using an explicit
date (without time). This class extends `DateTime` and is therefore compatible with the rest of the model. The class
enforces a date-only representation (Y-m-d).
#### Serialization
-You should use the `CXml\Mode\Date` class when generating your object-graph in cases you want to output a date-only
+You should use the `CXml\Model\Date` class when generating your object-graph in cases you want to output a date-only
value.
#### Deserialization
-When parsing a date-property from a cXML document, the `CXml\Mode\Date` will be instantiated **if** a date-only
+When parsing a date-property from a cXML document, the `CXml\Model\Date` will be instantiated **if** a date-only
value was discovered (Y-m-d).
# Credits
-- Markus Thielen (https://github.com/mathielen)
\ No newline at end of file
+- Markus Thielen (https://github.com/mathielen)
diff --git a/rector.php b/rector.php
new file mode 100644
index 0000000..669c57e
--- /dev/null
+++ b/rector.php
@@ -0,0 +1,43 @@
+withPaths([
+ __DIR__ . '/src',
+ __DIR__ . '/tests',
+ ])
+ ->withSets([
+ JMSSetList::ANNOTATIONS_TO_ATTRIBUTES,
+ PHPUnitSetList::PHPUNIT_100,
+ PHPUnitSetList::PHPUNIT_CODE_QUALITY,
+ PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
+ SetList::TYPE_DECLARATION,
+ SetList::CODE_QUALITY,
+ SetList::CODING_STYLE,
+ SetList::DEAD_CODE,
+ SetList::PHP_82,
+ SetList::PRIVATIZATION,
+ SetList::EARLY_RETURN,
+ SetList::INSTANCEOF,
+ SetList::STRICT_BOOLEANS,
+ ])
+ ->withFileExtensions(['php'])
+ ->withCache(
+ cacheDirectory: '/tmp/rector',
+ cacheClass: FileCacheStorage::class,
+ )
+ ->withParallel(
+ maxNumberOfProcess: 4,
+ jobSize: 16,
+ )
+ ->withImportNames(
+ importDocBlockNames: false,
+ removeUnusedImports: true,
+ );
diff --git a/src/CXml/Authentication/AuthenticatorInterface.php b/src/CXml/Authentication/AuthenticatorInterface.php
index 52e2759..a374301 100644
--- a/src/CXml/Authentication/AuthenticatorInterface.php
+++ b/src/CXml/Authentication/AuthenticatorInterface.php
@@ -1,5 +1,7 @@
sharedSecret = $sharedSecret;
}
public function authenticate(Header $header, Context $context): void
diff --git a/src/CXml/Builder.php b/src/CXml/Builder.php
index 279f28d..acc6f08 100644
--- a/src/CXml/Builder.php
+++ b/src/CXml/Builder.php
@@ -1,5 +1,7 @@
locale = $locale;
$this->payloadIdentityFactory = $payloadIdentityFactory ?? new DefaultPayloadIdentityFactory();
- $this->senderUserAgent = $senderUserAgent;
}
public static function create(string $senderUserAgent = 'cxml-php UserAgent', string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null): self
@@ -87,19 +90,21 @@ public function to(Credential $to): self
private function buildHeader(): Header
{
if (!isset($this->from)) {
- throw new \LogicException("No 'from' has been set. Necessary for building a header.");
+ throw new LogicException("No 'from' has been set. Necessary for building a header.");
}
+
if (!isset($this->to)) {
- throw new \LogicException("No 'to' has been set. Necessary for building a header.");
+ throw new LogicException("No 'to' has been set. Necessary for building a header.");
}
+
if (!isset($this->sender)) {
- throw new \LogicException("No 'sender' has been set. Necessary for building a header.");
+ throw new LogicException("No 'sender' has been set. Necessary for building a header.");
}
return new Header(
new Party($this->from),
new Party($this->to),
- new Party($this->sender, $this->senderUserAgent)
+ new Party($this->sender, $this->senderUserAgent),
);
}
@@ -115,7 +120,7 @@ public function build(string $deploymentMode = null): CXml
$this->payloadIdentityFactory->newPayloadIdentity(),
new Request($this->payload, $this->status, null, $deploymentMode),
$this->buildHeader(),
- $this->locale
+ $this->locale,
);
break;
@@ -125,7 +130,7 @@ public function build(string $deploymentMode = null): CXml
$this->payloadIdentityFactory->newPayloadIdentity(),
new Message($this->payload, $this->status),
$this->buildHeader(),
- $this->locale
+ $this->locale,
);
break;
@@ -133,7 +138,7 @@ public function build(string $deploymentMode = null): CXml
$status = $this->status;
// response requires a status
- if (null === $status) {
+ if (!$status instanceof Status) {
$status = new Status(); // 200 OK
}
@@ -141,17 +146,17 @@ public function build(string $deploymentMode = null): CXml
$cXml = CXml::forResponse(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Response($status, $this->payload),
- $this->locale
+ $this->locale,
);
break;
default:
// simple status ping-pong response
- if ($this->status) {
+ if ($this->status instanceof Status) {
$cXml = CXml::forResponse(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Response($this->status),
- $this->locale
+ $this->locale,
);
break;
diff --git a/src/CXml/Builder/OrderRequestBuilder.php b/src/CXml/Builder/OrderRequestBuilder.php
index 177c706..096ce55 100644
--- a/src/CXml/Builder/OrderRequestBuilder.php
+++ b/src/CXml/Builder/OrderRequestBuilder.php
@@ -1,5 +1,7 @@
orderId = $orderId;
- $this->orderDate = $orderDate;
- $this->currency = $currency;
- $this->language = $language;
}
- public static function create(string $orderId, \DateTimeInterface $orderDate, string $currency, string $language = 'en'): self
+ public static function create(string $orderId, DateTimeInterface $orderDate, string $currency, string $language = 'en'): self
{
return new self($orderId, $orderDate, $currency, $language);
}
@@ -58,27 +66,29 @@ public static function fromPunchOutOrderMessage(
PunchOutOrderMessage $punchOutOrderMessage,
string $currency = null,
string $orderId = null,
- \DateTimeInterface $orderDate = null,
- string $language = 'en'
+ DateTimeInterface $orderDate = null,
+ string $language = 'en',
): self {
- if ($supplierOrderInfo = $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getSupplierOrderInfo()) {
+ if (($supplierOrderInfo = $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getSupplierOrderInfo()) instanceof SupplierOrderInfo) {
$orderId ??= $supplierOrderInfo->getOrderId();
$orderDate ??= $supplierOrderInfo->getOrderDate();
}
+
$currency ??= $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getTotal()->getMoney()->getCurrency();
if (null === $orderId) {
- throw new \LogicException('orderId should either be given or present in the PunchOutOrderMessage');
+ throw new LogicException('orderId should either be given or present in the PunchOutOrderMessage');
}
- if (null === $orderDate) {
- throw new \LogicException('orderDate should either be given or present in the PunchOutOrderMessage');
+
+ if (!$orderDate instanceof DateTimeInterface) {
+ throw new LogicException('orderDate should either be given or present in the PunchOutOrderMessage');
}
$orb = new self(
$orderId,
$orderDate,
$currency,
- $language
+ $language,
);
$orb->setShipTo($punchOutOrderMessage->getPunchOutOrderMessageHeader()->getShipTo());
@@ -92,7 +102,7 @@ public static function fromPunchOutOrderMessage(
$item->getItemDetail()->getUnitPrice()->getMoney()->getValueCent(),
[
new Classification('custom', '0'), // TODO make this configurable
- ]
+ ],
);
}
@@ -107,7 +117,7 @@ public function billTo(
string $email = null,
Phone $phone = null,
string $fax = null,
- string $url = null
+ string $url = null,
): self {
$this->billTo = new BillTo(
new Address(
@@ -118,8 +128,8 @@ public function billTo(
$email,
$phone,
$fax,
- $url
- )
+ $url,
+ ),
);
return $this;
@@ -129,14 +139,14 @@ public function shipTo(
string $name,
PostalAddress $postalAddress,
array $carrierIdentifiers = [],
- string $carrierAccountNo = null
+ string $carrierAccountNo = null,
): self {
$this->shipTo = new ShipTo(
new Address(
new MultilanguageString($name, null, $this->language),
- $postalAddress
+ $postalAddress,
),
- $carrierAccountNo ? TransportInformation::fromContractAccountNumber($carrierAccountNo) : null
+ null !== $carrierAccountNo && '' !== $carrierAccountNo && '0' !== $carrierAccountNo ? TransportInformation::fromContractAccountNumber($carrierAccountNo) : null,
);
foreach ($carrierIdentifiers as $domain => $identifier) {
@@ -182,11 +192,11 @@ public function addItem(
string $unitOfMeasure,
int $unitPrice,
array $classifications,
- \DateTimeInterface $requestDeliveryDate = null,
- ItemOut $parent = null,
- PriceBasisQuantity $priceBasisQuantity = null
+ ?DateTimeInterface $requestDeliveryDate = null,
+ ?ItemOut $parent = null,
+ ?PriceBasisQuantity $priceBasisQuantity = null,
): ItemOut {
- $lineNumber = \count($this->items) + 1;
+ $lineNumber = count($this->items) + 1;
$item = ItemOut::create(
$lineNumber,
@@ -196,24 +206,24 @@ public function addItem(
new Description(
$description,
null,
- $this->language
+ $this->language,
),
$unitOfMeasure,
new MoneyWrapper(
$this->currency,
- $unitPrice
+ $unitPrice,
),
$classifications,
- $priceBasisQuantity
+ $priceBasisQuantity,
),
$requestDeliveryDate,
- $parent ? $parent->getLineNumber() : null
+ $parent instanceof ItemOut ? $parent->getLineNumber() : null,
);
$this->items[] = $item;
if ($priceBasisQuantity instanceof PriceBasisQuantity && $priceBasisQuantity->getQuantity() > 0) {
- $this->total += (int) \round($quantity * ($priceBasisQuantity->getConversionFactor() / $priceBasisQuantity->getQuantity()) * $unitPrice);
+ $this->total += (int)round($quantity * ($priceBasisQuantity->getConversionFactor() / $priceBasisQuantity->getQuantity()) * $unitPrice);
} else {
$this->total += ($quantity * $unitPrice);
}
@@ -227,7 +237,7 @@ public function addComment(string $value = null, string $type = null, string $la
$value,
$type,
$lang,
- $attachmentUrl
+ $attachmentUrl,
);
return $this;
@@ -237,7 +247,7 @@ public function addContact(string $name, string $email, string $role = Contact::
{
$contact = new Contact(
new MultilanguageString($name, null, $this->language),
- $role
+ $role,
);
$contact->addEmail($email);
@@ -262,15 +272,15 @@ private function buildOrderRequestHeader(): OrderRequestHeader
$this->billTo,
new MoneyWrapper($this->currency, $this->total),
OrderRequestHeader::TYPE_NEW,
- $this->contacts
+ $this->contacts,
)
->setShipping($this->shipping)
- ->setTax($this->tax)
- ;
+ ->setTax($this->tax);
foreach ($this->comments as $comment) {
$orh->addComment($comment);
}
+
foreach ($this->extrinsics as $extrinsic) {
$orh->addExtrinsic($extrinsic);
}
@@ -281,11 +291,11 @@ private function buildOrderRequestHeader(): OrderRequestHeader
public function build(): OrderRequest
{
if (!isset($this->billTo)) {
- throw new \LogicException('BillTo is required');
+ throw new LogicException('BillTo is required');
}
return OrderRequest::create(
- $this->buildOrderRequestHeader()
+ $this->buildOrderRequestHeader(),
)->addItems($this->items);
}
diff --git a/src/CXml/Builder/ProductActivityMessageBuilder.php b/src/CXml/Builder/ProductActivityMessageBuilder.php
index fe56acd..b840669 100644
--- a/src/CXml/Builder/ProductActivityMessageBuilder.php
+++ b/src/CXml/Builder/ProductActivityMessageBuilder.php
@@ -1,5 +1,7 @@
productActivityMessage = ProductActivityMessage::create(
$messageId,
);
-
- $this->warehouseCodeDomain = $warehouseCodeDomain;
}
public static function create(string $messageId, string $warehouseCodeDomain): self
@@ -32,17 +32,16 @@ public static function create(string $messageId, string $warehouseCodeDomain): s
public function addProductActivityDetail(string $sku, string $warehouseCode, int $stockLevel, array $extrinsics = null): self
{
$inventory = Inventory::create()
- ->setStockOnHandQuantity(new InventoryQuantity($stockLevel, 'EA'))
- ;
+ ->setStockOnHandQuantity(new InventoryQuantity($stockLevel, 'EA'));
$activityDetail = ProductActivityDetail::create(
new ItemId($sku, null, $sku),
$inventory,
Contact::create(new MultilanguageString($warehouseCode, null, 'en'), 'locationFrom')
- ->addIdReference($this->warehouseCodeDomain, $warehouseCode)
+ ->addIdReference($this->warehouseCodeDomain, $warehouseCode),
);
- if ($extrinsics) {
+ if (null !== $extrinsics && [] !== $extrinsics) {
foreach ($extrinsics as $k => $v) {
$activityDetail->addExtrinsicAsKeyValue($k, $v);
}
@@ -55,8 +54,8 @@ public function addProductActivityDetail(string $sku, string $warehouseCode, int
public function build(): ProductActivityMessage
{
- if (empty($this->productActivityMessage->getProductActivityDetails())) {
- throw new \RuntimeException('Cannot build ProductActivityMessage without any ProductActivityDetail');
+ if ([] === $this->productActivityMessage->getProductActivityDetails()) {
+ throw new RuntimeException('Cannot build ProductActivityMessage without any ProductActivityDetail');
}
return $this->productActivityMessage;
diff --git a/src/CXml/Builder/PunchOutOrderMessageBuilder.php b/src/CXml/Builder/PunchOutOrderMessageBuilder.php
index 9febe63..33ac62f 100644
--- a/src/CXml/Builder/PunchOutOrderMessageBuilder.php
+++ b/src/CXml/Builder/PunchOutOrderMessageBuilder.php
@@ -1,5 +1,7 @@
buyerCookie = $buyerCookie;
- $this->currency = $currency;
- $this->operationAllowed = $operationAllowed;
- $this->language = $language;
}
public static function create(string $language, string $buyerCookie, string $currency, string $operationAllowed = null): self
@@ -49,7 +52,7 @@ public static function create(string $language, string $buyerCookie, string $cur
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;
@@ -61,14 +64,14 @@ public function shipTo(
string $name,
PostalAddress $postalAddress,
array $carrierIdentifiers = [],
- string $carrierAccountNo = null
+ string $carrierAccountNo = null,
): self {
$this->shipTo = new ShipTo(
new Address(
new MultilanguageString($name, null, $this->language),
- $postalAddress
+ $postalAddress,
),
- $carrierAccountNo ? TransportInformation::fromContractAccountNumber($carrierAccountNo) : null
+ null !== $carrierAccountNo && '' !== $carrierAccountNo && '0' !== $carrierAccountNo ? TransportInformation::fromContractAccountNumber($carrierAccountNo) : null,
);
foreach ($carrierIdentifiers as $domain => $identifier) {
@@ -86,8 +89,8 @@ public function shipping(int $shipping, string $taxDescription): self
new Description(
$taxDescription,
null,
- $this->language
- )
+ $this->language,
+ ),
);
return $this;
@@ -101,8 +104,8 @@ public function tax(int $tax, string $taxDescription): self
new Description(
$taxDescription,
null,
- $this->language
- )
+ $this->language,
+ ),
);
return $this;
@@ -118,27 +121,26 @@ public function addPunchoutOrderMessageItem(
string $manufacturerPartId = null,
string $manufacturerName = null,
int $leadTime = null,
- array $extrinsics = null
+ array $extrinsics = null,
): self {
$itemDetail = ItemDetail::create(
new Description(
$description,
null,
- $this->language
+ $this->language,
),
$unitOfMeasure,
new MoneyWrapper(
$this->currency,
- $unitPrice
+ $unitPrice,
),
- $classifications
+ $classifications,
)
->setManufacturerPartId($manufacturerPartId)
->setManufacturerName($manufacturerName)
- ->setLeadtime($leadTime)
- ;
+ ->setLeadtime($leadTime);
- if ($extrinsics) {
+ if (null !== $extrinsics && [] !== $extrinsics) {
foreach ($extrinsics as $k => $v) {
$itemDetail->addExtrinsicAsKeyValue($k, $v);
}
@@ -147,7 +149,7 @@ public function addPunchoutOrderMessageItem(
$punchoutOrderMessageItem = ItemIn::create(
$quantity,
$itemId,
- $itemDetail
+ $itemDetail,
);
return $this->addItem($punchoutOrderMessageItem);
@@ -165,7 +167,7 @@ public function addItem(ItemIn $itemIn): self
&& $itemIn->getItemDetail()->getPriceBasisQuantity()->getQuantity() > 0
) {
$priceBasisQuantity = $itemIn->getItemDetail()->getPriceBasisQuantity();
- $this->total += (int) \round($itemQty * ($priceBasisQuantity->getConversionFactor() / $priceBasisQuantity->getQuantity()) * $moneyValueCent);
+ $this->total += (int)round($itemQty * ($priceBasisQuantity->getConversionFactor() / $priceBasisQuantity->getQuantity()) * $moneyValueCent);
} else {
$this->total += $moneyValueCent * $itemQty;
}
@@ -175,18 +177,18 @@ public function addItem(ItemIn $itemIn): self
public function build(): PunchOutOrderMessage
{
- if (empty($this->punchoutOrderMessageItems)) {
- throw new \RuntimeException('Cannot build PunchOutOrderMessage without any PunchoutOrderMessageItem');
+ if ([] === $this->punchoutOrderMessageItems) {
+ throw new RuntimeException('Cannot build PunchOutOrderMessage without any PunchoutOrderMessageItem');
}
$punchoutOrderMessageHeader = new PunchOutOrderMessageHeader(
new MoneyWrapper($this->currency, $this->total),
$this->shipping,
$this->tax,
- $this->operationAllowed
+ $this->operationAllowed,
);
- if (isset($this->shipTo)) {
+ if ($this->shipTo instanceof ShipTo) {
$punchoutOrderMessageHeader->setShipTo($this->shipTo);
}
@@ -196,7 +198,7 @@ public function build(): PunchOutOrderMessage
$punchOutOrderMessage = PunchOutOrderMessage::create(
$this->buyerCookie,
- $punchoutOrderMessageHeader
+ $punchoutOrderMessageHeader,
);
foreach ($this->punchoutOrderMessageItems as $punchoutOrderMessageItem) {
diff --git a/src/CXml/Context.php b/src/CXml/Context.php
index 8aa072f..1ab1803 100644
--- a/src/CXml/Context.php
+++ b/src/CXml/Context.php
@@ -1,17 +1,18 @@
options = $options;
}
public static function create(array $options = []): self
@@ -19,7 +20,7 @@ public static function create(array $options = []): self
return new self($options);
}
- public function getOption(string $key)/* : mixed */
+ public function getOption(string $key): mixed
{
return $this->options[$key] ?? null;
}
@@ -55,13 +56,13 @@ public function setCXml(CXml $cxml): self
public function getSenderUserAgent(): ?string
{
- $cxml = $this->getCxml();
- if (!$cxml) {
+ $cxml = $this->getCXml();
+ if (!$cxml instanceof CXml) {
return null;
}
$header = $cxml->getHeader();
- if (!$header) {
+ if (!$header instanceof Header) {
return null;
}
@@ -70,8 +71,8 @@ public function getSenderUserAgent(): ?string
public function getPayloadId(): ?string
{
- $cxml = $this->getCxml();
- if (!$cxml) {
+ $cxml = $this->getCXml();
+ if (!$cxml instanceof CXml) {
return null;
}
diff --git a/src/CXml/Credential/CredentialRepositoryInterface.php b/src/CXml/Credential/CredentialRepositoryInterface.php
index 1897445..7480472 100644
--- a/src/CXml/Credential/CredentialRepositoryInterface.php
+++ b/src/CXml/Credential/CredentialRepositoryInterface.php
@@ -1,5 +1,7 @@
registeredCredentials as $registeredCredential) {
- if ($registeredCredential->getDomain() === $domain && $registeredCredential->getIdentity() === $identity) {
- return $registeredCredential;
+ if ($registeredCredential->getDomain() !== $domain) {
+ continue;
}
+
+ if ($registeredCredential->getIdentity() !== $identity) {
+ continue;
+ }
+
+ return $registeredCredential;
}
- throw new CXmlCredentialInvalidException("Could not find credentials for '{$identity}@{$domain}'.");
+ throw new CXmlCredentialInvalidException(sprintf("Could not find credentials for '%s@%s'.", $identity, $domain));
}
/**
@@ -61,7 +71,7 @@ public function validate(Credential $credential): void
// provoke an exception if credential was not found
$this->getCredentialByDomainAndId(
$credential->getDomain(),
- $credential->getIdentity()
+ $credential->getIdentity(),
);
}
}
diff --git a/src/CXml/Document/DocumentRegistryInterface.php b/src/CXml/Document/DocumentRegistryInterface.php
index ea0a0fe..aa0e24f 100644
--- a/src/CXml/Document/DocumentRegistryInterface.php
+++ b/src/CXml/Document/DocumentRegistryInterface.php
@@ -1,5 +1,7 @@
serializer = $serializer;
- $this->dtdValidator = $messageValidator;
- $this->processor = $processor;
$this->logger = $logger ?? new NullLogger();
}
@@ -40,28 +37,28 @@ public function parseAndProcessStringAsCXml(string $xml, Context $context = null
// validate
try {
$this->dtdValidator->validateAgainstDtd($xml);
- } catch (CXmlInvalidException $e) {
+ } catch (CXmlInvalidException $cXmlInvalidException) {
$this->logger->error('Incoming CXml was invalid (via DTD)', ['xml' => $xml]);
- throw $e;
+ throw $cXmlInvalidException;
}
// deserialize
try {
$cxml = $this->serializer->deserialize($xml);
- } catch (\RuntimeException $e) {
- $this->logger->error('Error while deserializing xml to CXml: '.$e->getMessage(), ['xml' => $xml]);
+ } catch (RuntimeException $runtimeException) {
+ $this->logger->error('Error while deserializing xml to CXml: ' . $runtimeException->getMessage(), ['xml' => $xml]);
- throw new CXmlInvalidException('Error while deserializing xml: '.$e->getMessage(), $xml, $e);
+ throw new CXmlInvalidException('Error while deserializing xml: ' . $runtimeException->getMessage(), $xml, $runtimeException);
}
// process
try {
$result = $this->processor->process($cxml, $context);
- } catch (CXmlException $e) {
- $this->logger->error('Error while processing valid CXml: '.$e->getMessage(), ['xml' => $xml]);
+ } catch (CXmlException $cXmlException) {
+ $this->logger->error('Error while processing valid CXml: ' . $cXmlException->getMessage(), ['xml' => $xml]);
- throw $e;
+ throw $cXmlException;
}
$this->logger->info('Success after processing incoming CXml message', ['xml' => $xml]);
diff --git a/src/CXml/Exception/CXmlAuthenticationInvalidException.php b/src/CXml/Exception/CXmlAuthenticationInvalidException.php
index e812f5e..22c2bd8 100644
--- a/src/CXml/Exception/CXmlAuthenticationInvalidException.php
+++ b/src/CXml/Exception/CXmlAuthenticationInvalidException.php
@@ -1,5 +1,7 @@
credential = $credential;
+ parent::__construct($message . ($credential instanceof Credential ? "\nCredential was:" . $credential : ''), $previous);
}
public function getCredential(): ?Credential
diff --git a/src/CXml/Exception/CXmlException.php b/src/CXml/Exception/CXmlException.php
index 00e1c24..5ecdc63 100644
--- a/src/CXml/Exception/CXmlException.php
+++ b/src/CXml/Exception/CXmlException.php
@@ -1,10 +1,15 @@
registry, $handlerId, "Handler for '{$handlerId}' already registered.");
+ Assertion::keyNotExists($this->registry, $handlerId, sprintf("Handler for '%s' already registered.", $handlerId));
$this->registry[$handlerId] = $handler;
}
diff --git a/src/CXml/Handler/HandlerRegistryInterface.php b/src/CXml/Handler/HandlerRegistryInterface.php
index ab3eaae..4cea577 100644
--- a/src/CXml/Handler/HandlerRegistryInterface.php
+++ b/src/CXml/Handler/HandlerRegistryInterface.php
@@ -1,5 +1,7 @@
handlerRegistry = $handlerRegistry;
- $this->urlGenerator = $urlGenerator;
- $this->defaultRoute = $defaultRoute;
}
public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface
{
$profileResponse = new ProfileResponse();
- foreach ($this->handlerRegistry->all() as $requestName => $handler) {
+ foreach (array_keys($this->handlerRegistry->all()) as $requestName) {
$transaction = new Transaction($requestName, $this->getEndpointUrl());
$profileResponse->addTransaction($transaction);
diff --git a/src/CXml/Handler/Request/StaticStartPagePunchOutSetupRequestHandler.php b/src/CXml/Handler/Request/StaticStartPagePunchOutSetupRequestHandler.php
index 4b73b21..c84b75d 100644
--- a/src/CXml/Handler/Request/StaticStartPagePunchOutSetupRequestHandler.php
+++ b/src/CXml/Handler/Request/StaticStartPagePunchOutSetupRequestHandler.php
@@ -1,5 +1,7 @@
startPageUrl = $startPageUrl;
}
public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface
{
return new PunchOutSetupResponse(
new Url(
- $this->startPageUrl
- )
+ $this->startPageUrl,
+ ),
);
}
diff --git a/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php b/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php
index ca544cd..e2e5418 100644
--- a/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php
+++ b/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php
@@ -1,5 +1,7 @@
children() as $child) {
if ('Status' === $child->getName()) {
@@ -78,7 +85,7 @@ private static function findPayloadNode(\SimpleXMLElement $cXmlNode): ?\SimpleXM
}
/**
- * @throws \ReflectionException
+ * @throws ReflectionException
*/
public function onPostSerializePayload(ObjectEvent $event): void
{
@@ -86,41 +93,41 @@ public function onPostSerializePayload(ObjectEvent $event): void
$visitor = $event->getVisitor();
// this is the actual payload object of type MessagePayloadInterface
- /* @phpstan-ignore-next-line */
+ /** @phpstan-ignore-next-line */
$payload = $event->getObject()->getPayload();
if ($payload) {
- $cls = (new \ReflectionClass($payload))->getShortName();
+ $cls = (new ReflectionClass($payload))->getShortName();
// tell jms to add the payload value in a wrapped node
$visitor->visitProperty(
new StaticPropertyMetadata($event->getType()['name'], $cls, null),
- $payload
+ $payload,
);
}
}
/**
* @throws CXmlModelNotFoundException
- * @throws \ReflectionException
+ * @throws ReflectionException
*/
public function onPreDeserializePayload(PreDeserializeEvent $event): void
{
/** @var ClassMetadata $metadata */
$metadata = $event->getContext()->getMetadataFactory()->getMetadataForClass($event->getType()['name']);
- /** @var \SimpleXMLElement $data */
+ /** @var SimpleXMLElement $data */
$data = $event->getData();
- $payloadNode = self::findPayloadNode($data);
- if (null === $payloadNode) {
+ $payloadNode = $this->findPayloadNode($data);
+ if (!$payloadNode instanceof SimpleXMLElement) {
return;
}
$serializedName = $payloadNode->getName();
- $targetNamespace = (new \ReflectionClass($event->getType()['name']))->getNamespaceName();
+ $targetNamespace = (new ReflectionClass($event->getType()['name']))->getNamespaceName();
- $cls = $targetNamespace.'\\'.$serializedName;
- if (!\class_exists($cls)) {
+ $cls = $targetNamespace . '\\' . $serializedName;
+ if (!class_exists($cls)) {
throw new CXmlModelNotFoundException($serializedName);
}
@@ -128,7 +135,7 @@ public function onPreDeserializePayload(PreDeserializeEvent $event): void
$propertyMetadata = new PropertyMetadata(
$event->getType()['name'],
- 'payload'
+ 'payload',
);
$propertyMetadata->serializedName = $serializedName;
diff --git a/src/CXml/Jms/JmsDateTimeHandler.php b/src/CXml/Jms/JmsDateTimeHandler.php
index ac67ecf..c117249 100644
--- a/src/CXml/Jms/JmsDateTimeHandler.php
+++ b/src/CXml/Jms/JmsDateTimeHandler.php
@@ -1,11 +1,18 @@
getFormat($type);
- }
+ $format = $date instanceof Date ? 'Y-m-d' : $this->getFormat($type);
return $visitor->visitSimpleString($date->format($format), $type);
}
private function getFormat(array $type): string
{
- return $type['params'][0] ?? \DateTimeInterface::ATOM;
+ return $type['params'][0] ?? DateTimeInterface::ATOM;
}
- public function deserialize(XmlDeserializationVisitor $visitor, $dateAsString, array $type, Context $context)
+ public function deserialize(XmlDeserializationVisitor $visitor, SimpleXMLElement $dateAsString, array $type, Context $context): DateTime|false
{
// explicit date-format was defined in property annotation
if (isset($type['params'][0])) {
- return \DateTime::createFromFormat($type['params'][0], $dateAsString);
+ return DateTime::createFromFormat($type['params'][0], $dateAsString->__toString());
}
// else try ISO-8601
- $dateTime = \DateTime::createFromFormat(\DateTimeInterface::ATOM, $dateAsString);
- if ($dateTime) {
+ $dateTime = DateTime::createFromFormat(DateTimeInterface::ATOM, $dateAsString->__toString());
+ if ($dateTime instanceof DateTimeInterface) {
return $dateTime;
}
// else try milliseconds-format
- $dateTime = \DateTime::createFromFormat('Y-m-d\TH:i:s.vP', $dateAsString);
- if ($dateTime) {
+ $dateTime = DateTime::createFromFormat('Y-m-d\TH:i:s.vP', $dateAsString->__toString());
+ if ($dateTime instanceof DateTimeInterface) {
return $dateTime;
}
// else try simple date-format
- $dateTime = Date::createFromFormat('Y-m-d', $dateAsString);
- if ($dateTime) {
+ $dateTime = Date::createFromFormat('Y-m-d', $dateAsString->__toString());
+ if ($dateTime instanceof DateTimeInterface) {
return $dateTime;
}
// last resort: throw exception
- throw new \RuntimeException('Could not parse date: '.$dateAsString);
+ throw new RuntimeException('Could not parse date: ' . $dateAsString->__toString());
}
}
diff --git a/src/CXml/Model/Address.php b/src/CXml/Model/Address.php
index 142c270..d431c61 100644
--- a/src/CXml/Model/Address.php
+++ b/src/CXml/Model/Address.php
@@ -1,68 +1,39 @@
addressId = $addressId;
- $this->addressIdDomain = $addressIdDomain;
- $this->name = $name;
- $this->postalAddress = $postalAddress;
- $this->email = $email;
- $this->phone = $phone;
- $this->fax = $fax;
- $this->url = $url;
+ public function __construct(
+ #[Serializer\SerializedName('Name')]
+ #[Serializer\XmlElement(cdata: false)]
+ private MultilanguageString $name,
+ #[Serializer\SerializedName('PostalAddress')]
+ private ?PostalAddress $postalAddress = null,
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('addressID')]
+ private ?string $addressId = null,
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('addressIDDomain')]
+ private ?string $addressIdDomain = null,
+ #[Serializer\SerializedName('Email')]
+ #[Serializer\XmlElement(cdata: false)]
+ private ?string $email = null,
+ #[Serializer\SerializedName('Phone')]
+ #[Serializer\XmlElement(cdata: false)]
+ private ?Phone $phone = null,
+ #[Serializer\SerializedName('Fax')]
+ #[Serializer\XmlElement(cdata: false)]
+ private ?string $fax = null,
+ #[Serializer\SerializedName('URL')]
+ #[Serializer\XmlElement(cdata: false)]
+ private ?string $url = null,
+ ) {
}
public function getAddressId(): ?string
diff --git a/src/CXml/Model/BillTo.php b/src/CXml/Model/BillTo.php
index 627f54c..0aad89f 100644
--- a/src/CXml/Model/BillTo.php
+++ b/src/CXml/Model/BillTo.php
@@ -1,21 +1,20 @@
address = $address;
+ public function __construct(
+ #[Serializer\SerializedName('Address')]
+ private readonly Address $address,
+ ) {
}
public function getAddress(): Address
diff --git a/src/CXml/Model/CXml.php b/src/CXml/Model/CXml.php
index 324e91c..316c78e 100644
--- a/src/CXml/Model/CXml.php
+++ b/src/CXml/Model/CXml.php
@@ -1,72 +1,42 @@
request = $request;
- $this->response = $response;
- $this->header = $header;
- $this->payloadId = $payloadId;
- $this->timestamp = $timestamp;
- $this->message = $message;
- $this->lang = $lang;
}
public static function forMessage(PayloadIdentity $payloadIdentity, Message $message, Header $header, string $lang = null): self
@@ -89,7 +59,7 @@ public function getPayloadId(): string
return $this->payloadId;
}
- public function getTimestamp(): \DateTimeInterface
+ public function getTimestamp(): DateTimeInterface
{
return $this->timestamp;
}
@@ -119,28 +89,30 @@ public function __toString(): string
$wrapper = $this->message ?? $this->request ?? $this->response;
$shortName = 'undefined';
- if ($wrapper) {
+ if (null !== $wrapper) {
$payload = $wrapper->getPayload();
- if ($payload) {
- $shortName = (new \ReflectionClass($payload))->getShortName();
+ if (null !== $payload) {
+ $shortName = (new ReflectionClass($payload))->getShortName();
} else {
- $shortName = (new \ReflectionClass($wrapper))->getShortName();
+ $shortName = (new ReflectionClass($wrapper))->getShortName();
}
}
- return $shortName.'_'.$this->payloadId;
+ return $shortName . '_' . $this->payloadId;
}
public function getStatus(): ?Status
{
- if ($this->request) {
+ if ($this->request instanceof Request) {
return $this->request->getStatus();
}
- if ($this->message) {
+
+ if ($this->message instanceof Message) {
return $this->message->getStatus();
}
- if ($this->response) {
+
+ if ($this->response instanceof Response) {
return $this->response->getStatus();
}
diff --git a/src/CXml/Model/CarrierIdentifier.php b/src/CXml/Model/CarrierIdentifier.php
index 6ff9232..a7fad35 100644
--- a/src/CXml/Model/CarrierIdentifier.php
+++ b/src/CXml/Model/CarrierIdentifier.php
@@ -1,30 +1,28 @@
domain = $domain;
- $this->value = $value;
+ final public const DOMAIN_SCAC = 'SCAC';
+
+ final public const DOMAIN_COMPANYNAME = 'companyName';
+
+ final public const DOMAIN_SKU = 'sku';
+
+ final public const DOMAIN_CARRIER_METHOD = 'carrierMethod';
+
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ private readonly string $domain,
+ #[Serializer\XmlValue(cdata: false)]
+ private readonly string $value,
+ ) {
}
public static function fromScacCode(string $scacCarrierCode): self
diff --git a/src/CXml/Model/Classification.php b/src/CXml/Model/Classification.php
index b6c796a..8441a8c 100644
--- a/src/CXml/Model/Classification.php
+++ b/src/CXml/Model/Classification.php
@@ -1,25 +1,20 @@
domain = $domain;
- $this->value = $value;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ private string $domain,
+ #[Serializer\XmlValue(cdata: false)]
+ private string $value,
+ ) {
}
public function getDomain(): string
diff --git a/src/CXml/Model/Comment.php b/src/CXml/Model/Comment.php
index 6e5daf1..6166a74 100644
--- a/src/CXml/Model/Comment.php
+++ b/src/CXml/Model/Comment.php
@@ -1,37 +1,27 @@
value = $value;
- $this->type = $type;
- $this->lang = $lang;
- $this->attachment = $attachment ? new Url($attachment) : null;
+ #[Serializer\SerializedName('Attachment')]
+ private ?Url $attachment;
+
+ public function __construct(
+ #[Serializer\XmlValue(cdata: false)]
+ private ?string $value = null,
+ #[Serializer\XmlAttribute]
+ private ?string $type = null,
+ #[Serializer\XmlAttribute(namespace: 'http://www.w3.org/XML/1998/namespace')]
+ private ?string $lang = null,
+ string $attachment = null,
+ ) {
+ $this->attachment = null !== $attachment && '' !== $attachment && '0' !== $attachment ? new Url($attachment) : null;
}
public function getAttachment(): ?Url
diff --git a/src/CXml/Model/CommentsTrait.php b/src/CXml/Model/CommentsTrait.php
index 52d1a7d..93eace4 100644
--- a/src/CXml/Model/CommentsTrait.php
+++ b/src/CXml/Model/CommentsTrait.php
@@ -1,17 +1,21 @@
")
- *
* @var Comment[]
*/
+ #[Serializer\XmlList(entry: 'Comments', inline: true)]
+ #[Serializer\Type('array')]
private ?array $comments = null;
public function addCommentAsString(string $comment, string $type = null, string $lang = null): self
@@ -43,12 +47,13 @@ public function getCommentsAsString(): ?string
{
$commentStrings = [];
- if ($comments = $this->getComments()) {
+ $comments = $this->getComments();
+ if (is_array($comments)) {
foreach ($comments as $comment) {
$commentStrings[] = $comment->getValue();
}
}
- return empty($commentStrings) ? null : \implode("\n", $commentStrings);
+ return [] === $commentStrings ? null : implode("\n", $commentStrings);
}
}
diff --git a/src/CXml/Model/Contact.php b/src/CXml/Model/Contact.php
index 2df171d..76f0ee1 100644
--- a/src/CXml/Model/Contact.php
+++ b/src/CXml/Model/Contact.php
@@ -1,50 +1,56 @@
role = $role;
- $this->name = $name;
+ public function __construct(
+ #[Serializer\SerializedName('Name')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly MultilanguageString $name,
+ #[Serializer\XmlAttribute]
+ private readonly ?string $role = null,
+ ) {
}
public static function create(MultilanguageString $name, string $role = null): self
diff --git a/src/CXml/Model/Country.php b/src/CXml/Model/Country.php
index 692b20a..52e7c05 100644
--- a/src/CXml/Model/Country.php
+++ b/src/CXml/Model/Country.php
@@ -1,26 +1,21 @@
isoCountryCode = $isoCountryCode;
- $this->name = $name;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('isoCountryCode')]
+ private string $isoCountryCode,
+ #[Serializer\XmlValue(cdata: false)]
+ private ?string $name = null,
+ ) {
}
public function getIsoCountryCode(): string
diff --git a/src/CXml/Model/CountryCode.php b/src/CXml/Model/CountryCode.php
index 662ea8a..42ed7fb 100644
--- a/src/CXml/Model/CountryCode.php
+++ b/src/CXml/Model/CountryCode.php
@@ -1,26 +1,21 @@
isoCountryCode = $isoCountryCode;
- $this->name = $name;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('isoCountryCode')]
+ private string $isoCountryCode,
+ #[Serializer\XmlValue(cdata: false)]
+ private ?string $name = null,
+ ) {
}
public function getIsoCountryCode(): string
diff --git a/src/CXml/Model/Credential.php b/src/CXml/Model/Credential.php
index 8b20e2d..aa79259 100644
--- a/src/CXml/Model/Credential.php
+++ b/src/CXml/Model/Credential.php
@@ -1,39 +1,27 @@
domain = $domain;
- $this->identity = $identity;
- $this->sharedSecret = $sharedSecret;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ private readonly string $domain,
+ #[Serializer\SerializedName('Identity')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly string $identity,
+ #[Serializer\SerializedName('SharedSecret')]
+ #[Serializer\XmlElement(cdata: false)]
+ private ?string $sharedSecret = null,
+ ) {
}
public function getDomain(): string
@@ -58,6 +46,6 @@ public function setSharedSecret(?string $sharedSecret): void
public function __toString(): string
{
- return \sprintf('%s@%s', $this->identity, $this->domain);
+ return sprintf('%s@%s', $this->identity, $this->domain);
}
}
diff --git a/src/CXml/Model/Date.php b/src/CXml/Model/Date.php
index 102c998..3b06cfe 100644
--- a/src/CXml/Model/Date.php
+++ b/src/CXml/Model/Date.php
@@ -1,44 +1,24 @@
format('Y-m-d'), $timezone);
- }
+use DateTime;
+use DateTimeZone;
- public static function createFromInterface(\DateTimeInterface $object): \DateTime
- {
- return new self($object->format('Y-m-d'), $object->getTimezone());
- }
- }
-} else {
- /**
- * Represents a date *without* time. This is a separate class to allow for different serialization formats.
- */
- class Date extends \DateTime
+/**
+ * Represents a date *without* time. This is a separate class to allow for different serialization formats.
+ */
+class Date extends DateTime
+{
+ public static function createFromFormat($format, $datetime, DateTimeZone $timezone = null): DateTime|false|Date
{
- #[\ReturnTypeWillChange]
- public static function createFromFormat($format, $datetime, \DateTimeZone $timezone = null)
- {
- $dateTime = parent::createFromFormat($format, $datetime, $timezone);
- if (!$dateTime) {
- return false;
- }
-
- return new self($dateTime->format('Y-m-d'), $timezone);
+ $dateTime = parent::createFromFormat($format, $datetime, $timezone);
+ if (false === $dateTime) {
+ return false;
}
+
+ return new self($dateTime->format('Y-m-d'), $timezone);
}
}
diff --git a/src/CXml/Model/Description.php b/src/CXml/Model/Description.php
index 147d5a6..1e168b0 100644
--- a/src/CXml/Model/Description.php
+++ b/src/CXml/Model/Description.php
@@ -1,15 +1,16 @@
payloadId = $payloadId;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('payloadID')]
+ private string $payloadId,
+ ) {
}
public function getPayloadId(): string
diff --git a/src/CXml/Model/Exception/CXmlModelNotFoundException.php b/src/CXml/Model/Exception/CXmlModelNotFoundException.php
index 58cd0c5..edbca97 100644
--- a/src/CXml/Model/Exception/CXmlModelNotFoundException.php
+++ b/src/CXml/Model/Exception/CXmlModelNotFoundException.php
@@ -1,5 +1,7 @@
name = $name;
- $this->value = $value;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ private string $name,
+ #[Serializer\XmlValue(cdata: false)]
+ private string $value,
+ ) {
}
public function getName(): string
diff --git a/src/CXml/Model/ExtrinsicsTrait.php b/src/CXml/Model/ExtrinsicsTrait.php
index 16a2322..7465d8a 100644
--- a/src/CXml/Model/ExtrinsicsTrait.php
+++ b/src/CXml/Model/ExtrinsicsTrait.php
@@ -1,17 +1,20 @@
")
- *
* @var Extrinsic[]
*/
+ #[Serializer\XmlList(entry: 'Extrinsic', inline: true)]
+ #[Serializer\Type('array')]
protected array $extrinsics = [];
public function addExtrinsic(Extrinsic $extrinsic): self
@@ -56,7 +59,7 @@ public function getExtrinsicsAsKeyValue(): array
$extrinsics = [];
foreach ($this->getExtrinsics() as $extrinsic) {
- $extrinsics[\trim($extrinsic->getName())] = \trim($extrinsic->getValue());
+ $extrinsics[trim($extrinsic->getName())] = trim($extrinsic->getValue());
}
return $extrinsics;
diff --git a/src/CXml/Model/Header.php b/src/CXml/Model/Header.php
index 2865371..36256c1 100644
--- a/src/CXml/Model/Header.php
+++ b/src/CXml/Model/Header.php
@@ -1,31 +1,22 @@
from = $from;
- $this->to = $to;
- $this->sender = $sender;
+ public function __construct(
+ #[Serializer\SerializedName('From')]
+ private Party $from,
+ #[Serializer\SerializedName('To')]
+ private Party $to,
+ #[Serializer\SerializedName('Sender')]
+ private Party $sender,
+ ) {
}
public function getFrom(): Party
diff --git a/src/CXml/Model/IdReference.php b/src/CXml/Model/IdReference.php
index f8c83e3..59ec089 100644
--- a/src/CXml/Model/IdReference.php
+++ b/src/CXml/Model/IdReference.php
@@ -1,25 +1,19 @@
domain = $domain;
- $this->identifier = $identifier;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ private string $domain,
+ #[Serializer\XmlAttribute]
+ private string $identifier,
+ ) {
}
public function getDomain(): string
diff --git a/src/CXml/Model/IdReferencesTrait.php b/src/CXml/Model/IdReferencesTrait.php
index 8fbbf64..186d79c 100644
--- a/src/CXml/Model/IdReferencesTrait.php
+++ b/src/CXml/Model/IdReferencesTrait.php
@@ -1,17 +1,18 @@
")
- *
* @var IdReference[]
*/
+ #[Serializer\XmlList(entry: 'IdReference', inline: true)]
+ #[Serializer\Type('array')]
protected array $idReferences = [];
public function addIdReference(string $domain, string $identifier): self
diff --git a/src/CXml/Model/Inventory.php b/src/CXml/Model/Inventory.php
index db45ec3..6bd97e1 100644
--- a/src/CXml/Model/Inventory.php
+++ b/src/CXml/Model/Inventory.php
@@ -1,19 +1,18 @@
quantity = $quantity;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ private int $quantity,
+ string $unitOfMeasure,
+ ) {
$this->unitOfMeasure = new UnitOfMeasure($unitOfMeasure);
}
diff --git a/src/CXml/Model/ItemDetail.php b/src/CXml/Model/ItemDetail.php
index cab4779..71eb5fb 100644
--- a/src/CXml/Model/ItemDetail.php
+++ b/src/CXml/Model/ItemDetail.php
@@ -1,76 +1,55 @@
")
- *
* @var Classification[]
*/
+ #[Serializer\XmlList(entry: 'Classification', inline: true)]
+ #[Serializer\Type('array')]
private array $classifications = [];
- /**
- * @Ser\SerializedName("ManufacturerPartID")
- * @Ser\XmlElement (cdata=false)
- */
+ #[Serializer\SerializedName('ManufacturerPartID')]
+ #[Serializer\XmlElement(cdata: false)]
private ?string $manufacturerPartId = null;
- /**
- * @Ser\SerializedName("ManufacturerName")
- * @Ser\XmlElement (cdata=false)
- */
+ #[Serializer\SerializedName('ManufacturerName')]
+ #[Serializer\XmlElement(cdata: false)]
private ?string $manufacturerName = null;
- /**
- * @Ser\SerializedName("URL")
- * @Ser\XmlElement (cdata=false)
- */
+ #[Serializer\SerializedName('URL')]
+ #[Serializer\XmlElement(cdata: false)]
private ?string $url = null;
- /**
- * @Ser\SerializedName("LeadTime")
- * @Ser\XmlElement (cdata=false)
- */
+ #[Serializer\SerializedName('LeadTime')]
+ #[Serializer\XmlElement(cdata: false)]
private ?int $leadtime = null;
- protected function __construct(Description $description, string $unitOfMeasure, MoneyWrapper $unitPrice, ?PriceBasisQuantity $priceBasisQuantity = null)
- {
- $this->description = $description;
- $this->unitOfMeasure = $unitOfMeasure;
- $this->unitPrice = $unitPrice;
- $this->priceBasisQuantity = $priceBasisQuantity;
+ protected function __construct(
+ #[Serializer\SerializedName('Description')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly Description $description,
+ #[Serializer\SerializedName('UnitOfMeasure')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly string $unitOfMeasure,
+ #[Serializer\SerializedName('UnitPrice')]
+ private readonly MoneyWrapper $unitPrice,
+ #[Serializer\SerializedName('PriceBasisQuantity')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly ?PriceBasisQuantity $priceBasisQuantity,
+ ) {
}
public static function create(Description $description, string $unitOfMeasure, MoneyWrapper $unitPrice, array $classifications, ?PriceBasisQuantity $priceBasisQuantity = null): self
diff --git a/src/CXml/Model/ItemId.php b/src/CXml/Model/ItemId.php
index af3cc17..e4015a6 100644
--- a/src/CXml/Model/ItemId.php
+++ b/src/CXml/Model/ItemId.php
@@ -1,36 +1,27 @@
supplierPartId = $supplierPartId;
- $this->supplierPartAuxiliaryId = $supplierPartAuxiliaryId;
- $this->buyerPartId = $buyerPartId;
+ public function __construct(
+ #[Serializer\SerializedName('SupplierPartID')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly string $supplierPartId,
+ #[Serializer\SerializedName('SupplierPartAuxiliaryID')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly ?string $supplierPartAuxiliaryId = null,
+ #[Serializer\SerializedName('BuyerPartID')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly ?string $buyerPartId = null,
+ ) {
}
public function getSupplierPartId(): string
diff --git a/src/CXml/Model/ItemIn.php b/src/CXml/Model/ItemIn.php
index c8d3e12..8801af0 100644
--- a/src/CXml/Model/ItemIn.php
+++ b/src/CXml/Model/ItemIn.php
@@ -1,41 +1,29 @@
quantity = $quantity;
- $this->itemId = $itemId;
- $this->itemDetail = $itemDetail;
}
public static function create(
int $quantity,
ItemId $itemId,
- ItemDetail $itemDetail
+ ItemDetail $itemDetail,
): self {
return new self(
$quantity,
diff --git a/src/CXml/Model/ItemOut.php b/src/CXml/Model/ItemOut.php
index 45744cd..3b580e7 100644
--- a/src/CXml/Model/ItemOut.php
+++ b/src/CXml/Model/ItemOut.php
@@ -1,59 +1,33 @@
lineNumber = $lineNumber;
- $this->quantity = $quantity;
- $this->itemId = $itemId;
- $this->itemDetail = $itemDetail;
- $this->requestedDeliveryDate = $requestedDeliveryDate;
- $this->parentLineNumber = $parentLineNumber;
}
public static function create(
@@ -61,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,
@@ -70,7 +44,7 @@ public static function create(
$itemId,
$itemDetail,
$requestedDeliveryDate,
- $parentLineNumber
+ $parentLineNumber,
);
}
@@ -92,7 +66,7 @@ public function getQuantity(): int
return $this->quantity;
}
- public function getRequestedDeliveryDate(): ?\DateTimeInterface
+ public function getRequestedDeliveryDate(): ?DateTimeInterface
{
return $this->requestedDeliveryDate;
}
diff --git a/src/CXml/Model/Message/Message.php b/src/CXml/Model/Message/Message.php
index 6f7b8d7..c667142 100644
--- a/src/CXml/Model/Message/Message.php
+++ b/src/CXml/Model/Message/Message.php
@@ -1,59 +1,34 @@
status = $status;
- $this->payload = $message;
- $this->deploymentMode = $deploymentMode;
- $this->inReplyTo = $inReplyTo;
- $this->id = $id;
}
public function getStatus(): ?Status
diff --git a/src/CXml/Model/Message/MessagePayloadInterface.php b/src/CXml/Model/Message/MessagePayloadInterface.php
index 1164f80..df4342d 100644
--- a/src/CXml/Model/Message/MessagePayloadInterface.php
+++ b/src/CXml/Model/Message/MessagePayloadInterface.php
@@ -1,5 +1,7 @@
contact = $contact;
- $this->description = $description;
- $this->itemId = $itemId;
- $this->inventory = $inventory;
+ private function __construct(
+ #[Serializer\SerializedName('ItemID')]
+ private readonly ItemId $itemId,
+ #[Serializer\SerializedName('Inventory')]
+ private readonly ?Inventory $inventory = null,
+ #[Serializer\SerializedName('Contact')]
+ private readonly ?Contact $contact = null,
+ #[Serializer\SerializedName('Description')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly ?MultilanguageString $description = null,
+ ) {
}
public static function create(ItemId $itemId, Inventory $inventory = null, Contact $contact = null, MultilanguageString $description = null): self
diff --git a/src/CXml/Model/Message/ProductActivityHeader.php b/src/CXml/Model/Message/ProductActivityHeader.php
index 487a601..2da5377 100644
--- a/src/CXml/Model/Message/ProductActivityHeader.php
+++ b/src/CXml/Model/Message/ProductActivityHeader.php
@@ -1,35 +1,27 @@
messageId = $messageId;
- $this->processType = $processType;
- $this->creationDate = $creationDate;
+ final public const PROCESSTYPE_SUPPLIER_MANAGED_INVENTORY = 'SMI';
+
+ final public const PROCESSTYPE_THIRD_PARTY_LOGISTICS = '3PL';
+
+ public function __construct(
+ #[Serializer\SerializedName('messageID')]
+ #[Serializer\XmlAttribute]
+ private string $messageId,
+ #[Serializer\XmlAttribute]
+ private ?string $processType = null,
+ #[Serializer\XmlAttribute]
+ private ?DateTimeInterface $creationDate = null,
+ ) {
}
public function getMessageId(): string
@@ -42,7 +34,7 @@ public function getProcessType(): ?string
return $this->processType;
}
- public function getCreationDate(): ?\DateTimeInterface
+ public function getCreationDate(): ?DateTimeInterface
{
return $this->creationDate;
}
diff --git a/src/CXml/Model/Message/ProductActivityMessage.php b/src/CXml/Model/Message/ProductActivityMessage.php
index 85967c2..8356ef6 100644
--- a/src/CXml/Model/Message/ProductActivityMessage.php
+++ b/src/CXml/Model/Message/ProductActivityMessage.php
@@ -1,33 +1,34 @@
")
- *
* @var ProductActivityDetail[]
*/
+ #[Serializer\XmlList(entry: 'ProductActivityDetails', inline: true)]
+ #[Serializer\Type('array')]
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);
}
diff --git a/src/CXml/Model/Message/PunchOutOrderMessage.php b/src/CXml/Model/Message/PunchOutOrderMessage.php
index 96fd6dc..5b5e86b 100644
--- a/src/CXml/Model/Message/PunchOutOrderMessage.php
+++ b/src/CXml/Model/Message/PunchOutOrderMessage.php
@@ -1,35 +1,27 @@
")
- *
* @var ItemIn[]
*/
+ #[Serializer\XmlList(entry: 'ItemIn', inline: true)]
+ #[Serializer\Type('array')]
private array $punchoutOrderMessageItems = [];
- private function __construct(string $buyerCookie, PunchOutOrderMessageHeader $punchOutOrderMessageHeader)
+ private function __construct(#[Serializer\SerializedName('BuyerCookie')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly string $buyerCookie, #[Serializer\SerializedName('PunchOutOrderMessageHeader')]
+ private readonly PunchOutOrderMessageHeader $punchOutOrderMessageHeader)
{
- $this->buyerCookie = $buyerCookie;
- $this->punchOutOrderMessageHeader = $punchOutOrderMessageHeader;
}
public static function create(string $buyerCookie, PunchOutOrderMessageHeader $punchOutOrderMessageHeader): self
diff --git a/src/CXml/Model/Message/PunchOutOrderMessageHeader.php b/src/CXml/Model/Message/PunchOutOrderMessageHeader.php
index 3b43870..c5c3ce7 100644
--- a/src/CXml/Model/Message/PunchOutOrderMessageHeader.php
+++ b/src/CXml/Model/Message/PunchOutOrderMessageHeader.php
@@ -1,5 +1,7 @@
total = $total;
- $this->shipping = $shipping;
- $this->tax = $tax;
$this->operationAllowed = $operationAllowed ?? self::OPERATION_CREATE;
}
@@ -68,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);
diff --git a/src/CXml/Model/Message/QuoteMessage.php b/src/CXml/Model/Message/QuoteMessage.php
index 52c4d14..ce45d1c 100644
--- a/src/CXml/Model/Message/QuoteMessage.php
+++ b/src/CXml/Model/Message/QuoteMessage.php
@@ -1,36 +1,34 @@
")
- *
* @var ItemIn[]
*/
+ #[Serializer\XmlList(entry: 'QuoteItemIn', inline: true)]
+ #[Serializer\Type('array')]
private array $quoteMessageItems = [];
- private function __construct(QuoteMessageHeader $quoteMessageHeader)
+ private function __construct(#[Serializer\SerializedName('QuoteMessageHeader')]
+ private readonly QuoteMessageHeader $quoteMessageHeader)
{
- $this->quoteMessageHeader = $quoteMessageHeader;
}
- public static function create(OrganizationId $organizationId, MoneyWrapper $total, string $type, string $quoteId, \DateTime $quoteDate, string $lang = 'en'): self
+ public static function create(OrganizationId $organizationId, MoneyWrapper $total, string $type, string $quoteId, DateTime $quoteDate, string $lang = 'en'): self
{
return new self(
- new QuoteMessageHeader($organizationId, $total, $type, $quoteId, $quoteDate, $total->getMoney()->getCurrency(), $lang)
+ new QuoteMessageHeader($organizationId, $total, $type, $quoteId, $quoteDate, $total->getMoney()->getCurrency(), $lang),
);
}
diff --git a/src/CXml/Model/Message/QuoteMessageHeader.php b/src/CXml/Model/Message/QuoteMessageHeader.php
index 78ac5c8..51f9828 100644
--- a/src/CXml/Model/Message/QuoteMessageHeader.php
+++ b/src/CXml/Model/Message/QuoteMessageHeader.php
@@ -1,5 +1,7 @@
")
- *
* @var Contact[]
*/
+ #[Serializer\XmlList(entry: 'Contact', inline: true)]
+ #[Serializer\Type('array')]
private array $contacts = [];
- public function __construct(OrganizationId $organizationId, MoneyWrapper $total, string $type, string $quoteId, \DateTime $quoteDate, string $currency, string $lang = 'en')
- {
+ public function __construct(
+ #[Serializer\SerializedName('OrganizationID')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly OrganizationId $organizationId,
+ #[Serializer\SerializedName('Total')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly MoneyWrapper $total,
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('type')]
+ private readonly string $type,
+ #[Serializer\SerializedName('quoteID')]
+ #[Serializer\XmlAttribute]
+ private readonly string $quoteId,
+ #[Serializer\XmlAttribute]
+ private readonly DateTimeInterface $quoteDate,
+ #[Serializer\XmlAttribute]
+ private readonly string $currency,
+ #[Serializer\XmlAttribute(namespace: 'http://www.w3.org/XML/1998/namespace')]
+ private readonly string $lang = 'en',
+ ) {
Assertion::inArray($type, [
self::TYPE_ACCEPT,
self::TYPE_REJECT,
@@ -84,14 +68,6 @@ public function __construct(OrganizationId $organizationId, MoneyWrapper $total,
self::TYPE_FINAL,
self::TYPE_AWARD,
]);
-
- $this->organizationId = $organizationId;
- $this->total = $total;
- $this->type = $type;
- $this->quoteId = $quoteId;
- $this->quoteDate = $quoteDate;
- $this->currency = $currency;
- $this->lang = $lang;
}
public function setShipTo(ShipTo $shipTo): self
@@ -131,7 +107,7 @@ public function getQuoteId(): string
return $this->quoteId;
}
- public function getQuoteDate(): \DateTimeInterface
+ public function getQuoteDate(): DateTimeInterface
{
return $this->quoteDate;
}
diff --git a/src/CXml/Model/Money.php b/src/CXml/Model/Money.php
index ea49fc6..7102cc7 100644
--- a/src/CXml/Model/Money.php
+++ b/src/CXml/Model/Money.php
@@ -1,31 +1,25 @@
currency = $currency;
- $this->valueCent = $valueCent;
- $this->value = \number_format($valueCent / 100, 2, '.', '');
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ private string $currency,
+ #[Serializer\Exclude]
+ private int $valueCent,
+ ) {
+ $this->value = number_format($this->valueCent / 100, 2, '.', '');
}
public function getCurrency(): string
@@ -40,6 +34,6 @@ public function getValue(): string
public function getValueCent(): int
{
- return $this->valueCent ?? (int) (((float) $this->value) * 100);
+ return $this->valueCent ?? (int)(((float)$this->value) * 100);
}
}
diff --git a/src/CXml/Model/MoneyWrapper.php b/src/CXml/Model/MoneyWrapper.php
index 1e5dc7d..a5c22f1 100644
--- a/src/CXml/Model/MoneyWrapper.php
+++ b/src/CXml/Model/MoneyWrapper.php
@@ -1,14 +1,14 @@
value = $value;
- $this->lang = $lang;
- $this->type = $type;
+ public function __construct(
+ #[Serializer\XmlValue(cdata: false)]
+ private readonly ?string $value,
+ #[Serializer\XmlAttribute]
+ private readonly ?string $type = null,
+ #[Serializer\XmlAttribute(namespace: 'http://www.w3.org/XML/1998/namespace')]
+ private readonly ?string $lang = 'en',
+ ) {
}
public function getValue(): ?string
diff --git a/src/CXml/Model/Option.php b/src/CXml/Model/Option.php
index 4d8977a..c007c64 100644
--- a/src/CXml/Model/Option.php
+++ b/src/CXml/Model/Option.php
@@ -1,24 +1,28 @@
name;
+ }
- public function __construct(string $name, string $value)
+ public function getValue(): string
{
- $this->name = $name;
- $this->value = $value;
+ return $this->value;
}
}
diff --git a/src/CXml/Model/OrderReference.php b/src/CXml/Model/OrderReference.php
index 71be241..c16f7a6 100644
--- a/src/CXml/Model/OrderReference.php
+++ b/src/CXml/Model/OrderReference.php
@@ -1,38 +1,30 @@
documentReference = $documentReference;
- $this->orderId = $orderId;
- $this->orderDate = $orderDate;
+ public function __construct(
+ #[Serializer\SerializedName('DocumentReference')]
+ private ?DocumentReference $documentReference,
+ #[Serializer\SerializedName('orderID')]
+ #[Serializer\XmlAttribute]
+ private ?string $orderId = null,
+ #[Serializer\XmlAttribute]
+ private ?DateTimeInterface $orderDate = null,
+ ) {
}
public static function create(string $documentReference): self
{
return new self(
- new DocumentReference($documentReference)
+ new DocumentReference($documentReference),
);
}
@@ -46,7 +38,7 @@ public function getOrderId(): ?string
return $this->orderId;
}
- public function getOrderDate(): ?\DateTimeInterface
+ public function getOrderDate(): ?DateTimeInterface
{
return $this->orderDate;
}
diff --git a/src/CXml/Model/OrganizationId.php b/src/CXml/Model/OrganizationId.php
index 5d6eab1..14cc324 100644
--- a/src/CXml/Model/OrganizationId.php
+++ b/src/CXml/Model/OrganizationId.php
@@ -1,19 +1,18 @@
credential = $credential;
+ public function __construct(
+ #[Serializer\SerializedName('Credential')]
+ private Credential $credential,
+ ) {
}
public function getCredential(): Credential
diff --git a/src/CXml/Model/Party.php b/src/CXml/Model/Party.php
index c37c997..f6cce29 100644
--- a/src/CXml/Model/Party.php
+++ b/src/CXml/Model/Party.php
@@ -1,26 +1,21 @@
credential = $credential;
- $this->userAgent = $userAgent;
+ public function __construct(
+ #[Serializer\SerializedName('Credential')]
+ private Credential $credential,
+ #[Serializer\SerializedName('UserAgent')]
+ #[Serializer\XmlElement(cdata: false)]
+ private ?string $userAgent = null,
+ ) {
}
public function getCredential(): Credential
diff --git a/src/CXml/Model/PayloadIdentity.php b/src/CXml/Model/PayloadIdentity.php
index b1a7c74..29793a5 100644
--- a/src/CXml/Model/PayloadIdentity.php
+++ b/src/CXml/Model/PayloadIdentity.php
@@ -1,16 +1,19 @@
payloadId = $payloadId;
- $this->timestamp = $timestamp ?? new \DateTime();
+ $this->timestamp = $timestamp ?? new DateTime();
}
public function getPayloadId(): string
@@ -18,7 +21,7 @@ public function getPayloadId(): string
return $this->payloadId;
}
- public function getTimestamp(): \DateTimeInterface
+ public function getTimestamp(): DateTimeInterface
{
return $this->timestamp;
}
diff --git a/src/CXml/Model/PayloadInterface.php b/src/CXml/Model/PayloadInterface.php
index b9b8999..5b2d5cd 100644
--- a/src/CXml/Model/PayloadInterface.php
+++ b/src/CXml/Model/PayloadInterface.php
@@ -1,5 +1,7 @@
telephoneNumber = $telephoneNumber;
- $this->name = $name;
+ public function __construct(
+ #[Serializer\SerializedName('TelephoneNumber')]
+ #[Serializer\XmlElement(cdata: false)]
+ private TelephoneNumber $telephoneNumber,
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('name')]
+ private ?string $name = null,
+ ) {
}
public function getTelephoneNumber(): TelephoneNumber
diff --git a/src/CXml/Model/PostalAddress.php b/src/CXml/Model/PostalAddress.php
index 615051c..5566037 100644
--- a/src/CXml/Model/PostalAddress.php
+++ b/src/CXml/Model/PostalAddress.php
@@ -1,73 +1,46 @@
")
- * @Ser\XmlElement(cdata=false)
- */
- private array $deliverTo;
-
- /**
- * @Ser\XmlList(inline=true, entry="Street")
- * @Ser\Type("array")
- * @Ser\XmlElement(cdata=false)
- */
- private array $street;
-
- /**
- * @Ser\SerializedName("City")
- * @Ser\XmlElement (cdata=false)
- */
- private string $city;
-
- /**
- * @Ser\SerializedName("Municipality")
- * @Ser\XmlElement (cdata=false)
- */
- private ?string $municipality = null;
-
- /**
- * @Ser\SerializedName("State")
- * @Ser\XmlElement (cdata=false)
- */
- private ?string $state = null;
-
- /**
- * @Ser\SerializedName("PostalCode")
- * @Ser\XmlElement (cdata=false)
- */
- private ?string $postalCode = null;
-
- /**
- * @Ser\SerializedName("Country")
- * @Ser\XmlElement (cdata=false)
- */
- private Country $country;
-
- public function __construct(array $deliverTo, array $street, string $city, Country $country, string $municipality = null, string $state = null, string $postalCode = null, string $name = null)
- {
- $this->name = $name;
- $this->deliverTo = $deliverTo;
- $this->street = $street;
- $this->city = $city;
- $this->municipality = $municipality;
- $this->state = $state;
- $this->postalCode = $postalCode;
- $this->country = $country;
+ public function __construct(
+ #[Serializer\XmlList(entry: 'DeliverTo', inline: true)]
+ #[Serializer\Type('array')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly array $deliverTo,
+ #[Serializer\XmlList(entry: 'Street', inline: true)]
+ #[Serializer\Type('array')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly array $street,
+ #[Serializer\SerializedName('City')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly string $city,
+ #[Serializer\SerializedName('Country')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly Country $country,
+ #[Serializer\SerializedName('Municipality')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly ?string $municipality = null,
+ #[Serializer\SerializedName('State')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly ?string $state = null,
+ #[Serializer\SerializedName('PostalCode')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly ?string $postalCode = null,
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('name')]
+ private readonly ?string $name = null,
+ ) {
}
public function getName(): ?string
@@ -116,12 +89,12 @@ public function getCountry(): Country
public function isEmpty(): bool
{
return
- empty($this->name)
- && empty(\array_filter($this->deliverTo))
- && empty(\array_filter($this->street))
- && empty($this->city)
- && empty($this->municipality)
- && empty($this->state)
- && empty($this->postalCode);
+ (null === $this->name || '' === $this->name || '0' === $this->name)
+ && [] === array_filter($this->deliverTo)
+ && [] === array_filter($this->street)
+ && ('' === $this->city || '0' === $this->city)
+ && (null === $this->municipality || '' === $this->municipality || '0' === $this->municipality)
+ && (null === $this->state || '' === $this->state || '0' === $this->state)
+ && (null === $this->postalCode || '' === $this->postalCode || '0' === $this->postalCode);
}
}
diff --git a/src/CXml/Model/PriceBasisQuantity.php b/src/CXml/Model/PriceBasisQuantity.php
index 799e6de..244d6f1 100644
--- a/src/CXml/Model/PriceBasisQuantity.php
+++ b/src/CXml/Model/PriceBasisQuantity.php
@@ -1,41 +1,27 @@
quantity = $quantity;
- $this->conversionFactor = $conversionFactor;
- $this->unitOfMeasure = $unitOfMeasure;
- $this->description = $description;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('quantity')]
+ private int $quantity,
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('conversionFactor')]
+ private float $conversionFactor,
+ #[Serializer\SerializedName('UnitOfMeasure')]
+ #[Serializer\XmlElement(cdata: false)]
+ private string $unitOfMeasure,
+ #[Serializer\SerializedName('Description')]
+ #[Serializer\XmlElement(cdata: false)]
+ private MultilanguageString $description,
+ ) {
}
public function getQuantity(): int
diff --git a/src/CXml/Model/Request/ConfirmationHeader.php b/src/CXml/Model/Request/ConfirmationHeader.php
index 1402697..6a6d004 100644
--- a/src/CXml/Model/Request/ConfirmationHeader.php
+++ b/src/CXml/Model/Request/ConfirmationHeader.php
@@ -1,38 +1,45 @@
type = $type;
- $this->noticeDate = $noticeDate ?? new \DateTime();
}
- public static function create(string $type, \DateTimeInterface $noticeDate = null): self
+ public static function create(string $type, DateTimeInterface $noticeDate = new DateTime()): self
{
return new self(
$type,
- $noticeDate
+ $noticeDate,
);
}
@@ -61,7 +65,7 @@ public function getType(): string
return $this->type;
}
- public function getNoticeDate(): \DateTimeInterface
+ public function getNoticeDate(): DateTimeInterface
{
return $this->noticeDate;
}
diff --git a/src/CXml/Model/Request/ConfirmationRequest.php b/src/CXml/Model/Request/ConfirmationRequest.php
index 4f5606d..a5ebbf2 100644
--- a/src/CXml/Model/Request/ConfirmationRequest.php
+++ b/src/CXml/Model/Request/ConfirmationRequest.php
@@ -1,26 +1,21 @@
confirmationHeader = $confirmationHeader;
- $this->orderReference = $orderReference;
+ public function __construct(
+ #[Serializer\SerializedName('ConfirmationHeader')]
+ private ConfirmationHeader $confirmationHeader,
+ #[Serializer\SerializedName('OrderReference')]
+ private OrderReference $orderReference,
+ ) {
}
public static function create(ConfirmationHeader $confirmationHeader, OrderReference $orderReference): self
diff --git a/src/CXml/Model/Request/OrderRequest.php b/src/CXml/Model/Request/OrderRequest.php
index f0dad1b..c74e467 100644
--- a/src/CXml/Model/Request/OrderRequest.php
+++ b/src/CXml/Model/Request/OrderRequest.php
@@ -1,34 +1,31 @@
")
- *
* @var ItemOut[]
*/
+ #[Serializer\XmlList(entry: 'ItemOut', inline: true)]
+ #[Serializer\Type('array')]
private array $itemOut = [];
- protected function __construct(OrderRequestHeader $orderRequestHeader)
+ protected function __construct(#[Serializer\SerializedName('OrderRequestHeader')]
+ private readonly OrderRequestHeader $orderRequestHeader)
{
- $this->orderRequestHeader = $orderRequestHeader;
}
public static function create(OrderRequestHeader $orderRequestHeader): self
{
return new self(
- $orderRequestHeader
+ $orderRequestHeader,
);
}
diff --git a/src/CXml/Model/Request/OrderRequestHeader.php b/src/CXml/Model/Request/OrderRequestHeader.php
index 0e1182a..c692281 100644
--- a/src/CXml/Model/Request/OrderRequestHeader.php
+++ b/src/CXml/Model/Request/OrderRequestHeader.php
@@ -1,5 +1,7 @@
")
- *
- * @var Contact[]
- */
- private ?array $contacts = null;
-
- /**
- * @Ser\SerializedName("SupplierOrderInfo")
- */
+ #[Serializer\SerializedName('SupplierOrderInfo')]
private ?SupplierOrderInfo $supplierOrderInfo = null;
- public function __construct(
- string $orderId,
- \DateTimeInterface $orderDate,
- ?ShipTo $shipTo,
- BillTo $billTo,
- MoneyWrapper $total,
- string $type = self::TYPE_NEW,
- array $contacts = null
+ protected function __construct(
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('orderID')]
+ private readonly string $orderId,
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('orderDate')]
+ private readonly DateTimeInterface $orderDate,
+ #[Serializer\XmlElement]
+ #[Serializer\SerializedName('ShipTo')]
+ private readonly ?ShipTo $shipTo,
+ #[Serializer\XmlElement]
+ #[Serializer\SerializedName('BillTo')]
+ private readonly BillTo $billTo,
+ #[Serializer\XmlElement]
+ #[Serializer\SerializedName('Total')]
+ private readonly MoneyWrapper $total,
+ #[Serializer\XmlAttribute]
+ private readonly string $type = self::TYPE_NEW,
+ #[Serializer\Type('array')]
+ #[Serializer\XmlList(entry: 'Contact', inline: true)]
+ private ?array $contacts = null,
) {
- if ($contacts) {
- Assertion::allIsInstanceOf($contacts, Contact::class);
+ if (null === $contacts) {
+ return;
+ }
+
+ if ([] === $contacts) {
+ return;
}
- $this->orderId = $orderId;
- $this->orderDate = $orderDate;
- $this->type = $type;
- $this->total = $total;
- $this->shipTo = $shipTo;
- $this->billTo = $billTo;
- $this->contacts = $contacts;
+ Assertion::allIsInstanceOf($contacts, Contact::class);
}
public static function create(
string $orderId,
- \DateTimeInterface $orderDate,
+ DateTimeInterface $orderDate,
?ShipTo $shipTo,
BillTo $billTo,
MoneyWrapper $total,
string $type = self::TYPE_NEW,
- array $contacts = null
+ array $contacts = null,
): self {
return new self($orderId, $orderDate, $shipTo, $billTo, $total, $type, $contacts);
}
@@ -146,7 +112,7 @@ public function getOrderId(): string
return $this->orderId;
}
- public function getOrderDate(): \DateTimeInterface
+ public function getOrderDate(): DateTimeInterface
{
return $this->orderDate;
}
@@ -171,11 +137,6 @@ public function getBillTo(): BillTo
return $this->billTo;
}
- public function getComments(): ?array
- {
- return $this->comments;
- }
-
public function addContact(Contact $contact): self
{
if (null === $this->contacts) {
diff --git a/src/CXml/Model/Request/ProfileRequest.php b/src/CXml/Model/Request/ProfileRequest.php
index 5a4acc4..8209851 100644
--- a/src/CXml/Model/Request/ProfileRequest.php
+++ b/src/CXml/Model/Request/ProfileRequest.php
@@ -1,5 +1,7 @@
")
- *
* @var Extrinsic[]
*/
+ #[Serializer\XmlList(entry: 'Extrinsic', inline: true)]
+ #[Serializer\Type('array')]
protected array $extrinsics = [];
- /**
- * @Ser\SerializedName("BrowserFormPost")
- */
+ #[Serializer\SerializedName('BrowserFormPost')]
private Url $browserFormPost;
- /**
- * @Ser\SerializedName("SupplierSetup")
- */
+ #[Serializer\SerializedName('SupplierSetup')]
private Url $supplierSetup;
/**
- * @Ser\SerializedName("ShipTo")
- */
- private ?ShipTo $shipTo = null;
-
- /**
- * @Ser\SerializedName("SelectedItem")
- */
- private ?SelectedItem $selectedItem = null;
-
- /**
- * @Ser\XmlList(inline=true, entry="ItemOut")
- * @Ser\Type("array")
- *
* @var ItemOut[]
*/
+ #[Serializer\XmlList(entry: 'ItemOut', inline: true)]
+ #[Serializer\Type('array')]
private array $itemOut = [];
- public function __construct(string $buyerCookie, string $browserFormPost, string $supplierSetup, ShipTo $shipTo = null, SelectedItem $selectedItem = null, string $operation = 'create')
- {
- $this->operation = $operation;
- $this->buyerCookie = $buyerCookie;
+ public function __construct(
+ #[Serializer\SerializedName('BuyerCookie')]
+ private readonly string $buyerCookie,
+ string $browserFormPost,
+ string $supplierSetup,
+ #[Serializer\SerializedName('ShipTo')]
+ private readonly ?ShipTo $shipTo = null,
+ #[Serializer\SerializedName('SelectedItem')]
+ private readonly ?SelectedItem $selectedItem = null,
+ #[Serializer\XmlAttribute]
+ private readonly ?string $operation = 'create',
+ ) {
$this->browserFormPost = new Url($browserFormPost);
$this->supplierSetup = new Url($supplierSetup);
- $this->shipTo = $shipTo;
- $this->selectedItem = $selectedItem;
}
public function getOperation(): ?string
diff --git a/src/CXml/Model/Request/Request.php b/src/CXml/Model/Request/Request.php
index 2db7efb..ada9e28 100644
--- a/src/CXml/Model/Request/Request.php
+++ b/src/CXml/Model/Request/Request.php
@@ -1,51 +1,32 @@
status = $status;
- $this->id = $id;
- $this->payload = $payload;
- $this->deploymentMode = $deploymentMode;
}
public function getStatus(): ?Status
diff --git a/src/CXml/Model/Request/RequestPayloadInterface.php b/src/CXml/Model/Request/RequestPayloadInterface.php
index 7709983..da0dc50 100644
--- a/src/CXml/Model/Request/RequestPayloadInterface.php
+++ b/src/CXml/Model/Request/RequestPayloadInterface.php
@@ -1,5 +1,7 @@
shipmentId = $shipmentId;
- $this->noticeDate = $noticeDate ?? new \DateTime();
- $this->shipmentDate = $shipmentDate;
- $this->deliveryDate = $deliveryDate;
- $this->documentReference = $documentReference ? new DocumentReference($documentReference) : null;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('shipmentID')]
+ private readonly string $shipmentId,
+ DateTimeInterface $noticeDate = null,
+ #[Serializer\XmlAttribute]
+ private readonly ?DateTimeInterface $shipmentDate = null,
+ #[Serializer\XmlAttribute]
+ private readonly ?DateTimeInterface $deliveryDate = 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);
}
@@ -64,17 +55,17 @@ public function getShipmentId(): string
return $this->shipmentId;
}
- public function getNoticeDate(): \DateTimeInterface
+ public function getNoticeDate(): DateTimeInterface
{
return $this->noticeDate;
}
- public function getShipmentDate(): ?\DateTimeInterface
+ public function getShipmentDate(): ?DateTimeInterface
{
return $this->shipmentDate;
}
- public function getDeliveryDate(): ?\DateTimeInterface
+ public function getDeliveryDate(): ?DateTimeInterface
{
return $this->deliveryDate;
}
diff --git a/src/CXml/Model/Request/ShipNoticeRequest.php b/src/CXml/Model/Request/ShipNoticeRequest.php
index 1427c5e..346702d 100644
--- a/src/CXml/Model/Request/ShipNoticeRequest.php
+++ b/src/CXml/Model/Request/ShipNoticeRequest.php
@@ -1,37 +1,33 @@
")
- *
* @var ShipControl[]
*/
+ #[Serializer\XmlList(entry: 'ShipControl', inline: true)]
+ #[Serializer\Type('array')]
private array $shipControls = [];
/**
- * @Ser\XmlList(inline=true, entry="ShipNoticePortion")
- * @Ser\Type("array")
- *
* @var ShipNoticePortion[]
*/
+ #[Serializer\XmlList(entry: 'ShipNoticePortion', inline: true)]
+ #[Serializer\Type('array')]
private array $shipNoticePortions = [];
- public function __construct(ShipNoticeHeader $shipNoticeHeader)
+ public function __construct(#[Serializer\SerializedName('ShipNoticeHeader')]
+ private readonly ShipNoticeHeader $shipNoticeHeader)
{
- $this->shipNoticeHeader = $shipNoticeHeader;
}
public static function create(ShipNoticeHeader $shipNoticeHeader): self
diff --git a/src/CXml/Model/Request/StatusUpdateRequest.php b/src/CXml/Model/Request/StatusUpdateRequest.php
index f8c6b05..f06ee70 100644
--- a/src/CXml/Model/Request/StatusUpdateRequest.php
+++ b/src/CXml/Model/Request/StatusUpdateRequest.php
@@ -1,37 +1,35 @@
status = $status;
- $this->documentReference = $documentReference ? new DocumentReference($documentReference) : null;
+ public function __construct(
+ #[Serializer\SerializedName('Status')]
+ private readonly Status $status,
+ string $documentReference = null,
+ ) {
+ $this->documentReference = null !== $documentReference && '' !== $documentReference && '0' !== $documentReference ? new DocumentReference($documentReference) : null;
}
public static function create(Status $status, string $documentReference = null): self
{
return new self(
$status,
- $documentReference
+ $documentReference,
);
}
diff --git a/src/CXml/Model/Response/ProfileResponse.php b/src/CXml/Model/Response/ProfileResponse.php
index 0f5af2d..eee5be8 100644
--- a/src/CXml/Model/Response/ProfileResponse.php
+++ b/src/CXml/Model/Response/ProfileResponse.php
@@ -1,43 +1,41 @@
")
- *
* @var Option[]
*/
+ #[Serializer\XmlList(entry: 'Option', inline: true)]
+ #[Serializer\Type('array')]
private array $options = [];
/**
- * @Ser\XmlList(inline=true, entry="Transaction")
- * @Ser\Type("array")
- *
* @var Transaction[]
*/
+ #[Serializer\XmlList(inline: true, entry: 'Transaction')]
+ #[Serializer\Type('array')]
private array $transactions = [];
- public function __construct(\DateTimeInterface $effectiveDate = null, \DateTimeInterface $lastRefresh = null)
- {
- $this->effectiveDate = $effectiveDate ?? new \DateTime();
- $this->lastRefresh = $lastRefresh;
+ public function __construct(
+ DateTimeInterface $effectiveDate = null,
+ #[Serializer\XmlAttribute]
+ private readonly ?DateTimeInterface $lastRefresh = null,
+ ) {
+ $this->effectiveDate = $effectiveDate ?? new DateTime();
}
public function addTransaction(Transaction $transaction): void
diff --git a/src/CXml/Model/Response/PunchOutSetupResponse.php b/src/CXml/Model/Response/PunchOutSetupResponse.php
index e4aff8f..9d5a125 100644
--- a/src/CXml/Model/Response/PunchOutSetupResponse.php
+++ b/src/CXml/Model/Response/PunchOutSetupResponse.php
@@ -1,19 +1,18 @@
startPage = $startPage;
+ public function __construct(
+ #[Serializer\SerializedName('StartPage')]
+ private Url $startPage,
+ ) {
}
}
diff --git a/src/CXml/Model/Response/Response.php b/src/CXml/Model/Response/Response.php
index 9e63386..162a757 100644
--- a/src/CXml/Model/Response/Response.php
+++ b/src/CXml/Model/Response/Response.php
@@ -1,37 +1,24 @@
status = $status;
- $this->id = $id;
- $this->payload = $payload;
}
public function getStatus(): Status
@@ -46,6 +33,6 @@ public function getId(): ?string
public function getPayload(): ?ResponsePayloadInterface
{
- return $this->payload;
+ return $this->payload ?? null;
}
}
diff --git a/src/CXml/Model/Response/ResponsePayloadInterface.php b/src/CXml/Model/Response/ResponsePayloadInterface.php
index 3dfa25c..0efd216 100644
--- a/src/CXml/Model/Response/ResponsePayloadInterface.php
+++ b/src/CXml/Model/Response/ResponsePayloadInterface.php
@@ -1,5 +1,7 @@
itemId = $itemId;
+ public function __construct(
+ #[Serializer\SerializedName('ItemID')]
+ private ItemId $itemId,
+ ) {
}
public function getItemId(): ItemId
diff --git a/src/CXml/Model/ShipControl.php b/src/CXml/Model/ShipControl.php
index a9be86a..d79c211 100644
--- a/src/CXml/Model/ShipControl.php
+++ b/src/CXml/Model/ShipControl.php
@@ -1,25 +1,26 @@
")
- *
* @var CarrierIdentifier[]
*/
+ #[Serializer\XmlList(entry: 'CarrierIdentifier', inline: true)]
+ #[Serializer\Type('array')]
private array $carrierIdentifiers = [];
/**
- * @Ser\XmlList(inline=true, entry="ShipmentIdentifier")
- * @Ser\Type("array")
- *
* @var ShipmentIdentifier[]
*/
+ #[Serializer\XmlList(entry: 'ShipmentIdentifier', inline: true)]
+ #[Serializer\Type('array')]
private array $shipmentIdentifiers = [];
public function __construct(CarrierIdentifier $carrierIdentifier, ShipmentIdentifier $shipmentIdentifier)
diff --git a/src/CXml/Model/ShipNoticePortion.php b/src/CXml/Model/ShipNoticePortion.php
index cb31c0c..6265b30 100644
--- a/src/CXml/Model/ShipNoticePortion.php
+++ b/src/CXml/Model/ShipNoticePortion.php
@@ -1,24 +1,26 @@
orderReference = new OrderReference(
new DocumentReference(
- $documentReference
+ $documentReference,
),
$orderId,
- $orderDate
+ $orderDate,
);
}
diff --git a/src/CXml/Model/ShipTo.php b/src/CXml/Model/ShipTo.php
index 8d83061..1c7a512 100644
--- a/src/CXml/Model/ShipTo.php
+++ b/src/CXml/Model/ShipTo.php
@@ -1,35 +1,27 @@
")
- *
* @var CarrierIdentifier[]
*/
+ #[Serializer\XmlList(entry: 'CarrierIdentifier', inline: true)]
+ #[Serializer\Type('array')]
private array $carrierIdentifiers = [];
- /**
- * @Ser\SerializedName("TransportInformation")
- */
- private ?TransportInformation $transportInformation = null;
-
- public function __construct(Address $address, TransportInformation $transportInformation = null)
+ public function __construct(#[Serializer\SerializedName('Address')]
+ private readonly Address $address, #[Serializer\SerializedName('TransportInformation')]
+ private readonly ?TransportInformation $transportInformation = null)
{
- $this->address = $address;
- $this->transportInformation = $transportInformation;
}
public function addCarrierIdentifier(string $domain, string $identifier): self
diff --git a/src/CXml/Model/ShipmentIdentifier.php b/src/CXml/Model/ShipmentIdentifier.php
index 1400213..fafaf82 100644
--- a/src/CXml/Model/ShipmentIdentifier.php
+++ b/src/CXml/Model/ShipmentIdentifier.php
@@ -1,37 +1,24 @@
value = $value;
- $this->domain = $domain;
- $this->trackingNumberDate = $trackingNumberDate;
- $this->trackingURL = $trackingURL;
+ public function __construct(
+ #[Serializer\XmlValue(cdata: false)]
+ private string $value,
+ #[Serializer\XmlAttribute]
+ private ?string $domain = null,
+ #[Serializer\XmlAttribute]
+ private ?string $trackingNumberDate = null,
+ #[Serializer\XmlAttribute]
+ private ?string $trackingURL = null,
+ ) {
}
public function getDomain(): ?string
diff --git a/src/CXml/Model/Shipping.php b/src/CXml/Model/Shipping.php
index 6ae7736..f17de1b 100644
--- a/src/CXml/Model/Shipping.php
+++ b/src/CXml/Model/Shipping.php
@@ -1,26 +1,25 @@
money = new Money($currency, $value);
- $this->description = $description;
}
public function getMoney(): Money
diff --git a/src/CXml/Model/ShippingContractNumber.php b/src/CXml/Model/ShippingContractNumber.php
index 451d078..03a9eb5 100644
--- a/src/CXml/Model/ShippingContractNumber.php
+++ b/src/CXml/Model/ShippingContractNumber.php
@@ -1,18 +1,21 @@
value = $value;
+ return $this->value;
}
}
diff --git a/src/CXml/Model/Status.php b/src/CXml/Model/Status.php
index 2026a50..6049b8c 100644
--- a/src/CXml/Model/Status.php
+++ b/src/CXml/Model/Status.php
@@ -1,37 +1,23 @@
code = $code;
- $this->text = $text;
- $this->message = $message;
- $this->lang = $lang;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ private int $code = 200,
+ #[Serializer\XmlAttribute]
+ private string $text = 'OK',
+ #[Serializer\XmlValue(cdata: false)]
+ private ?string $message = null,
+ #[Serializer\XmlAttribute(namespace: 'http://www.w3.org/XML/1998/namespace')]
+ private ?string $lang = null,
+ ) {
}
public function getCode(): int
@@ -48,4 +34,9 @@ public function getMessage(): ?string
{
return $this->message;
}
+
+ public function getLang(): ?string
+ {
+ return $this->lang;
+ }
}
diff --git a/src/CXml/Model/SupplierOrderInfo.php b/src/CXml/Model/SupplierOrderInfo.php
index 7847f03..9d89c16 100644
--- a/src/CXml/Model/SupplierOrderInfo.php
+++ b/src/CXml/Model/SupplierOrderInfo.php
@@ -1,26 +1,21 @@
orderId = $orderId;
- $this->orderDate = $orderDate;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ #[Serializer\SerializedName('orderID')]
+ private string $orderId,
+ #[Serializer\XmlAttribute]
+ private ?DateTimeInterface $orderDate = null,
+ ) {
}
public function getOrderId(): string
@@ -28,7 +23,7 @@ public function getOrderId(): string
return $this->orderId;
}
- public function getOrderDate(): ?\DateTimeInterface
+ public function getOrderDate(): ?DateTimeInterface
{
return $this->orderDate;
}
diff --git a/src/CXml/Model/Tax.php b/src/CXml/Model/Tax.php
index 41cefa7..9d280d8 100644
--- a/src/CXml/Model/Tax.php
+++ b/src/CXml/Model/Tax.php
@@ -1,26 +1,25 @@
money = new Money($currency, $value);
- $this->description = $description;
}
public function getMoney(): Money
diff --git a/src/CXml/Model/TelephoneNumber.php b/src/CXml/Model/TelephoneNumber.php
index 301ead1..e7fa3b5 100644
--- a/src/CXml/Model/TelephoneNumber.php
+++ b/src/CXml/Model/TelephoneNumber.php
@@ -1,34 +1,25 @@
countryCode = $countryCode;
- $this->areaOrCityCode = $areaOrCityCode;
- $this->number = $number;
+ public function __construct(
+ #[Serializer\SerializedName('CountryCode')]
+ #[Serializer\XmlElement(cdata: false)]
+ private CountryCode $countryCode,
+ #[Serializer\SerializedName('AreaOrCityCode')]
+ #[Serializer\XmlElement(cdata: false)]
+ private ?string $areaOrCityCode = null,
+ #[Serializer\SerializedName('Number')]
+ #[Serializer\XmlElement(cdata: false)]
+ private ?string $number = null,
+ ) {
}
public function getCountryCode(): CountryCode
diff --git a/src/CXml/Model/Transaction.php b/src/CXml/Model/Transaction.php
index a8587c1..711310b 100644
--- a/src/CXml/Model/Transaction.php
+++ b/src/CXml/Model/Transaction.php
@@ -1,34 +1,28 @@
")
- *
* @var Option[]
*/
+ #[Serializer\XmlList(entry: 'Option', inline: true)]
+ #[Serializer\Type('array')]
private array $options = [];
- public function __construct(string $requestName, string $url)
- {
- $this->requestName = $requestName;
- $this->url = $url;
+ public function __construct(
+ #[Serializer\XmlAttribute]
+ private readonly string $requestName,
+ #[Serializer\SerializedName('URL')]
+ #[Serializer\XmlElement(cdata: false)]
+ private readonly string $url,
+ ) {
}
public function addOption(Option $option): void
diff --git a/src/CXml/Model/TransportInformation.php b/src/CXml/Model/TransportInformation.php
index bb77cbe..90559e8 100644
--- a/src/CXml/Model/TransportInformation.php
+++ b/src/CXml/Model/TransportInformation.php
@@ -1,19 +1,18 @@
shippingContractNumber = $shippingContractNumber;
+ public function __construct(
+ #[Serializer\SerializedName('ShippingContractNumber')]
+ private ?ShippingContractNumber $shippingContractNumber,
+ ) {
}
public static function fromContractAccountNumber(string $carrierAccountNo): self
diff --git a/src/CXml/Model/UnitOfMeasure.php b/src/CXml/Model/UnitOfMeasure.php
index 8459ea3..41b2c5e 100644
--- a/src/CXml/Model/UnitOfMeasure.php
+++ b/src/CXml/Model/UnitOfMeasure.php
@@ -1,19 +1,17 @@
value = $value;
+ public function __construct(
+ #[Serializer\XmlValue(cdata: false)]
+ private string $value,
+ ) {
}
public function getValue(): string
diff --git a/src/CXml/Model/Url.php b/src/CXml/Model/Url.php
index 74ca3a3..54816a1 100644
--- a/src/CXml/Model/Url.php
+++ b/src/CXml/Model/Url.php
@@ -1,20 +1,18 @@
url = $url;
+ public function __construct(
+ #[Serializer\SerializedName('URL')]
+ #[Serializer\XmlElement(cdata: false)]
+ private string $url,
+ ) {
}
public function getUrl(): string
diff --git a/src/CXml/Payload/DefaultPayloadIdentityFactory.php b/src/CXml/Payload/DefaultPayloadIdentityFactory.php
index 9c6c728..adab48c 100644
--- a/src/CXml/Payload/DefaultPayloadIdentityFactory.php
+++ b/src/CXml/Payload/DefaultPayloadIdentityFactory.php
@@ -1,45 +1,54 @@
timeCallable = $timeCallable ?? function () {
- return new \DateTime();
- };
+ $this->timeCallable = $timeCallable ?? static fn (): DateTime => new DateTime();
}
- private static function generateNewPayloadId(\DateTimeInterface $timestamp): string
+ private function generateNewPayloadId(DateTimeInterface $timestamp): string
{
// The recommended implementation is:
// datetime.process id.random number@hostname
- return \sprintf(
+ return sprintf(
'%s.%s.%s@%s',
$timestamp->format('U.v'), // include milliseconds
- \getmypid(),
- \mt_rand(1000, 9999),
- \gethostname()
+ getmypid(),
+ mt_rand(1000, 9999),
+ gethostname(),
);
}
public function newPayloadIdentity(): PayloadIdentity
{
- /** @var \DateTimeInterface $timestamp */
- $timestamp = \call_user_func($this->timeCallable);
- $payloadId = self::generateNewPayloadId($timestamp);
+ /** @var DateTimeInterface $timestamp */
+ $timestamp = call_user_func($this->timeCallable);
+ $payloadId = $this->generateNewPayloadId($timestamp);
return new PayloadIdentity(
$payloadId,
- $timestamp
+ $timestamp,
);
}
}
diff --git a/src/CXml/Payload/PayloadIdentityFactoryInterface.php b/src/CXml/Payload/PayloadIdentityFactoryInterface.php
index a48b4da..bafaa06 100644
--- a/src/CXml/Payload/PayloadIdentityFactoryInterface.php
+++ b/src/CXml/Payload/PayloadIdentityFactoryInterface.php
@@ -1,5 +1,7 @@
cxml = $cxml;
- $this->context = $context;
}
public function getCxml(): CXml
diff --git a/src/CXml/Processor/Exception/CXmlProcessException.php b/src/CXml/Processor/Exception/CXmlProcessException.php
index 5c5077a..9b50c9a 100644
--- a/src/CXml/Processor/Exception/CXmlProcessException.php
+++ b/src/CXml/Processor/Exception/CXmlProcessException.php
@@ -1,13 +1,16 @@
getMessage(), $previous);
+ parent::__construct('Error while processing cXML message: ' . $previous->getMessage(), $previous);
}
}
diff --git a/src/CXml/Processor/HeaderProcessor.php b/src/CXml/Processor/HeaderProcessor.php
index 1c69f78..557f70e 100644
--- a/src/CXml/Processor/HeaderProcessor.php
+++ b/src/CXml/Processor/HeaderProcessor.php
@@ -1,29 +1,22 @@
credentialRepository = $credentialRepository;
- $this->credentialValidator = $credentialValidator;
- $this->authenticator = $authenticator;
}
/**
diff --git a/src/CXml/Processor/Processor.php b/src/CXml/Processor/Processor.php
index 561ac2d..0ee5f48 100644
--- a/src/CXml/Processor/Processor.php
+++ b/src/CXml/Processor/Processor.php
@@ -1,5 +1,7 @@
450,
];
+ // TODO create enum for this?
private static array $exceptionCodeMapping = [
// cxml
450 => 'Not Implemented',
@@ -83,7 +89,7 @@ class Processor
415 => 'Unsupported Media Type',
416 => 'Range Not Satisfiable',
417 => 'Expectation Failed',
- 418 => 'I\'m a teapot', // RFC2324
+ 418 => "I'm a teapot", // RFC2324
421 => 'Misdirected Request', // RFC7540
422 => 'Unprocessable Entity', // RFC4918
423 => 'Locked', // RFC4918
@@ -107,21 +113,8 @@ class Processor
511 => 'Network Authentication Required', // RFC6585
];
- private HeaderProcessor $headerProcessor;
- private HandlerRegistryInterface $handlerRegistry;
- private Builder $builder;
- private ?EventDispatcherInterface $eventDispatcher;
-
- public function __construct(
- HeaderProcessor $requestProcessor,
- HandlerRegistryInterface $handlerRepository,
- Builder $builder,
- EventDispatcherInterface $eventDispatcher = null
- ) {
- $this->headerProcessor = $requestProcessor;
- $this->handlerRegistry = $handlerRepository;
- $this->builder = $builder;
- $this->eventDispatcher = $eventDispatcher;
+ public function __construct(private readonly HeaderProcessor $headerProcessor, private readonly HandlerRegistryInterface $handlerRegistry, private readonly Builder $builder, private readonly ?EventDispatcherInterface $eventDispatcher = null)
+ {
}
/**
@@ -132,24 +125,22 @@ public function process(CXml $cxml, Context $context = null): ?CXml
$context ??= Context::create();
$context->setCXml($cxml);
- if ($this->eventDispatcher) {
- $this->eventDispatcher->dispatch(new CXmlProcessEvent($cxml, $context));
- }
+ $this->eventDispatcher?->dispatch(new CXmlProcessEvent($cxml, $context));
$request = $cxml->getRequest();
- if ($request) {
+ if ($request instanceof Request) {
return $this->processRequest($request, $context);
}
$response = $cxml->getResponse();
- if ($response) {
+ if ($response instanceof Response) {
$this->processResponse($response, $context);
return null;
}
$message = $cxml->getMessage();
- if ($message) {
+ if ($message instanceof Message) {
$this->processMessage($message, $context);
return null;
@@ -160,7 +151,7 @@ public function process(CXml $cxml, Context $context = null): ?CXml
private function getHandlerForPayload(PayloadInterface $payload): HandlerInterface
{
- $handlerId = (new \ReflectionClass($payload))->getShortName();
+ $handlerId = (new ReflectionClass($payload))->getShortName();
return $this->handlerRegistry->get($handlerId);
}
@@ -171,8 +162,8 @@ private function getHandlerForPayload(PayloadInterface $payload): HandlerInterfa
*/
private function processMessage(Message $message, Context $context): void
{
- $header = $context->getCXml() ? $context->getCXml()->getHeader() : null;
- if (!$header) {
+ $header = $context->getCXml() instanceof CXml ? $context->getCXml()->getHeader() : null;
+ if (!$header instanceof Header) {
throw new CXmlException('Invalid CXml. Header is mandatory for message.');
}
@@ -180,7 +171,7 @@ private function processMessage(Message $message, Context $context): void
$this->headerProcessor->process($header, $context);
} catch (CXmlException $e) {
throw $e;
- } catch (\Throwable $e) {
+ } catch (Throwable $e) {
throw new CXmlProcessException($e);
}
@@ -189,7 +180,7 @@ private function processMessage(Message $message, Context $context): void
$this->getHandlerForPayload($payload)->handle($payload, $context);
} catch (CXmlException $e) {
throw $e;
- } catch (\Throwable $e) {
+ } catch (Throwable $e) {
throw new CXmlProcessException($e);
}
}
@@ -210,7 +201,7 @@ private function processResponse(Response $response, Context $context): void
$this->getHandlerForPayload($payload)->handle($payload, $context);
} catch (CXmlException $e) {
throw $e;
- } catch (\Throwable $e) {
+ } catch (Throwable $e) {
throw new CXmlProcessException($e);
}
}
@@ -221,8 +212,8 @@ private function processResponse(Response $response, Context $context): void
*/
private function processRequest(Request $request, Context $context): CXml
{
- $header = $context->getCXml() ? $context->getCXml()->getHeader() : null;
- if (!$header) {
+ $header = $context->getCXml() instanceof CXml ? $context->getCXml()->getHeader() : null;
+ if (!$header instanceof Header) {
throw new CXmlException('Invalid CXml. Header is mandatory for request.');
}
@@ -230,7 +221,7 @@ private function processRequest(Request $request, Context $context): CXml
$this->headerProcessor->process($header, $context);
} catch (CXmlException $e) {
throw $e;
- } catch (\Throwable $e) {
+ } catch (Throwable $e) {
throw new CXmlProcessException($e);
}
@@ -240,28 +231,26 @@ private function processRequest(Request $request, Context $context): CXml
$response = $handler->handle($payload, $context);
// if no response was returned, set an implicit 200/OK
- if (!$response) {
+ if (!$response instanceof ResponsePayloadInterface) {
$this->builder->status(new Status(
200,
- 'OK'
+ 'OK',
));
}
return $this->builder
->payload($response)
- ->build()
- ;
+ ->build();
}
public function buildResponseForException(CXmlException $exception): CXml
{
- $statusCode = self::$exceptionMapping[\get_class($exception)] ?? 500;
+ $statusCode = self::$exceptionMapping[$exception::class] ?? 500;
$statusText = self::$exceptionCodeMapping[$statusCode] ?? 'Unknown status';
$status = new Status($statusCode, $statusText, $exception->getMessage());
return $this->builder
->status($status)
- ->build()
- ;
+ ->build();
}
}
diff --git a/src/CXml/Serializer.php b/src/CXml/Serializer.php
index 2cb0376..c0fcf64 100644
--- a/src/CXml/Serializer.php
+++ b/src/CXml/Serializer.php
@@ -1,54 +1,57 @@
jmsSerializer = $jmsSerializer;
}
public static function create(): self
{
$jmsSerializer = SerializerBuilder::create()
- ->configureListeners(function (EventDispatcherInterface $dispatcher): void {
+ ->configureListeners(static function (EventDispatcherInterface $dispatcher): void {
$dispatcher->addSubscriber(new CXmlWrappingNodeJmsEventSubscriber());
})
- ->configureHandlers(function (HandlerRegistry $registry): void {
+ ->configureHandlers(static function (HandlerRegistry $registry): void {
$handler = new JmsDateTimeHandler();
+ $callable = static fn (XmlSerializationVisitor $visitor, DateTimeInterface $date, array $type, Context $context): DOMText => $handler->serialize($visitor, $date, $type, $context);
+ $registry->registerHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, DateTimeInterface::class, 'xml', $callable);
+ $registry->registerHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, DateTime::class, 'xml', $callable);
- $callable = [
- $handler,
- 'serialize',
- ];
- $registry->registerHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, \DateTimeInterface::class, 'xml', $callable);
- $registry->registerHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, \DateTime::class, 'xml', $callable);
-
- $callable = [
- $handler,
- 'deserialize',
- ];
- $registry->registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, \DateTimeInterface::class, 'xml', $callable);
- $registry->registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, \DateTime::class, 'xml', $callable);
+ $callable = static fn (XmlDeserializationVisitor $visitor, SimpleXMLElement $dateAsString, array $type, Context $context): DateTime|false => $handler->deserialize($visitor, $dateAsString, $type, $context);
+ $registry->registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, DateTimeInterface::class, 'xml', $callable);
+ $registry->registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, DateTime::class, 'xml', $callable);
})
->setPropertyNamingStrategy(
- new IdenticalPropertyNamingStrategy()
+ new IdenticalPropertyNamingStrategy(),
)
- ->build()
- ;
+ ->build();
return new self($jmsSerializer);
}
@@ -56,10 +59,10 @@ public static function create(): self
public function deserialize(string $xml): CXml
{
// remove doctype (if exists), as it would throw a JMS\Serializer\Exception\InvalidArgumentException
- $xml = \preg_replace('/]+?>/i', '', $xml);
+ $xml = preg_replace('/]+?>/i', '', $xml);
- if (empty($xml)) {
- throw new \RuntimeException('Cannot deserialize empty string');
+ if (null === $xml || '' === trim($xml)) {
+ throw new RuntimeException('Cannot deserialize empty string');
}
/* @phpstan-ignore-next-line */
@@ -70,10 +73,10 @@ public function serialize(CXml $cxml, string $docTypeVersion = '1.2.054'): strin
{
$xml = $this->jmsSerializer->serialize($cxml, 'xml');
- $docType = '';
+ $docType = '';
$xmlPrefix = '';
// add doctype, as it is mandatory in cXML
- return \str_replace($xmlPrefix, $xmlPrefix.$docType, $xml);
+ return str_replace($xmlPrefix, $xmlPrefix . $docType, $xml);
}
}
diff --git a/src/CXml/Validation/DtdValidator.php b/src/CXml/Validation/DtdValidator.php
index fac704e..3802923 100644
--- a/src/CXml/Validation/DtdValidator.php
+++ b/src/CXml/Validation/DtdValidator.php
@@ -1,22 +1,26 @@
pathToCxmlDtds = $pathToCxmlDtds;
+ Assertion::file($pathToCxmlDtds . '/cXML.dtd');
+ Assertion::file($pathToCxmlDtds . '/Fulfill.dtd');
+ Assertion::file($pathToCxmlDtds . '/Quote.dtd');
}
/**
@@ -24,14 +28,14 @@ public function __construct(string $pathToCxmlDtds)
*/
public function validateAgainstDtd(string $xml): void
{
- if (empty($xml)) {
+ if ('' === $xml || '0' === $xml) {
throw new CXmlInvalidException('XML was empty', $xml);
}
// disable throwing of php errors for libxml
- $internalErrors = \libxml_use_internal_errors(true);
+ $internalErrors = libxml_use_internal_errors(true);
- $old = new \DOMDocument();
+ $old = new DOMDocument();
$old->loadXML($xml);
$validateFiles = ['cXML.dtd', 'Fulfill.dtd', 'Quote.dtd'];
@@ -39,28 +43,28 @@ public function validateAgainstDtd(string $xml): void
$this->validateAgainstMultipleDtd($validateFiles, $old);
// reset throwing of php errors for libxml
- \libxml_use_internal_errors($internalErrors);
+ libxml_use_internal_errors($internalErrors);
}
/**
* @throws CXmlInvalidException
*/
- private function injectDtd(\DOMDocument $originalDomDocument, string $dtdFilename): \DOMDocument
+ private function injectDtd(DOMDocument $originalDomDocument, string $dtdFilename): DOMDocument
{
- $creator = new \DOMImplementation();
+ $creator = new DOMImplementation();
try {
- $doctype = $creator->createDocumentType('cXML', '', $this->pathToCxmlDtds.'/'.$dtdFilename);
+ $doctype = $creator->createDocumentType('cXML', '', $this->pathToCxmlDtds . '/' . $dtdFilename);
$new = $creator->createDocument('', '', $doctype);
- } catch (\DOMException $e) {
- throw new CXmlInvalidException($e->getMessage(), (string) $originalDomDocument->saveXML(), $e);
+ } catch (DOMException $domException) {
+ throw new CXmlInvalidException($domException->getMessage(), (string)$originalDomDocument->saveXML(), $domException);
}
$new->encoding = 'utf-8';
$oldNode = $originalDomDocument->getElementsByTagName('cXML')->item(0);
- if (!$oldNode) {
- throw new CXmlInvalidException('Missing cXML root node', (string) $originalDomDocument->saveXML());
+ if (null === $oldNode) {
+ throw new CXmlInvalidException('Missing cXML root node', (string)$originalDomDocument->saveXML());
}
$newNode = $new->importNode($oldNode, true);
@@ -72,7 +76,7 @@ private function injectDtd(\DOMDocument $originalDomDocument, string $dtdFilenam
/**
* @throws CXmlInvalidException
*/
- private function validateAgainstMultipleDtd(array $validateFiles, \DOMDocument $old): void
+ private function validateAgainstMultipleDtd(array $validateFiles, DOMDocument $old): void
{
foreach ($validateFiles as $validateFile) {
$dtdInjectedDomDocument = $this->injectDtd($old, $validateFile);
@@ -82,6 +86,6 @@ private function validateAgainstMultipleDtd(array $validateFiles, \DOMDocument $
}
}
- throw CXmlInvalidException::fromLibXmlError(\libxml_get_last_error(), (string) $old->saveXML());
+ throw CXmlInvalidException::fromLibXmlError(libxml_get_last_error(), (string)$old->saveXML());
}
}
diff --git a/src/CXml/Validation/Exception/CXmlInvalidException.php b/src/CXml/Validation/Exception/CXmlInvalidException.php
index be646f8..6160129 100644
--- a/src/CXml/Validation/Exception/CXmlInvalidException.php
+++ b/src/CXml/Validation/Exception/CXmlInvalidException.php
@@ -1,18 +1,21 @@
xml = $xml;
}
public function getXml(): string
@@ -23,15 +26,15 @@ public function getXml(): string
/** @phpstan-ignore-next-line */
public static function fromLibXmlError($libXmlError, string $xml): self
{
- if ($libXmlError instanceof \LibXMLError) {
- $message = \sprintf('%s at line %d, column %d. Code %s.', \trim($libXmlError->message), $libXmlError->line, $libXmlError->column, $libXmlError->code);
+ if ($libXmlError instanceof LibXMLError) {
+ $message = sprintf('%s at line %d, column %d. Code %s.', trim($libXmlError->message), $libXmlError->line, $libXmlError->column, $libXmlError->code);
} else {
$message = 'No LibXMLError was given.';
}
return new self(
$message,
- $xml
+ $xml,
);
}
}
diff --git a/tests/CXmlTest/Builder/OrderRequestBuilderTest.php b/tests/CXmlTest/Builder/OrderRequestBuilderTest.php
index a19a3fd..292ab51 100644
--- a/tests/CXmlTest/Builder/OrderRequestBuilderTest.php
+++ b/tests/CXmlTest/Builder/OrderRequestBuilderTest.php
@@ -1,5 +1,7 @@
deserialize($poomXml);
$orb = OrderRequestBuilder::fromPunchOutOrderMessage($poom->getMessage()->getPayload());
$actualOrderRequest = $orb
->billTo('name')
- ->build()
- ;
+ ->build();
$actualOrderRequest = Builder::create('cxml-php UserAgent', null, $this)
->payload($actualOrderRequest)
->from(new Credential('NetworkId', 'inbound@prominate-platform.com'))
->to(new Credential('NetworkId', 'supplier@supplier.com'))
->sender(new Credential('NetworkId', 'inbound@prominate-platform.com'))
- ->build()
- ;
+ ->build();
$actualOrderRequest = $serializer->serialize($actualOrderRequest);
- $expectedOrderRequest = \file_get_contents(__DIR__.'/fixtures/order_request.xml');
+ $expectedOrderRequest = file_get_contents(__DIR__ . '/fixtures/order_request.xml');
$this->assertXmlStringEqualsXmlString($expectedOrderRequest, $actualOrderRequest);
}
@@ -46,7 +50,7 @@ public function newPayloadIdentity(): PayloadIdentity
{
return new PayloadIdentity(
'933695160894',
- new \DateTime('2021-01-08T23:00:06-08:00')
+ new DateTime('2021-01-08T23:00:06-08:00'),
);
}
}
diff --git a/tests/CXmlTest/Handling/HandlerTest.php b/tests/CXmlTest/Handling/HandlerTest.php
new file mode 100644
index 0000000..db51c4b
--- /dev/null
+++ b/tests/CXmlTest/Handling/HandlerTest.php
@@ -0,0 +1,114 @@
+registerCredential(
+ new Credential(
+ 'NetworkId',
+ 'AN00000123',
+ ),
+ );
+ $credentialRepository->registerCredential(
+ new Credential(
+ 'NetworkId',
+ 'AN00000456',
+ ),
+ );
+
+ $authenticator = new SimpleSharedSecretAuthenticator('Secret!123');
+
+ $requestProcessor = new HeaderProcessor(
+ $credentialRepository,
+ $authenticator,
+ );
+
+ $actualHandlerCalled = '(none)';
+
+ $quoteMessageHandler = new class($actualHandlerCalled) implements HandlerInterface {
+ public function __construct(private string &$actualHandlerCalled)
+ {
+ }
+
+ public static function getRequestName(): string
+ {
+ return 'QuoteMessage';
+ }
+
+ public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface
+ {
+ $this->actualHandlerCalled = 'QuoteMessage';
+
+ return null;
+ }
+ };
+
+ $handlerRegistry = new HandlerRegistry();
+ $handlerRegistry->register($quoteMessageHandler);
+
+ $builder = Builder::create();
+
+ $processor = new Processor(
+ $requestProcessor,
+ $handlerRegistry,
+ $builder,
+ );
+
+ $endpoint = new Endpoint(
+ $serializer,
+ $messageValidator,
+ $processor,
+ );
+
+ $endpoint->parseAndProcessStringAsCXml($requestCxml);
+
+ $this->assertSame($expectedHandlerCalled, $actualHandlerCalled);
+ }
+}
diff --git a/tests/CXmlTest/Handling/fixtures/quote_request.xml b/tests/CXmlTest/Handling/fixtures/quote_request.xml
new file mode 100644
index 0000000..0e8e9b8
--- /dev/null
+++ b/tests/CXmlTest/Handling/fixtures/quote_request.xml
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+ AN00000123
+
+
+
+
+ AN00000456
+
+
+
+
+ AN00000123
+ Secret!123
+
+ Suppliers Super Order Processor
+
+
+
+
+
+
+
+ identity
+
+
+
+
+ 100.00
+
+
+
+
+ Acme Inc.
+
+ Acme Inc.
+ Joe Smith
+ 123 Anystreet
+ Sunnyvale
+ CA
+ 90489
+ United States
+
+
+
+ 1
+ 800
+ 1234567
+
+
+
+
+
+
+ Joe Smith
+ joe.smith@siemens.com
+
+
+
+ This is a comment
+ 2023-01-08T23:00:06-08:00
+
+
+
+
\ No newline at end of file
diff --git a/tests/CXmlTest/Model/OrderRequestTest.php b/tests/CXmlTest/Model/OrderRequestTest.php
index 755195a..9eb184d 100644
--- a/tests/CXmlTest/Model/OrderRequestTest.php
+++ b/tests/CXmlTest/Model/OrderRequestTest.php
@@ -1,5 +1,7 @@
dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.050/');
+ $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/');
}
public function testMinimumExample(): void
{
$from = new Credential(
'NetworkId',
- 'inbound@prominate-platform.com'
+ 'inbound@prominate-platform.com',
);
$to = new Credential(
'NetworkId',
- 'supplier@supplier.com'
+ 'supplier@supplier.com',
);
$sender = new Credential(
'NetworkId',
'inbound@prominate-platform.com',
- 'coyote'
+ 'coyote',
);
$orderRequestHeader = OrderRequestHeader::create(
'DO1234',
- new \DateTime('2000-10-12T18:41:29-08:00'),
+ new DateTime('2000-10-12T18:41:29-08:00'),
new ShipTo(
new Address(
new MultilanguageString('Acme'),
@@ -77,7 +81,7 @@ public function testMinimumExample(): void
null,
'CA',
'90489',
- 'default'
+ 'default',
),
null,
null,
@@ -86,11 +90,11 @@ public function testMinimumExample(): void
new TelephoneNumber(
new CountryCode('US', '1'),
'800',
- '5551212'
+ '5551212',
),
- 'personal'
- )
- )
+ 'personal',
+ ),
+ ),
),
new BillTo(
new Address(
@@ -105,7 +109,7 @@ public function testMinimumExample(): void
null,
null,
'42699',
- 'default'
+ 'default',
),
null,
null,
@@ -114,21 +118,21 @@ public function testMinimumExample(): void
new TelephoneNumber(
new CountryCode('DE', '49'),
'761',
- '1234567'
+ '1234567',
),
- 'company'
- )
- )
+ 'company',
+ ),
+ ),
),
new MoneyWrapper(
'EUR',
- 8500
- )
+ 8500,
+ ),
);
$orderRequestHeader->addComment(new Comment(null, null, null, 'delivery-note.pdf'));
$orderRequest = OrderRequest::create(
- $orderRequestHeader
+ $orderRequestHeader,
);
$item = ItemOut::create(
@@ -140,13 +144,13 @@ public function testMinimumExample(): void
'EA',
new MoneyWrapper(
'EUR',
- 210
+ 210,
),
[
- new Classification('custom', 0),
- ]
+ new Classification('custom', '0'),
+ ],
),
- new \DateTime('2020-02-28')
+ new DateTime('2020-02-28'),
);
$orderRequest->addItem($item);
@@ -159,13 +163,13 @@ public function testMinimumExample(): void
'EA',
new MoneyWrapper(
'EUR',
- 320
+ 320,
),
[
- new Classification('custom', 0),
- ]
+ new Classification('custom', '0'),
+ ],
),
- new \DateTime('2020-02-28')
+ new DateTime('2020-02-28'),
);
$orderRequest->addItem($item);
@@ -174,10 +178,9 @@ public function testMinimumExample(): void
->to($to)
->sender($sender)
->payload($orderRequest)
- ->build(CXml::DEPLOYMENT_TEST)
- ;
+ ->build(CXml::DEPLOYMENT_TEST);
- $this->assertEquals('OrderRequest_1625586002.193314.7293@dev', (string) $cxml);
+ $this->assertSame('OrderRequest_1625586002.193314.7293@dev', (string)$cxml);
$xml = Serializer::create()->serialize($cxml);
$this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/OrderRequest.xml', $xml);
@@ -189,7 +192,7 @@ public function newPayloadIdentity(): PayloadIdentity
{
return new PayloadIdentity(
'1625586002.193314.7293@dev',
- new \DateTime('2000-10-12T18:39:09-08:00')
+ new DateTime('2000-10-12T18:39:09-08:00'),
);
}
}
diff --git a/tests/CXmlTest/Model/ProductActivityMessageTest.php b/tests/CXmlTest/Model/ProductActivityMessageTest.php
index 5c77a7d..f8100a4 100644
--- a/tests/CXmlTest/Model/ProductActivityMessageTest.php
+++ b/tests/CXmlTest/Model/ProductActivityMessageTest.php
@@ -1,5 +1,7 @@
dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.050/');
+ $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/');
}
public function testMinimumExample(): void
{
$from = new Credential(
'NetworkId',
- 'AN00000123'
+ 'AN00000123',
);
$to = new Credential(
'NetworkId',
- 'AN00000456'
+ 'AN00000456',
);
$sender = new Credential(
'NetworkId',
'AN00000123',
- 'abracadabra'
+ 'abracadabra',
);
$productActivityMessage = ProductActivityMessage::create(
'CP12465192-1552965424130',
'SMI',
- new \DateTime('2019-02-20T14:39:48-08:00')
+ new DateTime('2019-02-20T14:39:48-08:00'),
)->addProductActivityDetail(
ProductActivityDetail::create(
new ItemId('SII99825', null, 'II99825'),
Inventory::create()->setStockOnHandQuantity(new InventoryQuantity(200, 'EA')),
Contact::create(new MultilanguageString('Warehouse', null, 'en'), 'locationFrom')
- ->addIdReference('NetworkId', '0003')
- )
+ ->addIdReference('NetworkId', '0003'),
+ ),
);
$cxml = Builder::create('Supplier’s Super Order Processor', 'en-US', $this)
@@ -64,10 +68,9 @@ public function testMinimumExample(): void
->to($to)
->sender($sender)
->payload($productActivityMessage)
- ->build()
- ;
+ ->build();
- $this->assertEquals('ProductActivityMessage_0c30050@supplierorg.com', (string) $cxml);
+ $this->assertSame('ProductActivityMessage_0c30050@supplierorg.com', (string)$cxml);
$xml = Serializer::create()->serialize($cxml);
$this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/ProductActivityMessage.xml', $xml);
@@ -79,7 +82,7 @@ public function newPayloadIdentity(): PayloadIdentity
{
return new PayloadIdentity(
'0c30050@supplierorg.com',
- new \DateTime('2021-01-08T23:00:06-08:00')
+ new DateTime('2021-01-08T23:00:06-08:00'),
);
}
}
diff --git a/tests/CXmlTest/Model/PunchOutSetupRequestTest.php b/tests/CXmlTest/Model/PunchOutSetupRequestTest.php
index 6a3b138..5cb98fd 100644
--- a/tests/CXmlTest/Model/PunchOutSetupRequestTest.php
+++ b/tests/CXmlTest/Model/PunchOutSetupRequestTest.php
@@ -1,5 +1,7 @@
dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.050/');
+ $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/');
}
public function testMinimumExample(): void
{
$from = new Credential(
'NetworkId',
- 'inbound@prominate-platform.com'
+ 'inbound@prominate-platform.com',
);
$to = new Credential(
'NetworkId',
- 'supplier@supplier.com'
+ 'supplier@supplier.com',
);
$sender = new Credential(
'NetworkId',
'inbound@prominate-platform.com',
- 's3cr3t'
+ 's3cr3t',
);
$punchoutSetupRequest = (new PunchOutSetupRequest(
@@ -77,7 +80,7 @@ public function testMinimumExample(): void
null,
'CA',
'90489',
- 'default'
+ 'default',
),
null,
null,
@@ -86,14 +89,14 @@ public function testMinimumExample(): void
new TelephoneNumber(
new CountryCode('US', '1'),
'800',
- '5551212'
+ '5551212',
),
- 'personal'
- )
- )
+ 'personal',
+ ),
+ ),
),
new SelectedItem(
- new ItemId('4545321', null, 'II99825')
+ new ItemId('4545321', null, 'II99825'),
),
))->addItem(
ItemOut::create(
@@ -106,10 +109,10 @@ public function testMinimumExample(): void
new MoneyWrapper('EUR', 76320),
[
new Classification('UNSPSC', 'ean1234'),
- ]
+ ],
),
- new \DateTime('2023-01-23T16:00:06-01:00'),
- )
+ new DateTime('2023-01-23T16:00:06-01:00'),
+ ),
)->addItem(
ItemOut::create(
20,
@@ -121,14 +124,14 @@ public function testMinimumExample(): void
new MoneyWrapper('EUR', 76420),
[
new Classification('UNSPSC', 'ean1230'),
- ]
+ ],
),
- new \DateTime('2023-01-23T16:00:06-01:00'),
- )
+ new DateTime('2023-01-23T16:00:06-01:00'),
+ ),
);
$punchoutSetupRequest->addExtrinsic(
- new Extrinsic('UserEmail', 'john-doe@domain.com')
+ new Extrinsic('UserEmail', 'john-doe@domain.com'),
);
$cxml = Builder::create('Workchairs cXML Application', 'en-US', $this)
@@ -136,23 +139,22 @@ public function testMinimumExample(): void
->to($to)
->sender($sender)
->payload($punchoutSetupRequest)
- ->build('test')
- ;
+ ->build('test');
- $this->assertEquals('PunchOutSetupRequest_933695160890', (string) $cxml);
+ $this->assertSame('PunchOutSetupRequest_933695160890', (string)$cxml);
$xml = Serializer::create()->serialize($cxml);
$this->dtdValidator->validateAgainstDtd($xml);
- $this->assertXmlStringEqualsXmlFile(__DIR__.'/../../metadata/cxml/samples/PunchOutSetupRequest.xml', $xml);
+ $this->assertXmlStringEqualsXmlFile(__DIR__ . '/../../metadata/cxml/samples/PunchOutSetupRequest.xml', $xml);
}
public function newPayloadIdentity(): PayloadIdentity
{
return new PayloadIdentity(
'933695160890',
- new \DateTime('2023-01-23T16:00:06-01:00')
+ new DateTime('2023-01-23T16:00:06-01:00'),
);
}
}
diff --git a/tests/CXmlTest/Model/PunchoutOrderMessageAdvancedPricingTest.php b/tests/CXmlTest/Model/PunchoutOrderMessageAdvancedPricingTest.php
index eb8bcf3..557ff6a 100644
--- a/tests/CXmlTest/Model/PunchoutOrderMessageAdvancedPricingTest.php
+++ b/tests/CXmlTest/Model/PunchoutOrderMessageAdvancedPricingTest.php
@@ -18,19 +18,21 @@
use CXml\Payload\PayloadIdentityFactoryInterface;
use CXml\Serializer;
use CXml\Validation\DtdValidator;
+use DateTime;
+use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
/**
* @internal
- * @coversNothing
*/
-class PunchoutOrderMessageAdvancedPricingTest extends TestCase implements PayloadIdentityFactoryInterface
+#[CoversNothing]
+final class PunchoutOrderMessageAdvancedPricingTest extends TestCase implements PayloadIdentityFactoryInterface
{
private DtdValidator $dtdValidator;
protected function setUp(): void
{
- $this->dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.050/');
+ $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/');
}
public function testMinimumExampleAdvPricing(): void
@@ -62,9 +64,9 @@ public function testMinimumExampleAdvPricing(): void
[
new Classification('UNSPSC', 'ean1234'),
],
- new PriceBasisQuantity(2, 0.5, 'BOX', new MultilanguageString('1 Box is 2 EA and the unit price is for 2', null, 'en'))
- )
- )
+ new PriceBasisQuantity(2, 0.5, 'BOX', new MultilanguageString('1 Box is 2 EA and the unit price is for 2', null, 'en')),
+ ),
+ ),
);
$cxml = Builder::create('Workchairs cXML Application', 'en-US', $this)
@@ -72,10 +74,9 @@ public function testMinimumExampleAdvPricing(): void
->to($to)
->sender($sender)
->payload($punchoutOrderMessage)
- ->build()
- ;
+ ->build();
- $this->assertEquals('PunchOutOrderMessage_933695160894', (string) $cxml);
+ $this->assertSame('PunchOutOrderMessage_933695160894', (string)$cxml);
$xml = Serializer::create()->serialize($cxml);
$this->dtdValidator->validateAgainstDtd($xml);
@@ -87,7 +88,7 @@ public function newPayloadIdentity(): PayloadIdentity
{
return new PayloadIdentity(
'933695160894',
- new \DateTime('2021-01-08T23:00:06-08:00')
+ new DateTime('2021-01-08T23:00:06-08:00'),
);
}
}
diff --git a/tests/CXmlTest/Model/PunchoutOrderMessageTest.php b/tests/CXmlTest/Model/PunchoutOrderMessageTest.php
index 5ab9990..67abe60 100644
--- a/tests/CXmlTest/Model/PunchoutOrderMessageTest.php
+++ b/tests/CXmlTest/Model/PunchoutOrderMessageTest.php
@@ -1,5 +1,7 @@
dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.050/');
+ $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/');
}
public function testMinimumExample(): void
@@ -59,9 +63,9 @@ public function testMinimumExample(): void
new MoneyWrapper('USD', 76320),
[
new Classification('UNSPSC', 'ean1234'),
- ]
- )
- )
+ ],
+ ),
+ ),
)->addPunchoutOrderMessageItem(
ItemIn::create(
5,
@@ -72,9 +76,9 @@ public function testMinimumExample(): void
new MoneyWrapper('USD', 76320),
[
new Classification('UNSPSC', 'ean1234'),
- ]
- )
- )
+ ],
+ ),
+ ),
);
$cxml = Builder::create('Workchairs cXML Application', 'en-US', $this)
@@ -82,10 +86,9 @@ public function testMinimumExample(): void
->to($to)
->sender($sender)
->payload($punchoutOrderMessage)
- ->build()
- ;
+ ->build();
- $this->assertEquals('PunchOutOrderMessage_933695160894', (string) $cxml);
+ $this->assertSame('PunchOutOrderMessage_933695160894', (string)$cxml);
$xml = Serializer::create()->serialize($cxml);
$this->dtdValidator->validateAgainstDtd($xml);
@@ -97,7 +100,7 @@ public function newPayloadIdentity(): PayloadIdentity
{
return new PayloadIdentity(
'933695160894',
- new \DateTime('2021-01-08T23:00:06-08:00')
+ new DateTime('2021-01-08T23:00:06-08:00'),
);
}
}
diff --git a/tests/CXmlTest/Model/QuoteMessageTest.php b/tests/CXmlTest/Model/QuoteMessageTest.php
index 2826850..b5ad51c 100644
--- a/tests/CXmlTest/Model/QuoteMessageTest.php
+++ b/tests/CXmlTest/Model/QuoteMessageTest.php
@@ -1,5 +1,7 @@
dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.050/');
+ $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/');
}
public function testMinimumExample(): void
{
$from = new Credential(
'NetworkId',
- 'AN00000123'
+ 'AN00000123',
);
$to = new Credential(
'NetworkId',
- 'AN00000456'
+ 'AN00000456',
);
$sender = new Credential(
'NetworkId',
'AN00000123',
- 'abracadabra'
+ 'abracadabra',
);
$organizationId = new OrganizationId(
new Credential(
'domain',
- 'identity'
- )
+ 'identity',
+ ),
);
$total = new MoneyWrapper('USD', 10000);
@@ -66,14 +70,13 @@ public function testMinimumExample(): void
$total,
QuoteMessageHeader::TYPE_ACCEPT,
'quoteId',
- new \DateTime('2021-01-08T23:00:06-08:00'),
- 'de'
+ new DateTime('2021-01-08T23:00:06-08:00'),
+ 'de',
);
$contact = Contact::create(new MultilanguageString('Joe Smith'))
->addEmail('joe.smith@siemens.com')
- ->addIdReference('GUID', '123456')
- ;
+ ->addIdReference('GUID', '123456');
$shipTo = new ShipTo(
new Address(
@@ -85,7 +88,7 @@ public function testMinimumExample(): void
new Country('US', 'United States'),
null,
'CA',
- '90489'
+ '90489',
),
null,
null,
@@ -94,29 +97,27 @@ public function testMinimumExample(): void
new TelephoneNumber(
new CountryCode('US', '1'),
'800',
- '1234567'
+ '1234567',
),
- 'company'
- )
- )
+ 'company',
+ ),
+ ),
);
$quoteMessage->getQuoteMessageHeader()
->addContact($contact)
->setShipTo($shipTo)
->addExtrinsicAsKeyValue('expiry_date', '2023-01-08T23:00:06-08:00')
- ->addCommentAsString('This is a comment')
- ;
+ ->addCommentAsString('This is a comment');
$cxml = Builder::create('Supplier’s Super Order Processor', 'en-US', $this)
->from($from)
->to($to)
->sender($sender)
->payload($quoteMessage)
- ->build()
- ;
+ ->build();
- $this->assertEquals('QuoteMessage_0c30050@supplierorg.com', (string) $cxml);
+ $this->assertSame('QuoteMessage_0c30050@supplierorg.com', (string)$cxml);
$xml = Serializer::create()->serialize($cxml);
$this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/QuoteMessage.xml', $xml);
@@ -128,7 +129,7 @@ public function newPayloadIdentity(): PayloadIdentity
{
return new PayloadIdentity(
'0c30050@supplierorg.com',
- new \DateTime('2021-01-08T23:00:06-08:00')
+ new DateTime('2021-01-08T23:00:06-08:00'),
);
}
}
diff --git a/tests/CXmlTest/Model/SerializerTest.php b/tests/CXmlTest/Model/SerializerTest.php
index ea3e77d..3e95e48 100644
--- a/tests/CXmlTest/Model/SerializerTest.php
+++ b/tests/CXmlTest/Model/SerializerTest.php
@@ -1,5 +1,7 @@
serialize($msg);
@@ -103,32 +108,32 @@ public function testSerializeSimpleRequest(): void
public function testSerializeSimpleMessage(): void
{
$from = new Party(
- new Credential('AribaNetworkUserId', 'admin@acme.com')
+ new Credential('AribaNetworkUserId', 'admin@acme.com'),
);
$to = new Party(
- new Credential('DUNS', '012345678')
+ new Credential('DUNS', '012345678'),
);
$sender = new Party(
new Credential('AribaNetworkUserId', 'sysadmin@buyer.com', 'abracadabra'),
- 'Network Hub 1.1'
+ 'Network Hub 1.1',
);
$message = new Message(
PunchOutOrderMessage::create(
'34234234ADFSDF234234',
- new PunchOutOrderMessageHeader(new MoneyWrapper('USD', 76320))
- )
+ new PunchOutOrderMessageHeader(new MoneyWrapper('USD', 76320)),
+ ),
);
$header = new Header(
$from,
$to,
- $sender
+ $sender,
);
$msg = CXml::forMessage(
- new PayloadIdentity('payload-id', new \DateTime('2000-01-01')),
+ new PayloadIdentity('payload-id', new DateTime('2000-01-01')),
$message,
- $header
+ $header,
);
$actualXml = Serializer::create()->serialize($msg);
@@ -176,12 +181,12 @@ public function testSerializeSimpleResponse(): void
$msg = CXml::forResponse(
new PayloadIdentity(
'978979621537--4882920031100014936@206.251.25.169',
- new \DateTime('2001-01-08T10:47:01-08:00')
+ new DateTime('2001-01-08T10:47:01-08:00'),
),
new Response(
new Status(200, 'OK', 'Ping Response CXml'),
- null
- )
+ null,
+ ),
);
$actualXml = Serializer::create()->serialize($msg);
@@ -271,10 +276,10 @@ public function testDeserializeWithDateTimeForDate(): void
/** @var OrderRequest $orderRequest */
$orderRequest = $cXml->getRequest()->getPayload();
- $this->assertEquals('2023-02-25 02:30:00', $orderRequest->getItems()[0]->getRequestedDeliveryDate()->format('Y-m-d H:i:s'));
- $this->assertInstanceOf(\DateTime::class, $orderRequest->getItems()[0]->getRequestedDeliveryDate());
+ $this->assertSame('2023-02-25 02:30:00', $orderRequest->getItems()[0]->getRequestedDeliveryDate()->format('Y-m-d H:i:s'));
+ $this->assertInstanceOf(DateTime::class, $orderRequest->getItems()[0]->getRequestedDeliveryDate());
- $this->assertEquals('2023-02-26', $orderRequest->getItems()[1]->getRequestedDeliveryDate()->format('Y-m-d'));
+ $this->assertSame('2023-02-26', $orderRequest->getItems()[1]->getRequestedDeliveryDate()->format('Y-m-d'));
$this->assertInstanceOf(Date::class, $orderRequest->getItems()[1]->getRequestedDeliveryDate());
$this->assertNull($orderRequest->getItems()[2]->getRequestedDeliveryDate());
@@ -282,7 +287,7 @@ public function testDeserializeWithDateTimeForDate(): void
public function testDeserializeInvalidDate(): void
{
- $this->expectException(\RuntimeException::class);
+ $this->expectException(RuntimeException::class);
$xmlIn =
'
@@ -305,14 +310,14 @@ public function testDeserializeInvalidDate(): void
public function testSerializeDateOnly(): void
{
$from = new Party(
- new Credential('AribaNetworkUserId', 'admin@acme.com')
+ new Credential('AribaNetworkUserId', 'admin@acme.com'),
);
$to = new Party(
- new Credential('DUNS', '012345678')
+ new Credential('DUNS', '012345678'),
);
$sender = new Party(
new Credential('AribaNetworkUserId', 'sysadmin@buyer.com', 'abracadabra'),
- 'Network Hub 1.1'
+ 'Network Hub 1.1',
);
$orderDate = new Date('2000-01-01');
@@ -320,21 +325,20 @@ public function testSerializeDateOnly(): void
$orderRequest =
OrderRequestBuilder::create('order-id', $orderDate, 'EUR')
->billTo('name')
- ->build()
- ;
+ ->build();
$header = new Header(
$from,
$to,
- $sender
+ $sender,
);
$msg = CXml::forRequest(
- new PayloadIdentity('payload-id', new \DateTime('2000-01-01')),
+ new PayloadIdentity('payload-id', new DateTime('2000-01-01')),
new Request(
- $orderRequest
+ $orderRequest,
),
- $header
+ $header,
);
$actualXml = Serializer::create()->serialize($msg);
diff --git a/tests/CXmlTest/Model/ShipNoticeRequestTest.php b/tests/CXmlTest/Model/ShipNoticeRequestTest.php
index f739361..160f04a 100644
--- a/tests/CXmlTest/Model/ShipNoticeRequestTest.php
+++ b/tests/CXmlTest/Model/ShipNoticeRequestTest.php
@@ -1,5 +1,7 @@
dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.050/');
+ $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/');
}
public function testMinimumExample(): void
{
$from = new Credential(
'NetworkId',
- 'AN00000123'
+ 'AN00000123',
);
$to = new Credential(
'NetworkId',
- 'AN00000456'
+ 'AN00000456',
);
$sender = new Credential(
'NetworkId',
'AN00000123',
- 'abracadabra'
+ 'abracadabra',
);
$statusUpdateRequest = ShipNoticeRequest::create(
ShipNoticeHeader::create(
'S2-123',
- new \DateTime('2000-10-14T18:39:09-08:00'),
- new \DateTime('2000-10-14T08:30:19-08:00'),
- new \DateTime('2000-10-18T09:00:00-08:00'),
+ new DateTime('2000-10-14T18:39:09-08:00'),
+ new DateTime('2000-10-14T08:30:19-08:00'),
+ new DateTime('2000-10-18T09:00:00-08:00'),
)
- ->addCommentAsString('Got it all into one shipment.', null, 'en-CA')
+ ->addCommentAsString('Got it all into one shipment.', null, 'en-CA'),
)
->addShipControl(
ShipControl::create(CarrierIdentifier::fromScacCode('FDE'), new ShipmentIdentifier('8202 8261 1194'))
- ->addCarrierIdentifier('companyName', 'Federal Express')
+ ->addCarrierIdentifier('companyName', 'Federal Express'),
)
->addShipNoticePortion(
- new ShipNoticePortion('32232995@hub.acme.com', 'DO1234')
- )
- ;
+ new ShipNoticePortion('32232995@hub.acme.com', 'DO1234'),
+ );
$cxml = Builder::create('Supplier’s Super Order Processor', 'en-US', $this)
->from($from)
->to($to)
->sender($sender)
->payload($statusUpdateRequest)
- ->build()
- ;
+ ->build();
- $this->assertEquals('ShipNoticeRequest_0c30050@supplierorg.com', (string) $cxml);
+ $this->assertSame('ShipNoticeRequest_0c30050@supplierorg.com', (string)$cxml);
$xml = Serializer::create()->serialize($cxml);
$this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/ShipNoticeRequest.xml', $xml);
@@ -83,7 +85,7 @@ public function newPayloadIdentity(): PayloadIdentity
{
return new PayloadIdentity(
'0c30050@supplierorg.com',
- new \DateTime('2021-01-08T23:00:06-08:00')
+ new DateTime('2021-01-08T23:00:06-08:00'),
);
}
}
diff --git a/tests/CXmlTest/Model/StatusUpdateRequestTest.php b/tests/CXmlTest/Model/StatusUpdateRequestTest.php
index d50aa51..df2fc92 100644
--- a/tests/CXmlTest/Model/StatusUpdateRequestTest.php
+++ b/tests/CXmlTest/Model/StatusUpdateRequestTest.php
@@ -1,5 +1,7 @@
dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.050/');
+ $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/');
}
public function testMinimumExample(): void
{
$from = new Credential(
'NetworkId',
- 'AN00000123'
+ 'AN00000123',
);
$to = new Credential(
'NetworkId',
- 'AN00000456'
+ 'AN00000456',
);
$sender = new Credential(
'NetworkId',
'AN00000123',
- 'abracadabra'
+ 'abracadabra',
);
$statusUpdateRequest = new StatusUpdateRequest(
new Status(200, 'OK', 'Forwarded to supplier', 'en-US'),
- '0c300508b7863dcclb_14999'
+ '0c300508b7863dcclb_14999',
);
$cxml = Builder::create('Supplier’s Super Order Processor', 'en-US', $this)
@@ -51,10 +55,9 @@ public function testMinimumExample(): void
->to($to)
->sender($sender)
->payload($statusUpdateRequest)
- ->build()
- ;
+ ->build();
- $this->assertEquals('StatusUpdateRequest_0c30050@supplierorg.com', (string) $cxml);
+ $this->assertSame('StatusUpdateRequest_0c30050@supplierorg.com', (string)$cxml);
$xml = Serializer::create()->serialize($cxml);
$this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/StatusUpdateRequest.xml', $xml);
@@ -66,7 +69,7 @@ public function newPayloadIdentity(): PayloadIdentity
{
return new PayloadIdentity(
'0c30050@supplierorg.com',
- new \DateTime('2021-01-08T23:00:06-08:00')
+ new DateTime('2021-01-08T23:00:06-08:00'),
);
}
}
diff --git a/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php b/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php
index 1de4b80..a3553a5 100644
--- a/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php
+++ b/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php
@@ -1,22 +1,25 @@
// 2022-04-22 08:00:00.400000 +00:00
- return \DateTime::createFromFormat('U.v', '1650614400.400');
- });
+ DateTime::createFromFormat('U.v', '1650614400.400'));
$actualIdentity = $pif->newPayloadIdentity();
$this->assertStringStartsWith('1650614400.400', $actualIdentity->getPayloadId());
diff --git a/tests/CXmlTest/Validation/MessageValidatorTest.php b/tests/CXmlTest/Validation/MessageValidatorTest.php
index 848c849..83ab82f 100644
--- a/tests/CXmlTest/Validation/MessageValidatorTest.php
+++ b/tests/CXmlTest/Validation/MessageValidatorTest.php
@@ -1,29 +1,34 @@
dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.050');
+ $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050');
}
public function testValidateSuccess(): void
{
$this->expectNotToPerformAssertions();
- $xml = \file_get_contents('tests/metadata/cxml/samples/simple-profile-request.xml');
+ $xml = file_get_contents('tests/metadata/cxml/samples/simple-profile-request.xml');
$this->dtdValidator->validateAgainstDtd($xml);
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..30172ea
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,9 @@
+