Skip to content

Commit 7ac6bb3

Browse files
authored
Merge pull request #10 from netlogix/feature/optimize
Feature/optimize
2 parents e5e833e + 6918d4f commit 7ac6bb3

30 files changed

Lines changed: 403 additions & 261 deletions

.github/workflows/ci.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ jobs:
1313
- { php: 7.4, phpunit: 9 }
1414
- { php: 8.0, phpunit: 10 }
1515
- { php: 8.1, phpunit: 10 }
16-
- { php: 8.2, phpunit: 10, main: true }
17-
- { php: 8.3, phpunit: 10, experimental: true }
16+
- { php: 8.2, phpunit: 10 }
17+
- { php: 8.3, phpunit: 10 }
18+
- { php: 8.4, phpunit: 10, main: true }
19+
- { php: 8.5, phpunit: 10 }
1820

1921
steps:
20-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@v6
2123
- name: Composer cache
22-
uses: actions/cache@v4
24+
uses: actions/cache@v5
2325
with:
2426
path: "vendor"
2527
key: ${{ runner.os }}-${{ matrix.env.php }}-composer-${{ hashFiles('composer.json') }}
@@ -67,5 +69,4 @@ jobs:
6769
path: code-coverage-results.md
6870

6971
- name: Behat tests
70-
run: composer run behat
71-
72+
run: composer run test:behat

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.idea/
22
vendor/
3-
composer.lock
3+
composer.lock
4+
.phpunit.result.cache
5+
.coverage

composer.json

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,65 @@
11
{
22
"name": "netlogix/xml-processor",
33
"description": "PHP XML-Processor based on XMLReader",
4+
"license": "MIT",
45
"homepage": "https://github.com/netlogix/XML-Processor",
5-
"support":{
6+
"support": {
7+
"issues": "https://github.com/netlogix/XML-Processor/issues",
68
"source": "https://github.com/netlogix/XML-Processor/",
7-
"docs": "https://github.com/netlogix/XML-Processor/blob/main/README.md",
8-
"issues": "https://github.com/netlogix/XML-Processor/issues"
9+
"docs": "https://github.com/netlogix/XML-Processor/blob/main/README.md"
910
},
10-
"license": "MIT",
1111
"require": {
1212
"php": "^7.4 || ^8.0",
13-
"ext-xmlreader": "*"
13+
"ext-xmlreader": "*",
14+
"symfony/polyfill-php80": ">=1.33.0"
1415
},
1516
"require-dev": {
1617
"behat/behat": "^3.12.0",
17-
"phpunit/phpunit": "^9.6.6"
18+
"ergebnis/composer-normalize": "^2.50",
19+
"phpunit/phpunit": "^9.6.6",
20+
"rector/rector": "^2.3"
1821
},
22+
"prefer-stable": true,
1923
"autoload": {
2024
"psr-4": {
2125
"Netlogix\\XmlProcessor\\": "src/"
2226
}
2327
},
2428
"autoload-dev": {
2529
"psr-4": {
26-
"Netlogix\\XmlProcessor\\Tests\\": "tests/",
27-
"Netlogix\\XmlProcessor\\Behat\\": "features/"
30+
"Netlogix\\XmlProcessor\\Behat\\": "features/",
31+
"Netlogix\\XmlProcessor\\Tests\\": "tests/"
2832
}
2933
},
30-
"scripts": {
31-
"behat": "behat"
34+
"config": {
35+
"allow-plugins": {
36+
"ergebnis/composer-normalize": true
37+
},
38+
"optimize-autoloader": true
3239
},
33-
"prefer-stable": true
40+
"scripts": {
41+
"apply-coding-standard": [
42+
"@composer:normalize:fix",
43+
"@rector:fix",
44+
"@format:fix"
45+
],
46+
"auto-scripts": {
47+
"cache:clear": "symfony-cmd",
48+
"assets:install %PUBLIC_DIR%": "symfony-cmd"
49+
},
50+
"composer:normalize": "@composer normalize --no-check-lock --dry-run",
51+
"composer:normalize:fix": "@composer normalize --no-check-lock",
52+
"format": "mago fmt --dry-run",
53+
"format:fix": "mago fmt",
54+
"lint": "mago lint",
55+
"rector": "rector process --dry-run",
56+
"rector:fix": "rector process",
57+
"test": [
58+
"@test:unit",
59+
"@test:behat"
60+
],
61+
"test:behat": "behat",
62+
"test:coverage": "XDEBUG_MODE=coverage phpunit --testdox --coverage-html .coverage",
63+
"test:unit": "phpunit --testdox --testsuite unit"
64+
}
3465
}

features/NodeProcessor/ArrayNodeProcessor.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Netlogix\XmlProcessor\NodeProcessor\Context\OpenContext;
77
use Netlogix\XmlProcessor\NodeProcessor\Context\TextContext;
88
use Netlogix\XmlProcessor\NodeProcessor\NodeProcessorInterface;
9+
use Netlogix\XmlProcessor\XmlProcessor;
910
use Netlogix\XmlProcessor\XmlProcessorContext;
1011

1112
class ArrayNodeProcessor implements NodeProcessorInterface, InvokeNodeProcessorInterface
@@ -30,13 +31,13 @@ private function removeParent(array $nodes): array
3031

3132
public function getSubscribedEvents(string $nodePath, XmlProcessorContext $context): iterable
3233
{
33-
yield 'NodeType_' . \XMLReader::ELEMENT => [$this, 'openElement'];
34-
yield 'NodeType_' . \XMLReader::TEXT => [$this, 'textElement'];
34+
yield XmlProcessor::NODE_TYPE_ELEMENT => [$this, 'openElement'];
35+
yield XmlProcessor::NODE_TYPE_TEXT => [$this, 'textElement'];
3536
}
3637

3738
public function openElement(OpenContext $context): void
3839
{
39-
$currentLevel = count($context->getNodePathArray());
40+
$currentLevel = \count($context->getNodePathArray());
4041
$newValue = [
4142
'node' => $context->getCurrentNodeName(),
4243
'level' => $currentLevel,

mago.toml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
php-version = "8.4"
2+
3+
[source]
4+
workspace = "."
5+
paths = [
6+
"src/",
7+
"tests/",
8+
# "importmap.php",
9+
"migrations/",
10+
]
11+
includes = ["vendor"]
12+
excludes = []
13+
14+
[formatter]
15+
print-width = 120
16+
tab-width = 4
17+
use-tabs = false
18+
preset = 'psr-12'
19+
excludes = []
20+
end-of-line = "Lf"
21+
single-quote = true
22+
empty-line-before-return = true
23+
24+
[linter]
25+
integrations = ["phpunit"]
26+
27+
[linter.rules]
28+
ambiguous-function-call = { enabled = false }
29+
literal-named-argument = { enabled = false }
30+
halstead = { effort-threshold = 7000 }
31+
final-controller = { enabled = false }
32+
no-boolean-flag-parameter = { enabled = false }
33+
34+
[analyzer]
35+
find-unused-definitions = true
36+
find-unused-expressions = false
37+
analyze-dead-code = false
38+
memoize-properties = true
39+
allow-possibly-undefined-array-keys = true
40+
perform-heuristic-checks = true
41+
check-throws = false
42+
check-missing-override = false
43+
find-unused-parameters = false
44+
strict-list-index-checks = false
45+
no-boolean-literal-comparison = false
46+
check-missing-type-hints = false
47+
register-super-globals = true

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</include>
1212
</coverage>
1313
<testsuites>
14-
<testsuite name="unit tests">
14+
<testsuite name="unit">
1515
<directory>tests/Unit</directory>
1616
</testsuite>
1717
</testsuites>

rector.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
4+
declare(strict_types=1);
5+
6+
use Rector\Config\RectorConfig;
7+
use Rector\PHPUnit\Set\PHPUnitSetList;
8+
use Rector\ValueObject\PhpVersion;
9+
10+
return RectorConfig::configure()
11+
->withPaths([
12+
__DIR__ . '/src',
13+
__DIR__ . '/tests',
14+
])
15+
// uncomment to reach your current PHP version
16+
->withPhpVersion(PhpVersion::PHP_74)
17+
->withSets([
18+
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES
19+
])
20+
->withImportNames(true, true, true, true)
21+
->withTypeCoverageLevel(0)
22+
->withDeadCodeLevel(0)
23+
->withCodeQualityLevel(0);

src/NodeProcessor/AbstractNodeProcessor.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
<?php
2-
declare(strict_types=1);
2+
3+
declare(strict_types = 1);
34

45
namespace Netlogix\XmlProcessor\NodeProcessor;
56

7+
use Exception;
8+
use Iterator;
69
use Netlogix\XmlProcessor\XmlProcessor;
710
use Netlogix\XmlProcessor\XmlProcessorContext;
811

912
class AbstractNodeProcessor implements NodeProcessorInterface
1013
{
1114
public function getNodePath(): string
1215
{
13-
$constName = get_class($this) . '::NODE_PATH';
16+
$constName = \get_class($this) . '::NODE_PATH';
1417
if (!defined($constName)) {
15-
throw new \Exception('NODE_PATH not defined in ' . static::class);
18+
throw new Exception('NODE_PATH not defined in ' . static::class);
1619
}
17-
return constant($constName);
20+
21+
return \constant($constName);
1822
}
1923

20-
public function getSubscribedEvents(string $nodePath, XmlProcessorContext $context): \Iterator
24+
public function getSubscribedEvents(string $nodePath, XmlProcessorContext $context): Iterator
2125
{
2226
if ($this->isNode($nodePath)) {
2327
if ($this instanceof OpenNodeProcessorInterface) {
24-
yield 'NodeType_' . \XMLReader::ELEMENT => [$this, 'openElement'];
28+
yield XmlProcessor::NODE_TYPE_ELEMENT => [$this, 'openElement'];
2529
}
2630
if ($this instanceof CloseNodeProcessorInterface) {
27-
yield 'NodeType_' . \XMLReader::END_ELEMENT => [$this, 'closeElement'];
31+
yield XmlProcessor::NODE_TYPE_END_ELEMENT => [$this, 'closeElement'];
2832
}
2933
if ($this instanceof TextNodeProcessorInterface) {
30-
yield 'NodeType_' . \XMLReader::TEXT => [$this, 'textElement'];
34+
yield XmlProcessor::NODE_TYPE_TEXT => [$this, 'textElement'];
3135
}
3236
}
3337
yield from [];

src/NodeProcessor/CloseNodeProcessorInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
declare(strict_types=1);
2+
3+
declare(strict_types = 1);
34

45
namespace Netlogix\XmlProcessor\NodeProcessor;
56

src/NodeProcessor/Context/CloseContext.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
declare(strict_types=1);
2+
3+
declare(strict_types = 1);
34

45
namespace Netlogix\XmlProcessor\NodeProcessor\Context;
56

0 commit comments

Comments
 (0)