Skip to content

Commit

Permalink
refactor: run rector with boolean strict and add phpstan strict rules…
Browse files Browse the repository at this point in the history
…. php-cs with some strict rules
  • Loading branch information
ynnoig committed May 31, 2024
1 parent 30df470 commit 96d43f5
Show file tree
Hide file tree
Showing 130 changed files with 633 additions and 355 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
.idea
/.phpunit.result.cache
/.phpunit.cache
/.phpstan/
18 changes: 15 additions & 3 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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' => [
Expand All @@ -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)
;
19 changes: 15 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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
}
}
}
17 changes: 17 additions & 0 deletions phpstan.neon → phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -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/*
Expand Down
10 changes: 5 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<!-- <coverage>-->
<!-- <report>-->
<!-- <html outputDirectory="./.tmp/report" lowUpperBound="35" highLowerBound="70"/>-->
<!-- </report>-->
<!-- </coverage>-->
<coverage>
<report>
<html outputDirectory="./.tmp/report" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<testsuites>
<testsuite name="cXML Test Suite">
<directory>tests/</directory>
Expand Down
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
SetList::PRIVATIZATION,
SetList::EARLY_RETURN,
SetList::INSTANCEOF,
SetList::STRICT_BOOLEANS,
])
->withPhpSets()
;
2 changes: 2 additions & 0 deletions src/CXml/Authentication/AuthenticatorInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CXml\Authentication;

use CXml\Context;
Expand Down
2 changes: 2 additions & 0 deletions src/CXml/Authentication/SimpleSharedSecretAuthenticator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CXml\Authentication;

use CXml\Context;
Expand Down
12 changes: 7 additions & 5 deletions src/CXml/Builder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CXml;

use CXml\Exception\CXmlException;
Expand Down Expand Up @@ -101,7 +103,7 @@ private function buildHeader(): Header
return new Header(
new Party($this->from),
new Party($this->to),
new Party($this->sender, $this->senderUserAgent)
new Party($this->sender, $this->senderUserAgent),
);
}

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand Down
41 changes: 21 additions & 20 deletions src/CXml/Builder/OrderRequestBuilder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CXml\Builder;

use CXml\Model\Address;
Expand Down Expand Up @@ -58,7 +60,7 @@ public static function fromPunchOutOrderMessage(
string $currency = null,
string $orderId = null,
\DateTimeInterface $orderDate = null,
string $language = 'en'
string $language = 'en',
): self {
if (($supplierOrderInfo = $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getSupplierOrderInfo()) instanceof \CXml\Model\SupplierOrderInfo) {
$orderId ??= $supplierOrderInfo->getOrderId();
Expand All @@ -79,7 +81,7 @@ public static function fromPunchOutOrderMessage(
$orderId,
$orderDate,
$currency,
$language
$language,
);

$orb->setShipTo($punchOutOrderMessage->getPunchOutOrderMessageHeader()->getShipTo());
Expand All @@ -93,7 +95,7 @@ public static function fromPunchOutOrderMessage(
$item->getItemDetail()->getUnitPrice()->getMoney()->getValueCent(),
[
new Classification('custom', '0'), // TODO make this configurable
]
],
);
}

Expand All @@ -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(
Expand All @@ -119,8 +121,8 @@ public function billTo(
$email,
$phone,
$fax,
$url
)
$url,
),
);

return $this;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -221,7 +223,7 @@ public function addComment(string $value = null, string $type = null, string $la
$value,
$type,
$lang,
$attachmentUrl
$attachmentUrl,
);

return $this;
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -280,7 +281,7 @@ public function build(): OrderRequest
}

return OrderRequest::create(
$this->buildOrderRequestHeader()
$this->buildOrderRequestHeader(),
)->addItems($this->items);
}

Expand Down
9 changes: 5 additions & 4 deletions src/CXml/Builder/ProductActivityMessageBuilder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CXml\Builder;

use CXml\Model\Contact;
Expand Down Expand Up @@ -29,17 +31,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);
}
Expand Down
Loading

0 comments on commit 96d43f5

Please sign in to comment.