Skip to content

Commit c73da29

Browse files
author
Jeroen de Graaf
committed
Add quality tools
1 parent fcd4b27 commit c73da29

File tree

8 files changed

+249
-1
lines changed

8 files changed

+249
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/var/
12
/vendor/
23
composer.lock

.php-cs-fixer.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$finder = (new PhpCsFixer\Finder())
6+
->in(['src', 'tests']);
7+
8+
return (new PhpCsFixer\Config())
9+
->setCacheFile('var/.php-cs-fixer.cache')
10+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
11+
->setRiskyAllowed(true)
12+
->setRules([
13+
'@PhpCsFixer' => true,
14+
'@Symfony' => true,
15+
'@PER-CS2.0' => true,
16+
'binary_operator_spaces' => false,
17+
'cast_spaces' => true,
18+
'concat_space' => ['spacing' => 'one'],
19+
'declare_strict_types' => true,
20+
'global_namespace_import' => [
21+
'import_classes' => true,
22+
'import_constants' => null,
23+
'import_functions' => null,
24+
],
25+
'multiline_whitespace_before_semicolons' => false,
26+
'phpdoc_align' => ['align' => 'left'],
27+
'phpdoc_order' => true,
28+
'phpdoc_to_comment' => false,
29+
'php_unit_test_class_requires_covers' => false,
30+
'single_line_throw' => false,
31+
'trailing_comma_in_multiline' => [
32+
'elements' => ['arrays', 'arguments', 'parameters'],
33+
],
34+
'void_return' => true,
35+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
36+
])
37+
->setFinder($finder);

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Gember
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

captainhook.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"pre-push": {
3+
"enabled": true,
4+
"actions": [
5+
{
6+
"action": "composer cs:dry-run"
7+
},
8+
{
9+
"action": "composer rector:dry-run"
10+
},
11+
{
12+
"action": "composer phpstan"
13+
},
14+
{
15+
"action": "composer dependency-analyser"
16+
},
17+
{
18+
"action": "composer phpunit"
19+
},
20+
{
21+
"action": "composer coverage"
22+
}
23+
]
24+
}
25+
}

composer.json

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,62 @@
33
"description": "Let go of the Aggregate - EventSourcing in PHP with DCB (Dynamic Consistency Boundary)",
44
"license": "MIT",
55
"type": "library",
6+
"keywords": [
7+
"gember",
8+
"event-sourcing",
9+
"domain-driven-design",
10+
"ddd",
11+
"dynamic-consistency-boundary",
12+
"dcb"
13+
],
614
"authors": [
715
{
816
"name": "Jeroen de Graaf",
9-
"email": "gember@jero.work"
17+
"email": "gember@jero.work",
18+
"homepage": "https://jero.work"
1019
}
1120
],
1221
"require": {
1322
"php": "^8.3"
1423
},
24+
"require-dev": {
25+
"captainhook/captainhook": "^5.23",
26+
"friendsofphp/php-cs-fixer": "^3.64",
27+
"phpstan/phpstan": "^1.12",
28+
"phpunit/phpunit": "^11.3",
29+
"rector/rector": "^1.2",
30+
"rregeer/phpunit-coverage-check": "^0.3.1",
31+
"shipmonk/composer-dependency-analyser": "^1.7"
32+
},
1533
"autoload": {
1634
"psr-4": {
1735
"Gember\\EventSourcing\\": "src/"
1836
}
37+
},
38+
"autoload-dev": {
39+
"psr-4": {
40+
"Gember\\EventSourcing\\Test\\": "tests/"
41+
}
42+
},
43+
"config": {
44+
"sort-packages": true
45+
},
46+
"scripts": {
47+
"coverage": "vendor/bin/coverage-check var/coverage/clover.xml 95",
48+
"cs": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php",
49+
"cs:dry-run": "vendor/bin/php-cs-fixer fix --diff --dry-run --config=.php-cs-fixer.php",
50+
"dependency-analyser": "vendor/bin/composer-dependency-analyser",
51+
"phpstan": "vendor/bin/phpstan analyse -c phpstan.neon",
52+
"phpunit": "XDEBUG_MODE=coverage vendor/bin/phpunit",
53+
"rector": "vendor/bin/rector process --ansi",
54+
"rector:dry-run": "vendor/bin/rector process --ansi --dry-run",
55+
"test": [
56+
"@rector:dry-run",
57+
"@cs:dry-run",
58+
"@phpstan",
59+
"@dependency-analyser",
60+
"@phpunit",
61+
"@coverage"
62+
]
1963
}
2064
}

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: max
3+
paths:
4+
- src/
5+
- tests/

phpunit.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
cacheDirectory="var/.phpunit.cache"
7+
executionOrder="depends,defects"
8+
requireCoverageMetadata="false"
9+
beStrictAboutCoverageMetadata="false"
10+
beStrictAboutOutputDuringTests="true"
11+
failOnRisky="true"
12+
failOnWarning="true">
13+
<testsuites>
14+
<testsuite name="default">
15+
<directory>tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
<coverage includeUncoveredFiles="true">
19+
<report>
20+
<clover outputFile="var/coverage/clover.xml"/>
21+
<html outputDirectory="var/coverage/html-coverage"/>
22+
</report>
23+
</coverage>
24+
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
25+
<include>
26+
<directory>src</directory>
27+
</include>
28+
</source>
29+
</phpunit>

rector.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\FuncCall\RemoveSoleValueSprintfRector;
6+
use Rector\CodeQuality\Rector\FuncCall\UnwrapSprintfOneArgumentRector;
7+
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
8+
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
9+
use Rector\Config\RectorConfig;
10+
use Rector\DeadCode\Rector\Array_\RemoveDuplicatedArrayKeyRector;
11+
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
12+
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
13+
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
14+
use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector;
15+
use Rector\DeadCode\Rector\If_\ReduceAlwaysFalseIfOrRector;
16+
use Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
17+
use Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector;
18+
use Rector\DeadCode\Rector\Property\RemoveUselessReadOnlyTagRector;
19+
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
20+
use Rector\DeadCode\Rector\Ternary\TernaryToBooleanOrFalseToBooleanAndRector;
21+
use Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector;
22+
use Rector\Php80\Rector\ClassConstFetch\ClassOnThisVariableObjectRector;
23+
use Rector\Php80\Rector\FuncCall\ClassOnObjectRector;
24+
use Rector\Php80\Rector\Identical\StrEndsWithRector;
25+
use Rector\Php80\Rector\Identical\StrStartsWithRector;
26+
use Rector\Php80\Rector\NotIdentical\StrContainsRector;
27+
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
28+
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
29+
use Rector\Php82\Rector\Class_\ReadOnlyClassRector;
30+
use Rector\Php83\Rector\ClassConst\AddTypeToConstRector;
31+
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
32+
use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector;
33+
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
34+
35+
$config = RectorConfig::configure()
36+
->withCache(__DIR__ . '/var/rector')
37+
->withPaths([
38+
__DIR__ . '/src',
39+
])
40+
->withParallel()
41+
->withRules([
42+
// Misc
43+
PrivatizeFinalClassPropertyRector::class,
44+
PrivatizeFinalClassMethodRector::class,
45+
UnwrapSprintfOneArgumentRector::class,
46+
RemoveSoleValueSprintfRector::class,
47+
CountArrayToEmptyArrayComparisonRector::class,
48+
// See withConfiguredRule below for more
49+
50+
// Misc - Deadcode
51+
RemoveUnusedForeachKeyRector::class,
52+
RemoveDuplicatedArrayKeyRector::class,
53+
RecastingRemovalRector::class,
54+
RemoveUnusedNonEmptyArrayBeforeForeachRector::class,
55+
TernaryToBooleanOrFalseToBooleanAndRector::class,
56+
RemoveUselessParamTagRector::class,
57+
RemoveUselessReturnTagRector::class,
58+
RemoveUselessReadOnlyTagRector::class,
59+
RemoveNonExistingVarAnnotationRector::class,
60+
RemoveUselessVarTagRector::class,
61+
ReduceAlwaysFalseIfOrRector::class,
62+
63+
// PHP 8.0
64+
ClassOnThisVariableObjectRector::class,
65+
ClassOnObjectRector::class,
66+
StrStartsWithRector::class,
67+
StrEndsWithRector::class,
68+
StrContainsRector::class,
69+
RemoveUnusedVariableInCatchRector::class,
70+
71+
// PHP 8.1
72+
ReadOnlyPropertyRector::class,
73+
FirstClassCallableRector::class,
74+
75+
// PHP 8.2
76+
ReadOnlyClassRector::class,
77+
78+
// PHP 8.3
79+
AddTypeToConstRector::class,
80+
AddOverrideAttributeToOverriddenMethodsRector::class,
81+
])
82+
->withConfiguredRule(SimplifyUselessVariableRector::class, [
83+
SimplifyUselessVariableRector::ONLY_DIRECT_ASSIGN => true,
84+
]);
85+
86+
return $config;

0 commit comments

Comments
 (0)