Skip to content

Commit

Permalink
Merge pull request #30 from FriendsOfCXML/feat/version-2
Browse files Browse the repository at this point in the history
cXML Version 2.0.0 (PHP 8.2+)
  • Loading branch information
mathielen committed Sep 11, 2024
2 parents 605a8de + 8b244a9 commit 8a14ffd
Show file tree
Hide file tree
Showing 139 changed files with 2,096 additions and 2,211 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: CI / Static

on:
push:
Expand All @@ -17,9 +17,6 @@ jobs:
fail-fast: false
matrix:
php-version: [
'7.4',
'8.0',
'8.1',
'8.2',
'8.3',
]
Expand All @@ -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

Expand All @@ -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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
vendor
composer.lock
.idea
.phpunit.result.cache
/.phpunit.result.cache
/.phpunit.cache
/.phpstan/
44 changes: 44 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfig;

$finder = Finder::create()
->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);
35 changes: 0 additions & 35 deletions .php-cs-fixer.php

This file was deleted.

33 changes: 23 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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
}
}
}
18 changes: 18 additions & 0 deletions phpstan.neon → phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -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/*
Expand Down
19 changes: 19 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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>-->
<testsuites>
<testsuite name="cXML Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
12 changes: 6 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
- Markus Thielen (https://github.com/mathielen)
43 changes: 43 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\JMSSetList;

return RectorConfig::configure()
->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,
);
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
9 changes: 4 additions & 5 deletions src/CXml/Authentication/SimpleSharedSecretAuthenticator.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?php

declare(strict_types=1);

namespace CXml\Authentication;

use CXml\Context;
use CXml\Exception\CXmlAuthenticationInvalidException;
use CXml\Model\Header;

class SimpleSharedSecretAuthenticator implements AuthenticatorInterface
readonly class SimpleSharedSecretAuthenticator implements AuthenticatorInterface
{
private string $sharedSecret;

public function __construct(string $sharedSecret)
public function __construct(private string $sharedSecret)
{
$this->sharedSecret = $sharedSecret;
}

public function authenticate(Header $header, Context $context): void
Expand Down
Loading

0 comments on commit 8a14ffd

Please sign in to comment.