Skip to content

Commit

Permalink
Downgraded requirements to php7.4 and did some changes - Merge pull r…
Browse files Browse the repository at this point in the history
…equest #3 from FriendsOfCXML/php7.4

Downgraded requirements to php7.4 and did some changes
  • Loading branch information
ynnoig committed May 30, 2022
2 parents ec1b151 + d9206a4 commit e5f8113
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 68 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ on:

jobs:
validation:
name: "Static validation / PHP 8.0 - 8.1"
name: "Static PHP Validation"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: [
'7.4',
'8.0',
'8.1',
]
Expand Down Expand Up @@ -48,7 +49,7 @@ jobs:
run: composer validate

- name: Composer install
run: composer install --no-scripts --ignore-platform-reqs
run: composer install --no-scripts

- name: Run PHP Parallel Lint
run: vendor/bin/parallel-lint src/
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'random_api_migration' => true,
'pow_to_exponentiation' => true,
'combine_nested_dirname' => true,
'@PHP80Migration' => true,
'@PHP74Migration' => true,
'global_namespace_import' => [
'import_classes' => false,
],
Expand Down
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,26 @@
}
],
"require": {
"php": "^8.0",
"php": "^7.4 || ^8.0",
"ext-simplexml": "*",
"ext-dom": "*",
"ext-libxml": "*",
"beberlei/assert": "@stable",
"jms/serializer": "^3.17",
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/routing": "^5.4 || ^6.0",
"psr/log": "^1.0 || ^2.0 || ^3.0"
},
"suggest": {
"symfony/http-foundation": "If you want to use the Processor",
"symfony/routing": "If you want to use SelfAwareProfileRequestHandler"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.6.0",
"friendsofphp/php-cs-fixer": "^3.8",
"php-parallel-lint/php-parallel-lint": "^1.3",
"enlightn/security-checker": "^1.10"
"enlightn/security-checker": "^1.10",
"symfony/http-foundation": "^4.4",
"symfony/routing": "^4.4"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
# Status

| CXML Version | Status Test |
|---|---|
| 1.2.050 | OK |
| 1.2.053 | OK |
| CXML Version | Status Test |
|--------------|-------------|
| 1.2.050 | OK |
| 1.2.053 | OK |

# Getting Started

Expand Down Expand Up @@ -142,4 +142,4 @@ $result = $endpoint->parseAndProcessStringAsCXml($xmlString);
//you would have to handle the transport yourself
```
# Credits
- Markus Thielen (https://github.com/mathielen)
- Markus Thielen (https://github.com/mathielen)
3 changes: 3 additions & 0 deletions src/CXml/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function build(string $deploymentMode = null): CXml
{
switch (true) {
case $this->payload instanceof RequestInterface:
/** @noinspection PhpParamsInspection */
$cXml = CXml::forRequest(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Request($this->payload, $this->status, null, $deploymentMode),
Expand All @@ -107,6 +108,7 @@ public function build(string $deploymentMode = null): CXml
break;

case $this->payload instanceof MessageInterface:
/** @noinspection PhpParamsInspection */
$cXml = CXml::forMessage(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Message($this->payload, $this->status),
Expand All @@ -116,6 +118,7 @@ public function build(string $deploymentMode = null): CXml
break;

case $this->payload instanceof ResponseInterface:
/** @noinspection PhpParamsInspection */
$cXml = CXml::forResponse(
$this->payloadIdentityFactory->newPayloadIdentity(),
new Response($this->payload, $this->status),
Expand Down
3 changes: 2 additions & 1 deletion src/CXml/Builder/OrderRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use CXml\Model\AddressWrapper;
use CXml\Model\Comment;
use CXml\Model\Contact;
use CXml\Model\Description;
use CXml\Model\ItemDetail;
use CXml\Model\ItemId;
use CXml\Model\ItemOut;
Expand Down Expand Up @@ -128,7 +129,7 @@ public function addItem(
$quantity,
$itemId,
new ItemDetail(
new MultilanguageString(
new Description(
$description,
null,
$this->language
Expand Down
13 changes: 5 additions & 8 deletions src/CXml/Builder/ProductActivityMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function create(string $messageId, string $warehouseCodeDomain): s
return new self($messageId, $warehouseCodeDomain);
}

public function addProductActivityDetail(string $sku, string $warehouseCode, int $stockLevel, ?string $nextIntakeDate, ?int $nextIntakeQuantity): self
public function addProductActivityDetail(string $sku, string $warehouseCode, int $stockLevel, ?array $extrinsics = null): self
{
$inventory = Inventory::create()
->setStockOnHandQuantity(new InventoryQuantity($stockLevel, 'EA'))
Expand All @@ -42,13 +42,10 @@ public function addProductActivityDetail(string $sku, string $warehouseCode, int
->addIdReference($this->warehouseCodeDomain, $warehouseCode)
);

// TODO found not better way to transport this info
if ($nextIntakeDate) {
$activityDetail->addExtrinsic('next_intake_date', $nextIntakeDate);
}
// TODO found not better way to transport this info
if ($nextIntakeQuantity) {
$activityDetail->addExtrinsic('next_intake_quantity', (string) $nextIntakeQuantity);
if ($extrinsics) {
foreach ($extrinsics as $k => $v) {
$activityDetail->addExtrinsic($k, $v);
}
}

$this->productActivityMessage->addProductActivityDetail($activityDetail);
Expand Down
4 changes: 2 additions & 2 deletions src/CXml/Builder/PunchoutOrderMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace CXml\Builder;

use CXml\Model\Description;
use CXml\Model\ItemDetail;
use CXml\Model\ItemId;
use CXml\Model\ItemIn;
use CXml\Model\Message\PunchOutOrderMessage;
use CXml\Model\Message\PunchOutOrderMessageHeader;
use CXml\Model\MoneyWrapper;
use CXml\Model\MultilanguageString;

// TODO not yet final and completed
class PunchoutOrderMessageBuilder
Expand All @@ -35,7 +35,7 @@ public function addPunchoutOrderMessageItem(string $sku, int $quantity, string $
$punchoutOrderMessageItem = ItemIn::create(
$quantity,
new ItemId($sku, null, $sku),
new ItemDetail(new MultilanguageString($description, null, 'de'), $unitOfMeasure, new MoneyWrapper('EUR', $unitPrice)),
new ItemDetail(new Description($description, null, 'de'), $unitOfMeasure, new MoneyWrapper('EUR', $unitPrice)),
);

$this->punchOutOrderMessage->addPunchoutOrderMessageItem($punchoutOrderMessageItem);
Expand Down
1 change: 0 additions & 1 deletion src/CXml/Jms/JmsEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public function onPreDeserialize(PreDeserializeEvent $event): void

// manipulate metadata of payload on-the-fly to match xml

/** @var PropertyMetadata $propertyMetadata */
$propertyMetadata = new PropertyMetadata(
$event->getType()['name'],
'payload'
Expand Down
32 changes: 32 additions & 0 deletions src/CXml/Model/Description.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace CXml\Model;

use JMS\Serializer\Annotation as Ser;

class Description extends MultilanguageString
{
/**
* @Ser\SerializedName("ShortName")
* @Ser\XmlElement(cdata=false)
*/
private ?string $shortName = null;

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

public static function createWithShortName(string $shortName, ?string $type = null, string $lang = 'en'): self
{
$new = new self(null, $type, $lang);
$new->setShortname($shortName);

return $new;
}

public function setShortname(?string $shortName): void
{
$this->shortName = $shortName;
}
}
4 changes: 2 additions & 2 deletions src/CXml/Model/ItemDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ItemDetail
* @Ser\SerializedName("Description")
* @Ser\XmlElement (cdata=false)
*/
private mixed $description;
private Description $description;

/**
* @Ser\SerializedName("UnitOfMeasure")
Expand Down Expand Up @@ -51,7 +51,7 @@ class ItemDetail
*/
private ?string $url;

public function __construct(MultilanguageString|MultilanguageShortName $description, string $unitOfMeasure, MoneyWrapper $unitPrice, ?string $manufacturerPartId = null, ?string $manufacturerName = null, ?string $url = null)
public function __construct(Description $description, string $unitOfMeasure, MoneyWrapper $unitPrice, ?string $manufacturerPartId = null, ?string $manufacturerName = null, ?string $url = null)
{
$this->description = $description;
$this->unitOfMeasure = $unitOfMeasure;
Expand Down
4 changes: 2 additions & 2 deletions src/CXml/Model/ItemIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ItemIn
private function __construct(
int $quantity,
ItemId $itemId,
ItemDetail $itemDetail,
ItemDetail $itemDetail
) {
$this->quantity = $quantity;
$this->itemId = $itemId;
Expand All @@ -35,7 +35,7 @@ private function __construct(
public static function create(
int $quantity,
ItemId $itemId,
ItemDetail $itemDetail,
ItemDetail $itemDetail
): self {
return new self(
$quantity,
Expand Down
31 changes: 0 additions & 31 deletions src/CXml/Model/MultilanguageShortName.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/CXml/Model/MultilanguageString.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class MultilanguageString
{
/**
* @Ser\XmlValue(cdata=true)
* @Ser\XmlValue(cdata=false)
*/
private ?string $value;

Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Processor/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function processResponse(Model\Response $response, Context $context): vo
*/
private function processRequest(Model\Request $request, Context $context): CXml
{
$header = $context->getCXml()?->getHeader();
$header = $context->getCXml() ? $context->getCXml()->getHeader() : null;
if (!$header) {
throw new CXmlException('Invalid CXml. Header is mandatory for request message.');
}
Expand Down
4 changes: 3 additions & 1 deletion src/CXml/Validation/DtdValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ public function validateAgainstDtd(string $xml): void

/**
* @throws CxmlInvalidException
* @throws \DOMException
*/
private function injectDtd(\DOMDocument $originalDomDocument, string $dtdFilename): \DOMDocument
{
$creator = new \DOMImplementation();
$doctype = $creator->createDocumentType('cXML', '', $this->pathToCxmlDtds.'/'.$dtdFilename);
$new = $creator->createDocument(null, '', $doctype);
$new = $creator->createDocument('', '', $doctype);
$new->encoding = 'utf-8';

$oldNode = $originalDomDocument->getElementsByTagName('cXML')->item(0);
Expand All @@ -64,6 +65,7 @@ private function injectDtd(\DOMDocument $originalDomDocument, string $dtdFilenam

/**
* @throws CxmlInvalidException
* @throws \DOMException
*/
private function validateAgainstMultipleDtd(array $validateFiles, \DOMDocument $old): void
{
Expand Down
3 changes: 2 additions & 1 deletion src/CXml/Validation/Exception/CxmlInvalidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function getXml(): string
return $this->xml;
}

public static function fromLibXmlError(mixed $libXmlError, string $xml): self
/** @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);
Expand Down
5 changes: 3 additions & 2 deletions tests/CXmlTest/Model/OrderRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use CXml\Model\Comment;
use CXml\Model\Country;
use CXml\Model\Credential;
use CXml\Model\Description;
use CXml\Model\ItemDetail;
use CXml\Model\ItemId;
use CXml\Model\ItemOut;
Expand Down Expand Up @@ -99,7 +100,7 @@ public function testMinimumExample(): void
10,
new ItemId('1233244'),
new ItemDetail(
new MultilanguageString('hello from item 1'),
new Description('hello from item 1'),
'EA',
new MoneyWrapper(
'EUR',
Expand All @@ -115,7 +116,7 @@ public function testMinimumExample(): void
20,
new ItemId('1233245'),
new ItemDetail(
new MultilanguageString('hello from item 2'),
new Description('hello from item 2'),
'EA',
new MoneyWrapper(
'EUR',
Expand Down
6 changes: 3 additions & 3 deletions tests/CXmlTest/Model/PunchoutOrderMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use CXml\Model\Message\PunchOutOrderMessage;
use CXml\Model\Message\PunchOutOrderMessageHeader;
use CXml\Model\MoneyWrapper;
use CXml\Model\MultilanguageShortName;
use CXml\Model\Description;
use CXml\Model\PayloadIdentity;
use CXml\Payload\PayloadIdentityFactoryInterface;
use CXml\Validation\DtdValidator;
Expand Down Expand Up @@ -54,7 +54,7 @@ public function testMinimumExample(): void
3,
new ItemId('5555', null, 'KD5555'),
(new ItemDetail(
new MultilanguageShortName('Excelsior Desk Chair', null, 'en'),
Description::createWithShortName('Excelsior Desk Chair', null, 'en'),
'EA',
new MoneyWrapper('USD', 76320)
))->addClassification((new Classification('UNSPSC', 'ean1234')))
Expand All @@ -64,7 +64,7 @@ public function testMinimumExample(): void
5,
new ItemId('666', null, 'KD666'),
new ItemDetail(
new MultilanguageShortName('22Excelsior Desk Chair', null, 'en'),
Description::createWithShortName('22Excelsior Desk Chair', null, 'en'),
'EA',
new MoneyWrapper('USD', 76320)
)
Expand Down

0 comments on commit e5f8113

Please sign in to comment.