From 96d43f532c9a03b8d56a695eb5d7d5849a86d62f Mon Sep 17 00:00:00 2001 From: Giovanni Piemontese <22853912+ynnoig@users.noreply.github.com> Date: Fri, 31 May 2024 17:58:24 +0200 Subject: [PATCH] refactor: run rector with boolean strict and add phpstan strict rules. php-cs with some strict rules --- .gitignore | 1 + .php-cs-fixer.dist.php | 18 ++++- composer.json | 19 ++++- phpstan.neon => phpstan.dist.neon | 17 ++++ phpunit.xml.dist | 10 +-- rector.php | 1 + .../Authentication/AuthenticatorInterface.php | 2 + .../SimpleSharedSecretAuthenticator.php | 2 + src/CXml/Builder.php | 12 +-- src/CXml/Builder/OrderRequestBuilder.php | 41 +++++----- .../Builder/ProductActivityMessageBuilder.php | 9 ++- .../Builder/PunchOutOrderMessageBuilder.php | 35 +++++---- src/CXml/Context.php | 8 +- .../CredentialRepositoryInterface.php | 2 + src/CXml/Credential/Registry.php | 2 + .../Document/DocumentRegistryInterface.php | 2 + src/CXml/Endpoint.php | 10 ++- .../CXmlAuthenticationInvalidException.php | 2 + src/CXml/Exception/CXmlConflictException.php | 2 + .../CXmlCredentialInvalidException.php | 4 +- src/CXml/Exception/CXmlException.php | 2 + .../CXmlExpectationFailedException.php | 2 + .../Exception/CXmlNotAcceptableException.php | 2 + .../Exception/CXmlNotImplementedException.php | 2 + .../CXmlPreconditionFailedException.php | 2 + .../CXmlHandlerNotFoundException.php | 2 + src/CXml/Handler/HandlerInterface.php | 2 + src/CXml/Handler/HandlerRegistry.php | 4 +- src/CXml/Handler/HandlerRegistryInterface.php | 2 + .../SelfAwareProfileRequestHandler.php | 2 + ...icStartPagePunchOutSetupRequestHandler.php | 6 +- .../CXmlWrappingNodeJmsEventSubscriber.php | 10 ++- src/CXml/Jms/JmsDateTimeHandler.php | 18 +++-- src/CXml/Model/Address.php | 4 +- src/CXml/Model/BillTo.php | 4 +- src/CXml/Model/CXml.php | 6 +- src/CXml/Model/CarrierIdentifier.php | 4 +- src/CXml/Model/Classification.php | 4 +- src/CXml/Model/Comment.php | 6 +- src/CXml/Model/CommentsTrait.php | 5 +- src/CXml/Model/Contact.php | 4 +- src/CXml/Model/Country.php | 4 +- src/CXml/Model/CountryCode.php | 4 +- src/CXml/Model/Credential.php | 4 +- src/CXml/Model/Date.php | 4 +- src/CXml/Model/Description.php | 2 + src/CXml/Model/DocumentReference.php | 4 +- .../Exception/CXmlModelNotFoundException.php | 4 +- src/CXml/Model/Extrinsic.php | 4 +- src/CXml/Model/ExtrinsicsTrait.php | 2 + src/CXml/Model/Header.php | 4 +- src/CXml/Model/IdReference.php | 4 +- src/CXml/Model/IdReferencesTrait.php | 2 + src/CXml/Model/Inventory.php | 2 + src/CXml/Model/InventoryQuantity.php | 4 +- src/CXml/Model/ItemDetail.php | 4 +- src/CXml/Model/ItemId.php | 4 +- src/CXml/Model/ItemIn.php | 6 +- src/CXml/Model/ItemOut.php | 8 +- src/CXml/Model/Message/Message.php | 4 +- .../Model/Message/MessagePayloadInterface.php | 2 + .../Model/Message/ProductActivityDetail.php | 4 +- .../Model/Message/ProductActivityHeader.php | 4 +- .../Model/Message/ProductActivityMessage.php | 2 + .../Model/Message/PunchOutOrderMessage.php | 2 + .../Message/PunchOutOrderMessageHeader.php | 4 +- src/CXml/Model/Message/QuoteMessage.php | 4 +- src/CXml/Model/Message/QuoteMessageHeader.php | 4 +- src/CXml/Model/Money.php | 6 +- src/CXml/Model/MoneyWrapper.php | 2 + src/CXml/Model/MultilanguageString.php | 4 +- src/CXml/Model/Option.php | 4 +- src/CXml/Model/OrderReference.php | 6 +- src/CXml/Model/OrganizationId.php | 4 +- src/CXml/Model/Party.php | 4 +- src/CXml/Model/PayloadIdentity.php | 2 + src/CXml/Model/PayloadInterface.php | 2 + src/CXml/Model/Phone.php | 4 +- src/CXml/Model/PostalAddress.php | 4 +- src/CXml/Model/Request/ConfirmationHeader.php | 4 +- .../Model/Request/ConfirmationRequest.php | 4 +- src/CXml/Model/Request/OrderRequest.php | 4 +- src/CXml/Model/Request/OrderRequestHeader.php | 8 +- src/CXml/Model/Request/ProfileRequest.php | 2 + .../Model/Request/PunchOutSetupRequest.php | 4 +- src/CXml/Model/Request/Request.php | 4 +- .../Model/Request/RequestPayloadInterface.php | 2 + src/CXml/Model/Request/ShipNoticeHeader.php | 6 +- src/CXml/Model/Request/ShipNoticeRequest.php | 2 + .../Model/Request/StatusUpdateRequest.php | 8 +- src/CXml/Model/Response/ProfileResponse.php | 4 +- .../Model/Response/PunchOutSetupResponse.php | 4 +- src/CXml/Model/Response/Response.php | 4 +- .../Response/ResponsePayloadInterface.php | 2 + src/CXml/Model/Response/StatusResponse.php | 2 + src/CXml/Model/SelectedItem.php | 4 +- src/CXml/Model/ShipControl.php | 2 + src/CXml/Model/ShipNoticePortion.php | 6 +- src/CXml/Model/ShipTo.php | 2 + src/CXml/Model/ShipmentIdentifier.php | 4 +- src/CXml/Model/Shipping.php | 4 +- src/CXml/Model/ShippingContractNumber.php | 4 +- src/CXml/Model/Status.php | 4 +- src/CXml/Model/SupplierOrderInfo.php | 4 +- src/CXml/Model/Tax.php | 4 +- src/CXml/Model/TelephoneNumber.php | 4 +- src/CXml/Model/Transaction.php | 4 +- src/CXml/Model/TransportInformation.php | 4 +- src/CXml/Model/UnitOfMeasure.php | 4 +- src/CXml/Model/Url.php | 4 +- .../Payload/DefaultPayloadIdentityFactory.php | 6 +- .../PayloadIdentityFactoryInterface.php | 2 + .../Exception/CXmlProcessException.php | 4 +- src/CXml/Processor/HeaderProcessor.php | 4 +- src/CXml/Processor/Processor.php | 10 +-- src/CXml/Serializer.php | 13 ++-- src/CXml/Validation/DtdValidator.php | 18 +++-- .../Exception/CXmlInvalidException.php | 4 +- .../Builder/OrderRequestBuilderTest.php | 18 ++--- tests/CXmlTest/Model/OrderRequestTest.php | 63 +++++++-------- .../Model/ProductActivityMessageTest.php | 27 +++---- .../Model/PunchOutSetupRequestTest.php | 43 ++++++----- .../Model/PunchoutOrderMessageTest.php | 27 +++---- tests/CXmlTest/Model/QuoteMessageTest.php | 43 +++++------ tests/CXmlTest/Model/SerializerTest.php | 77 ++++++++++--------- .../CXmlTest/Model/ShipNoticeRequestTest.php | 30 ++++---- .../Model/StatusUpdateRequestTest.php | 23 +++--- .../DefaultPayloadIdentityFactoryTest.php | 6 +- .../Validation/MessageValidatorTest.php | 6 +- tests/bootstrap.php | 8 ++ 130 files changed, 633 insertions(+), 355 deletions(-) rename phpstan.neon => phpstan.dist.neon (60%) diff --git a/.gitignore b/.gitignore index edb4255..c831d98 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ composer.lock .idea /.phpunit.result.cache /.phpunit.cache +/.phpstan/ diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 7a3ada3..2cc62b3 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -4,7 +4,9 @@ use PhpCsFixer\Config; use PhpCsFixer\Finder; +use PhpCsFixer\Fixer\Comment\HeaderCommentFixer; use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer; +use PhpCsFixer\Runner\Parallel\ParallelConfig; $finder = Finder::create() ->in(__DIR__.'/src') @@ -14,11 +16,13 @@ $config = new Config(); return $config + ->setParallelConfig((new ParallelConfig())) ->setRiskyAllowed(true) ->setRules([ '@PSR2' => true, '@PSR1' => true, '@PhpCsFixer' => true, + '@PhpCsFixer:risky' => true, '@Symfony' => true, '@Symfony:risky' => false, 'native_function_invocation' => [ @@ -32,10 +36,18 @@ 'pow_to_exponentiation' => true, 'combine_nested_dirname' => true, 'phpdoc_separation' => false, + 'phpdoc_align' => ['align' => 'left'], '@PHP82Migration' => true, - 'global_namespace_import' => [ - 'import_classes' => false, - ], + 'global_namespace_import' => ['import_classes' => false], + '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/composer.json b/composer.json index 4dec267..a09496f 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,12 @@ "php-parallel-lint/php-parallel-lint": "*", "enlightn/security-checker": "*", "symfony/routing": "^4.4.44 || ^5.0.0 || ^6.0.0", - "rector/rector": "^1.1" + "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": { @@ -56,8 +61,14 @@ }, "scripts": { "test": "vendor/bin/phpunit --testdox tests", - "cs-check": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer check --allow-risky=yes --diff", - "cs-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": "vendor/bin/rector process" + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + } } } diff --git a/phpstan.neon b/phpstan.dist.neon similarity index 60% rename from phpstan.neon rename to phpstan.dist.neon index f1720bf..d728e57 100644 --- a/phpstan.neon +++ b/phpstan.dist.neon @@ -1,7 +1,24 @@ parameters: + type_coverage: + return_type: 100 + param_type: 98 + property_type: 100 + 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 index df8747c..5889b6e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,10 @@ - - - - - + + + + + tests/ diff --git a/rector.php b/rector.php index 3b4d6f5..7a0c57e 100644 --- a/rector.php +++ b/rector.php @@ -21,6 +21,7 @@ SetList::PRIVATIZATION, SetList::EARLY_RETURN, SetList::INSTANCEOF, + SetList::STRICT_BOOLEANS, ]) ->withPhpSets() ; 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 @@ from), new Party($this->to), - new Party($this->sender, $this->senderUserAgent) + new Party($this->sender, $this->senderUserAgent), ); } @@ -117,7 +119,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; @@ -127,7 +129,7 @@ public function build(string $deploymentMode = null): CXml $this->payloadIdentityFactory->newPayloadIdentity(), new Message($this->payload, $this->status), $this->buildHeader(), - $this->locale + $this->locale, ); break; @@ -143,7 +145,7 @@ public function build(string $deploymentMode = null): CXml $cXml = CXml::forResponse( $this->payloadIdentityFactory->newPayloadIdentity(), new Response($status, $this->payload), - $this->locale + $this->locale, ); break; @@ -153,7 +155,7 @@ public function build(string $deploymentMode = null): CXml $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 230fc85..2ee938b 100644 --- a/src/CXml/Builder/OrderRequestBuilder.php +++ b/src/CXml/Builder/OrderRequestBuilder.php @@ -1,5 +1,7 @@ getPunchOutOrderMessageHeader()->getSupplierOrderInfo()) instanceof \CXml\Model\SupplierOrderInfo) { $orderId ??= $supplierOrderInfo->getOrderId(); @@ -79,7 +81,7 @@ public static function fromPunchOutOrderMessage( $orderId, $orderDate, $currency, - $language + $language, ); $orb->setShipTo($punchOutOrderMessage->getPunchOutOrderMessageHeader()->getShipTo()); @@ -93,7 +95,7 @@ public static function fromPunchOutOrderMessage( $item->getItemDetail()->getUnitPrice()->getMoney()->getValueCent(), [ new Classification('custom', '0'), // TODO make this configurable - ] + ], ); } @@ -108,7 +110,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( @@ -119,8 +121,8 @@ public function billTo( $email, $phone, $fax, - $url - ) + $url, + ), ); return $this; @@ -130,14 +132,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) { @@ -184,7 +186,7 @@ public function addItem( int $unitPrice, array $classifications, \DateTimeInterface $requestDeliveryDate = null, - ItemOut $parent = null + ItemOut $parent = null, ): self { $lineNumber = \count($this->items) + 1; @@ -196,17 +198,17 @@ public function addItem( new Description( $description, null, - $this->language + $this->language, ), $unitOfMeasure, new MoneyWrapper( $this->currency, - $unitPrice + $unitPrice, ), - $classifications + $classifications, ), $requestDeliveryDate, - $parent instanceof ItemOut ? $parent->getLineNumber() : null + $parent instanceof ItemOut ? $parent->getLineNumber() : null, ); $this->items[] = $item; @@ -221,7 +223,7 @@ public function addComment(string $value = null, string $type = null, string $la $value, $type, $lang, - $attachmentUrl + $attachmentUrl, ); return $this; @@ -231,7 +233,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); @@ -256,11 +258,10 @@ 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); @@ -280,7 +281,7 @@ public function build(): OrderRequest } 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 7bebfb8..a0f5005 100644 --- a/src/CXml/Builder/ProductActivityMessageBuilder.php +++ b/src/CXml/Builder/ProductActivityMessageBuilder.php @@ -1,5 +1,7 @@ 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); } diff --git a/src/CXml/Builder/PunchOutOrderMessageBuilder.php b/src/CXml/Builder/PunchOutOrderMessageBuilder.php index 611e0da..26bfd20 100644 --- a/src/CXml/Builder/PunchOutOrderMessageBuilder.php +++ b/src/CXml/Builder/PunchOutOrderMessageBuilder.php @@ -1,5 +1,7 @@ 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) { @@ -82,8 +84,8 @@ public function shipping(int $shipping, string $taxDescription): self new Description( $taxDescription, null, - $this->language - ) + $this->language, + ), ); return $this; @@ -97,8 +99,8 @@ public function tax(int $tax, string $taxDescription): self new Description( $taxDescription, null, - $this->language - ) + $this->language, + ), ); return $this; @@ -114,27 +116,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); } @@ -143,7 +144,7 @@ public function addPunchoutOrderMessageItem( $punchoutOrderMessageItem = ItemIn::create( $quantity, $itemId, - $itemDetail + $itemDetail, ); return $this->addItem($punchoutOrderMessageItem); @@ -167,7 +168,7 @@ public function build(): PunchOutOrderMessage new MoneyWrapper($this->currency, $this->total), $this->shipping, $this->tax, - $this->operationAllowed + $this->operationAllowed, ); if ($this->shipTo instanceof ShipTo) { @@ -180,7 +181,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 8ef1ad3..8ffbaaa 100644 --- a/src/CXml/Context.php +++ b/src/CXml/Context.php @@ -1,5 +1,7 @@ options[$key] ?? null; } @@ -53,7 +55,7 @@ public function setCXml(CXml $cxml): self public function getSenderUserAgent(): ?string { - $cxml = $this->getCxml(); + $cxml = $this->getCXml(); if (!$cxml instanceof CXml) { return null; } @@ -68,7 +70,7 @@ public function getSenderUserAgent(): ?string public function getPayloadId(): ?string { - $cxml = $this->getCxml(); + $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 @@ logger = $logger ?? new NullLogger(); } @@ -44,16 +46,16 @@ public function parseAndProcessStringAsCXml(string $xml, Context $context = null try { $cxml = $this->serializer->deserialize($xml); } catch (\RuntimeException $runtimeException) { - $this->logger->error('Error while deserializing xml to CXml: '.$runtimeException->getMessage(), ['xml' => $xml]); + $this->logger->error('Error while deserializing xml to CXml: ' . $runtimeException->getMessage(), ['xml' => $xml]); - throw new CXmlInvalidException('Error while deserializing xml: '.$runtimeException->getMessage(), $xml, $runtimeException); + throw new CXmlInvalidException('Error while deserializing xml: ' . $runtimeException->getMessage(), $xml, $runtimeException); } // process try { $result = $this->processor->process($cxml, $context); } catch (CXmlException $cXmlException) { - $this->logger->error('Error while processing valid CXml: '.$cXmlException->getMessage(), ['xml' => $xml]); + $this->logger->error('Error while processing valid CXml: ' . $cXmlException->getMessage(), ['xml' => $xml]); throw $cXmlException; } 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; } diff --git a/src/CXml/Exception/CXmlException.php b/src/CXml/Exception/CXmlException.php index 00e1c24..ff6c735 100644 --- a/src/CXml/Exception/CXmlException.php +++ b/src/CXml/Exception/CXmlException.php @@ -1,5 +1,7 @@ startPageUrl - ) + $this->startPageUrl, + ), ); } diff --git a/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php b/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php index fb134b1..0de65f8 100644 --- a/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php +++ b/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php @@ -1,5 +1,7 @@ getVisitor(); // this is the actual payload object of type MessagePayloadInterface - /* @phpstan-ignore-next-line */ + /** @phpstan-ignore-next-line */ $payload = $event->getObject()->getPayload(); if ($payload) { @@ -95,7 +97,7 @@ public function onPostSerializePayload(ObjectEvent $event): void // tell jms to add the payload value in a wrapped node $visitor->visitProperty( new StaticPropertyMetadata($event->getType()['name'], $cls, null), - $payload + $payload, ); } } @@ -119,7 +121,7 @@ public function onPreDeserializePayload(PreDeserializeEvent $event): void $serializedName = $payloadNode->getName(); $targetNamespace = (new \ReflectionClass($event->getType()['name']))->getNamespaceName(); - $cls = $targetNamespace.'\\'.$serializedName; + $cls = $targetNamespace . '\\' . $serializedName; if (!\class_exists($cls)) { throw new CXmlModelNotFoundException($serializedName); } @@ -128,7 +130,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 cc5f41c..d1b4c5f 100644 --- a/src/CXml/Jms/JmsDateTimeHandler.php +++ b/src/CXml/Jms/JmsDateTimeHandler.php @@ -1,5 +1,7 @@ __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 68c3947..d431c61 100644 --- a/src/CXml/Model/Address.php +++ b/src/CXml/Model/Address.php @@ -1,5 +1,7 @@ payloadId; + return $shortName . '_' . $this->payloadId; } public function getStatus(): ?Status diff --git a/src/CXml/Model/CarrierIdentifier.php b/src/CXml/Model/CarrierIdentifier.php index 716d3fb..0848ee8 100644 --- a/src/CXml/Model/CarrierIdentifier.php +++ b/src/CXml/Model/CarrierIdentifier.php @@ -1,5 +1,7 @@ attachment = $attachment ? new Url($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 3743da0..b44ad69 100644 --- a/src/CXml/Model/CommentsTrait.php +++ b/src/CXml/Model/CommentsTrait.php @@ -1,5 +1,7 @@ getComments()) { + $comments = $this->getComments(); + if (\is_array($comments)) { foreach ($comments as $comment) { $commentStrings[] = $comment->getValue(); } diff --git a/src/CXml/Model/Contact.php b/src/CXml/Model/Contact.php index 4c618fe..5092c6a 100644 --- a/src/CXml/Model/Contact.php +++ b/src/CXml/Model/Contact.php @@ -1,5 +1,7 @@ unitOfMeasure = new UnitOfMeasure($unitOfMeasure); } diff --git a/src/CXml/Model/ItemDetail.php b/src/CXml/Model/ItemDetail.php index 1e19b34..0b81856 100644 --- a/src/CXml/Model/ItemDetail.php +++ b/src/CXml/Model/ItemDetail.php @@ -1,5 +1,7 @@ operationAllowed = $operationAllowed ?? self::OPERATION_CREATE; diff --git a/src/CXml/Model/Message/QuoteMessage.php b/src/CXml/Model/Message/QuoteMessage.php index 7e769d3..d452d3c 100644 --- a/src/CXml/Model/Message/QuoteMessage.php +++ b/src/CXml/Model/Message/QuoteMessage.php @@ -1,5 +1,7 @@ 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 55ef881..1db582b 100644 --- a/src/CXml/Model/Message/QuoteMessageHeader.php +++ b/src/CXml/Model/Message/QuoteMessageHeader.php @@ -1,5 +1,7 @@ value = \number_format($this->valueCent / 100, 2, '.', ''); } @@ -30,6 +32,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 35468a0..a5c22f1 100644 --- a/src/CXml/Model/MoneyWrapper.php +++ b/src/CXml/Model/MoneyWrapper.php @@ -1,5 +1,7 @@ browserFormPost = new Url($browserFormPost); $this->supplierSetup = new Url($supplierSetup); diff --git a/src/CXml/Model/Request/Request.php b/src/CXml/Model/Request/Request.php index 07bf86f..c94ed35 100644 --- a/src/CXml/Model/Request/Request.php +++ b/src/CXml/Model/Request/Request.php @@ -1,5 +1,7 @@ noticeDate = $noticeDate ?? new \DateTime(); - $this->documentReference = $documentReference ? new DocumentReference($documentReference) : null; + $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 diff --git a/src/CXml/Model/Request/ShipNoticeRequest.php b/src/CXml/Model/Request/ShipNoticeRequest.php index 3b45711..346702d 100644 --- a/src/CXml/Model/Request/ShipNoticeRequest.php +++ b/src/CXml/Model/Request/ShipNoticeRequest.php @@ -1,5 +1,7 @@ documentReference = $documentReference ? new DocumentReference($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 46e5723..710a2cc 100644 --- a/src/CXml/Model/Response/ProfileResponse.php +++ b/src/CXml/Model/Response/ProfileResponse.php @@ -1,5 +1,7 @@ effectiveDate = $effectiveDate ?? new \DateTime(); } diff --git a/src/CXml/Model/Response/PunchOutSetupResponse.php b/src/CXml/Model/Response/PunchOutSetupResponse.php index 9a7d9f7..9d5a125 100644 --- a/src/CXml/Model/Response/PunchOutSetupResponse.php +++ b/src/CXml/Model/Response/PunchOutSetupResponse.php @@ -1,5 +1,7 @@ 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 e6b6d03..1c7a512 100644 --- a/src/CXml/Model/ShipTo.php +++ b/src/CXml/Model/ShipTo.php @@ -1,5 +1,7 @@ money = new Money($currency, $value); } diff --git a/src/CXml/Model/ShippingContractNumber.php b/src/CXml/Model/ShippingContractNumber.php index 97b620c..03a9eb5 100644 --- a/src/CXml/Model/ShippingContractNumber.php +++ b/src/CXml/Model/ShippingContractNumber.php @@ -1,5 +1,7 @@ money = new Money($currency, $value); } diff --git a/src/CXml/Model/TelephoneNumber.php b/src/CXml/Model/TelephoneNumber.php index aa8e8a7..e7fa3b5 100644 --- a/src/CXml/Model/TelephoneNumber.php +++ b/src/CXml/Model/TelephoneNumber.php @@ -1,5 +1,7 @@ format('U.v'), // include milliseconds \getmypid(), \mt_rand(1000, 9999), - \gethostname() + \gethostname(), ); } @@ -37,7 +39,7 @@ public function newPayloadIdentity(): PayloadIdentity 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 @@ 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 17305b8..e27ab7b 100644 --- a/src/CXml/Processor/HeaderProcessor.php +++ b/src/CXml/Processor/HeaderProcessor.php @@ -1,5 +1,7 @@ credentialRepository->getCredentialByDomainAndId( $testCredential->getDomain(), - $testCredential->getIdentity() + $testCredential->getIdentity(), ); } } diff --git a/src/CXml/Processor/Processor.php b/src/CXml/Processor/Processor.php index 97d4916..c970511 100644 --- a/src/CXml/Processor/Processor.php +++ b/src/CXml/Processor/Processor.php @@ -1,5 +1,7 @@ builder->status(new Status( 200, - 'OK' + 'OK', )); } return $this->builder ->payload($response) - ->build() - ; + ->build(); } public function buildResponseForException(CXmlException $exception): CXml @@ -240,7 +241,6 @@ public function buildResponseForException(CXmlException $exception): CXml return $this->builder ->status($status) - ->build() - ; + ->build(); } } diff --git a/src/CXml/Serializer.php b/src/CXml/Serializer.php index 755cb95..c2ec0f2 100644 --- a/src/CXml/Serializer.php +++ b/src/CXml/Serializer.php @@ -1,5 +1,7 @@ registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, \DateTime::class, 'xml', $callable); }) ->setPropertyNamingStrategy( - new IdenticalPropertyNamingStrategy() + new IdenticalPropertyNamingStrategy(), ) - ->build() - ; + ->build(); return new self($jmsSerializer); } @@ -51,7 +52,7 @@ public function deserialize(string $xml): CXml // remove doctype (if exists), as it would throw a JMS\Serializer\Exception\InvalidArgumentException $xml = \preg_replace('/]+?>/i', '', $xml); - if (empty($xml)) { + if (null === $xml || '' === \trim($xml)) { throw new \RuntimeException('Cannot deserialize empty string'); } @@ -63,10 +64,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 8c79e6f..7903667 100644 --- a/src/CXml/Validation/DtdValidator.php +++ b/src/CXml/Validation/DtdValidator.php @@ -1,5 +1,7 @@ pathToCxmlDtds = $pathToCxmlDtds; } @@ -50,17 +52,17 @@ private function injectDtd(\DOMDocument $originalDomDocument, string $dtdFilenam $creator = new \DOMImplementation(); try { - $doctype = $creator->createDocumentType('cXML', '', $this->pathToCxmlDtds.'/'.$dtdFilename); + $doctype = $creator->createDocumentType('cXML', '', $this->pathToCxmlDtds . '/' . $dtdFilename); $new = $creator->createDocument('', '', $doctype); } catch (\DOMException $domException) { - throw new CXmlInvalidException($domException->getMessage(), (string) $originalDomDocument->saveXML(), $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); @@ -82,6 +84,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 975d7a8..2446fa2 100644 --- a/src/CXml/Validation/Exception/CXmlInvalidException.php +++ b/src/CXml/Validation/Exception/CXmlInvalidException.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); + self::assertXmlStringEqualsXmlString($expectedOrderRequest, $actualOrderRequest); } 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/OrderRequestTest.php b/tests/CXmlTest/Model/OrderRequestTest.php index 755195a..94c4c1b 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( @@ -77,7 +79,7 @@ public function testMinimumExample(): void null, 'CA', '90489', - 'default' + 'default', ), null, null, @@ -86,11 +88,11 @@ public function testMinimumExample(): void new TelephoneNumber( new CountryCode('US', '1'), '800', - '5551212' + '5551212', ), - 'personal' - ) - ) + 'personal', + ), + ), ), new BillTo( new Address( @@ -105,7 +107,7 @@ public function testMinimumExample(): void null, null, '42699', - 'default' + 'default', ), null, null, @@ -114,21 +116,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 +142,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 +161,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,13 +176,12 @@ 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); + self::assertSame('OrderRequest_1625586002.193314.7293@dev', (string)$cxml); $xml = Serializer::create()->serialize($cxml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/OrderRequest.xml', $xml); + self::assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/OrderRequest.xml', $xml); $this->dtdValidator->validateAgainstDtd($xml); } @@ -189,7 +190,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..b6e3f70 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,13 +66,12 @@ public function testMinimumExample(): void ->to($to) ->sender($sender) ->payload($productActivityMessage) - ->build() - ; + ->build(); - $this->assertEquals('ProductActivityMessage_0c30050@supplierorg.com', (string) $cxml); + self::assertSame('ProductActivityMessage_0c30050@supplierorg.com', (string)$cxml); $xml = Serializer::create()->serialize($cxml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/ProductActivityMessage.xml', $xml); + self::assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/ProductActivityMessage.xml', $xml); $this->dtdValidator->validateAgainstDtd($xml); } @@ -79,7 +80,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..bc74887 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 +79,7 @@ public function testMinimumExample(): void null, 'CA', '90489', - 'default' + 'default', ), null, null, @@ -86,14 +88,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 +108,10 @@ public function testMinimumExample(): void new MoneyWrapper('EUR', 76320), [ new Classification('UNSPSC', 'ean1234'), - ] + ], ), new \DateTime('2023-01-23T16:00:06-01:00'), - ) + ), )->addItem( ItemOut::create( 20, @@ -121,14 +123,14 @@ public function testMinimumExample(): void new MoneyWrapper('EUR', 76420), [ new Classification('UNSPSC', 'ean1230'), - ] + ], ), 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 +138,22 @@ public function testMinimumExample(): void ->to($to) ->sender($sender) ->payload($punchoutSetupRequest) - ->build('test') - ; + ->build('test'); - $this->assertEquals('PunchOutSetupRequest_933695160890', (string) $cxml); + self::assertSame('PunchOutSetupRequest_933695160890', (string)$cxml); $xml = Serializer::create()->serialize($cxml); $this->dtdValidator->validateAgainstDtd($xml); - $this->assertXmlStringEqualsXmlFile(__DIR__.'/../../metadata/cxml/samples/PunchOutSetupRequest.xml', $xml); + self::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/PunchoutOrderMessageTest.php b/tests/CXmlTest/Model/PunchoutOrderMessageTest.php index 5ab9990..31582e2 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 +61,9 @@ public function testMinimumExample(): void new MoneyWrapper('USD', 76320), [ new Classification('UNSPSC', 'ean1234'), - ] - ) - ) + ], + ), + ), )->addPunchoutOrderMessageItem( ItemIn::create( 5, @@ -72,9 +74,9 @@ public function testMinimumExample(): void new MoneyWrapper('USD', 76320), [ new Classification('UNSPSC', 'ean1234'), - ] - ) - ) + ], + ), + ), ); $cxml = Builder::create('Workchairs cXML Application', 'en-US', $this) @@ -82,22 +84,21 @@ public function testMinimumExample(): void ->to($to) ->sender($sender) ->payload($punchoutOrderMessage) - ->build() - ; + ->build(); - $this->assertEquals('PunchOutOrderMessage_933695160894', (string) $cxml); + self::assertSame('PunchOutOrderMessage_933695160894', (string)$cxml); $xml = Serializer::create()->serialize($cxml); $this->dtdValidator->validateAgainstDtd($xml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/PunchoutOrderMessage.xml', $xml); + self::assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/PunchoutOrderMessage.xml', $xml); } 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..00e34be 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); @@ -67,13 +69,12 @@ public function testMinimumExample(): void QuoteMessageHeader::TYPE_ACCEPT, 'quoteId', new \DateTime('2021-01-08T23:00:06-08:00'), - 'de' + '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 +86,7 @@ public function testMinimumExample(): void new Country('US', 'United States'), null, 'CA', - '90489' + '90489', ), null, null, @@ -94,32 +95,30 @@ 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); + self::assertSame('QuoteMessage_0c30050@supplierorg.com', (string)$cxml); $xml = Serializer::create()->serialize($cxml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/QuoteMessage.xml', $xml); + self::assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/QuoteMessage.xml', $xml); $this->dtdValidator->validateAgainstDtd($xml); } @@ -128,7 +127,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..ace45bd 100644 --- a/tests/CXmlTest/Model/SerializerTest.php +++ b/tests/CXmlTest/Model/SerializerTest.php @@ -1,5 +1,7 @@ serialize($msg); @@ -97,38 +99,38 @@ public function testSerializeSimpleRequest(): void '; - $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); + self::assertXmlStringEqualsXmlString($expectedXml, $actualXml); } 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')), $message, - $header + $header, ); $actualXml = Serializer::create()->serialize($msg); @@ -168,7 +170,7 @@ public function testSerializeSimpleMessage(): void '; - $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); + self::assertXmlStringEqualsXmlString($expectedXml, $actualXml); } public function testSerializeSimpleResponse(): void @@ -176,12 +178,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); @@ -195,7 +197,7 @@ public function testSerializeSimpleResponse(): void '; - $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); + self::assertXmlStringEqualsXmlString($expectedXml, $actualXml); } public function testDeserialize(): void @@ -213,7 +215,7 @@ public function testDeserialize(): void $resultingXml = $serializer->serialize($cXml); - $this->assertXmlStringEqualsXmlString($xml, $resultingXml); + self::assertXmlStringEqualsXmlString($xml, $resultingXml); } /** @@ -242,7 +244,7 @@ public function testDeserializeWithMilliseconds(): void Ping Response CXml '; - $this->assertXmlStringEqualsXmlString($xmlOut, $actual); + self::assertXmlStringEqualsXmlString($xmlOut, $actual); } public function testDeserializeWithDateTimeForDate(): void @@ -271,13 +273,13 @@ 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()); + self::assertSame('2023-02-25 02:30:00', $orderRequest->getItems()[0]->getRequestedDeliveryDate()->format('Y-m-d H:i:s')); + self::assertInstanceOf(\DateTime::class, $orderRequest->getItems()[0]->getRequestedDeliveryDate()); - $this->assertEquals('2023-02-26', $orderRequest->getItems()[1]->getRequestedDeliveryDate()->format('Y-m-d')); - $this->assertInstanceOf(Date::class, $orderRequest->getItems()[1]->getRequestedDeliveryDate()); + self::assertSame('2023-02-26', $orderRequest->getItems()[1]->getRequestedDeliveryDate()->format('Y-m-d')); + self::assertInstanceOf(Date::class, $orderRequest->getItems()[1]->getRequestedDeliveryDate()); - $this->assertNull($orderRequest->getItems()[2]->getRequestedDeliveryDate()); + self::assertNull($orderRequest->getItems()[2]->getRequestedDeliveryDate()); } public function testDeserializeInvalidDate(): void @@ -305,14 +307,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 +322,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 Request( - $orderRequest + $orderRequest, ), - $header + $header, ); $actualXml = Serializer::create()->serialize($msg); @@ -377,7 +378,7 @@ public function testSerializeDateOnly(): void '; - $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); + self::assertXmlStringEqualsXmlString($expectedXml, $actualXml); } public function testDeserializeOneRowXml(): void @@ -389,6 +390,6 @@ public function testDeserializeOneRowXml(): void $resultingXml = $serializer->serialize($cXml); - $this->assertXmlStringEqualsXmlString($xml, $resultingXml); + self::assertXmlStringEqualsXmlString($xml, $resultingXml); } } diff --git a/tests/CXmlTest/Model/ShipNoticeRequestTest.php b/tests/CXmlTest/Model/ShipNoticeRequestTest.php index f739361..e89444f 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( @@ -52,29 +54,27 @@ public function testMinimumExample(): void 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); + self::assertSame('ShipNoticeRequest_0c30050@supplierorg.com', (string)$cxml); $xml = Serializer::create()->serialize($cxml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/ShipNoticeRequest.xml', $xml); + self::assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/ShipNoticeRequest.xml', $xml); $this->dtdValidator->validateAgainstDtd($xml); } @@ -83,7 +83,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..a290931 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,13 +53,12 @@ public function testMinimumExample(): void ->to($to) ->sender($sender) ->payload($statusUpdateRequest) - ->build() - ; + ->build(); - $this->assertEquals('StatusUpdateRequest_0c30050@supplierorg.com', (string) $cxml); + self::assertSame('StatusUpdateRequest_0c30050@supplierorg.com', (string)$cxml); $xml = Serializer::create()->serialize($cxml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/StatusUpdateRequest.xml', $xml); + self::assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/StatusUpdateRequest.xml', $xml); $this->dtdValidator->validateAgainstDtd($xml); } @@ -66,7 +67,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 09b3adc..743efbb 100644 --- a/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php +++ b/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php @@ -1,5 +1,7 @@ newPayloadIdentity(); - $this->assertStringStartsWith('1650614400.400', $actualIdentity->getPayloadId()); + self::assertStringStartsWith('1650614400.400', $actualIdentity->getPayloadId()); } } diff --git a/tests/CXmlTest/Validation/MessageValidatorTest.php b/tests/CXmlTest/Validation/MessageValidatorTest.php index 848c849..a1dca20 100644 --- a/tests/CXmlTest/Validation/MessageValidatorTest.php +++ b/tests/CXmlTest/Validation/MessageValidatorTest.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 testValidateSuccess(): void diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b3d9bbc..30172ea 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1 +1,9 @@