Skip to content

Commit 2df303b

Browse files
committed
Update various files to prefer PHP 8.1 and PHPUnit 10.5 or 11.0, remove PHPStan and restructure tests
Various files have been updated to prefer PHP >=8.1 and PHPUnit >=10.5 or 11.0. The PHPStan tool has been removed. PHPUnit tests have been restructured using Attributes instead of DocBlocks. The service layer is expanded with new Exception classes and all Facades have been revised to better align with the library's intended functionality. Signed-off-by: Marcel Strahl <info@marcel-strahl.de>
1 parent 41ca2d6 commit 2df303b

30 files changed

+508
-499
lines changed

.php-cs-fixer.dist.php

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/*
3+
* This document has been generated with
4+
* https://mlocati.github.io/php-cs-fixer-configurator/#version:3.8.0|configurator
5+
* you can change this configuration by importing this file.
6+
*/
7+
$config = new PhpCsFixer\Config();
8+
return $config
9+
->setRiskyAllowed(true)
10+
->setRules([
11+
'@PSR2' => true,
12+
'array_indentation' => true,
13+
'array_syntax' => ['syntax'=>'short'],
14+
'blank_line_before_statement' => true,
15+
'single_space_around_construct' => false,
16+
'cast_spaces' => true,
17+
'concat_space' => ['spacing'=>'one'],
18+
'declare_equal_normalize' => true,
19+
'dir_constant' => true,
20+
'type_declaration_spaces' => true,
21+
'include' => true,
22+
'linebreak_after_opening_tag' => true,
23+
'lowercase_cast' => true,
24+
'lowercase_static_reference' => true,
25+
'magic_constant_casing' => true,
26+
'modernize_types_casting' => true,
27+
'native_function_casing' => true,
28+
'new_with_parentheses' => true,
29+
'no_alternative_syntax' => true,
30+
'no_closing_tag' => true,
31+
'no_empty_comment' => true,
32+
'no_empty_statement' => true,
33+
'no_extra_blank_lines' => true,
34+
'no_leading_import_slash' => true,
35+
'no_leading_namespace_whitespace' => true,
36+
'no_multiline_whitespace_around_double_arrow' => true,
37+
'no_null_property_initialization' => true,
38+
'no_short_bool_cast' => true,
39+
'no_singleline_whitespace_before_semicolons' => true,
40+
'no_spaces_around_offset' => true,
41+
'no_superfluous_elseif' => true,
42+
'no_trailing_comma_in_singleline' => true,
43+
'no_unneeded_control_parentheses' => true,
44+
'no_unneeded_braces' => true,
45+
'no_unneeded_final_method' => true,
46+
'no_unused_imports' => true,
47+
'no_useless_else' => true,
48+
'no_whitespace_before_comma_in_array' => true,
49+
'no_whitespace_in_blank_line' => true,
50+
'normalize_index_brace' => true,
51+
'object_operator_without_whitespace' => true,
52+
'ordered_imports' => true,
53+
'phpdoc_annotation_without_dot' => true,
54+
'phpdoc_indent' => true,
55+
'phpdoc_no_access' => true,
56+
'return_type_declaration' => true,
57+
'short_scalar_cast' => true,
58+
'simplified_null_return' => true,
59+
'blank_lines_before_namespace' => true,
60+
'single_quote' => true,
61+
'standardize_not_equals' => true,
62+
'strict_comparison' => true,
63+
'ternary_operator_spaces' => true,
64+
'ternary_to_null_coalescing' => true,
65+
'trim_array_spaces' => true,
66+
'unary_operator_spaces' => true,
67+
'visibility_required' => true,
68+
'whitespace_after_comma_in_array' => true,
69+
])
70+
->setFinder(PhpCsFixer\Finder::create()
71+
->exclude(['vendor', 'tests/Http/Responses/metadata'])
72+
->in(__DIR__)
73+
)
74+
;

.php-cs-fixer.php

-78
This file was deleted.

composer.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@
1212
}
1313
],
1414
"require": {
15-
"php": "^8.0",
15+
"php": ">=8.1",
1616
"ext-bcmath": "*"
1717
},
1818
"require-dev": {
19-
"friendsofphp/php-cs-fixer": "^3.13",
20-
"phpstan/phpstan": "^1.9",
21-
"phpstan/phpstan-phpunit": "^1.3",
22-
"phpstan/phpstan-webmozart-assert": "^1.2",
23-
"phpunit/phpunit": "^9.5",
19+
"friendsofphp/php-cs-fixer": "^3.51",
20+
"phpunit/phpunit": "^10.5 | ^11.0",
2421
"psalm/plugin-phpunit": "^0.18",
25-
"squizlabs/php_codesniffer": "^3.7",
22+
"squizlabs/php_codesniffer": "^3.9",
2623
"vimeo/psalm": "^5.4"
2724
},
2825
"autoload": {
@@ -41,7 +38,6 @@
4138
"cs-fix": "php-cs-fixer --using-cache=no fix",
4239
"test": "export XDEBUG_MODE=coverage && vendor/bin/phpunit --configuration phpunit.xml",
4340
"psalm": "vendor/bin/psalm --no-cache",
44-
"analyze": "vendor/bin/phpstan analyse --xdebug --configuration phpstan.neon.dist",
4541
"check": [
4642
"@phpcs",
4743
"@cs-check",

phpunit.xml

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" beStrictAboutCoversAnnotation="true" beStrictAboutOutputDuringTests="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTodoAnnotatedTests="true" verbose="true">
3-
<coverage processUncoveredFiles="true">
4-
<include>
5-
<directory suffix=".php">src</directory>
6-
</include>
7-
<exclude>
8-
<directory>./tests</directory>
9-
<directory>./vendor</directory>
10-
</exclude>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" beStrictAboutOutputDuringTests="true" beStrictAboutTestsThatDoNotTestAnything="true" cacheDirectory=".phpunit.cache" beStrictAboutCoverageMetadata="true">
3+
<coverage>
114
<report>
125
<clover outputFile="build/output/tests/coverage.xml"/>
136
<html outputDirectory="build/output/tests/report" lowUpperBound="35" highLowerBound="70"/>
@@ -23,4 +16,13 @@
2316
<testdoxHtml outputFile="build/output/tests/testdox.html"/>
2417
<testdoxText outputFile="build/output/tests/testdox.txt"/>
2518
</logging>
19+
<source>
20+
<include>
21+
<directory suffix=".php">src</directory>
22+
</include>
23+
<exclude>
24+
<directory>./tests</directory>
25+
<directory>./vendor</directory>
26+
</exclude>
27+
</source>
2628
</phpunit>

psalm.xml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"
77
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
findUnusedBaselineEntry="true"
9+
findUnusedCode="false"
810
>
911
<projectFiles>
1012
<directory name="src"/>

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ composer require marcel-strahl/price-calculator
2424
### Supported PHP Versions
2525
| PHP | Package Version | Status |
2626
|:-----:|:---------------:|:-------------:|
27-
| ^8.0 | v5.x.x | Support |
27+
| ^8.0 | v5.x.x | Support |
2828
| ^7.4 | v4.x.x | Not supported |
2929
| <^7.4 | <=v3.x.x | Not supported |
3030

src/Exceptions/PriceCalculatorFactoryException.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,18 @@
66

77
use InvalidArgumentException;
88

9+
use function sprintf;
10+
911
/**
10-
* Class PriceCalculatorFactoryException
1112
* @author Marcel Strahl <info@marcel-strahl.de>
12-
* @package MarcelStrahl\PriceCalculator\Exceptions
1313
*/
1414
class PriceCalculatorFactoryException extends InvalidArgumentException
1515
{
16-
/**
17-
* @param string $type
18-
* @return self
19-
*/
2016
public static function fromUnsupportedArgument(string $type): self
2117
{
22-
return new self(
23-
sprintf('The required currency translation is not currently supported. Type: %s', $type),
24-
500
25-
);
18+
return new self(
19+
sprintf('The required currency translation is not currently supported. Type: %s', $type),
20+
500
21+
);
2622
}
2723
}

src/Facade/VatCalculator.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
*/
1414
class VatCalculator
1515
{
16-
private function __construct(private Vat $vat, private PriceCalculatorInterface $priceCalculator) {}
16+
private function __construct(private Vat $vat, private PriceCalculatorInterface $priceCalculator)
17+
{
18+
}
1719

1820
public static function getVatCalculator(int $vat): VatCalculatorService
1921
{

src/Helpers/Entity/Price.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
*/
1010
class Price
1111
{
12-
private function __construct(private int $price) {}
12+
private function __construct(private int $price)
13+
{
14+
}
1315

1416
public static function create(int $price): self
1517
{

src/Helpers/Entity/Vat.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
*/
1212
class Vat implements VatInterface
1313
{
14-
private function __construct(private int $vat) {}
14+
private function __construct(private int $vat)
15+
{
16+
}
1517

1618
public static function create(int $vat): self
1719
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace MarcelStrahl\PriceCalculator\Tests\Exceptions;
5+
6+
use MarcelStrahl\PriceCalculator\Exceptions\PriceCalculatorFactoryException;
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\Attributes\Test;
9+
use PHPUnit\Framework\TestCase;
10+
11+
#[CoversClass(className: PriceCalculatorFactoryException::class)]
12+
final class PriceCalculatorFactoryExceptionTest extends TestCase
13+
{
14+
#[Test]
15+
public function canCreateException(): void
16+
{
17+
$exception = PriceCalculatorFactoryException::fromUnsupportedArgument('test');
18+
19+
$this->assertSame(500, $exception->getCode());
20+
$this->assertSame(
21+
'The required currency translation is not currently supported. Type: test',
22+
$exception->getMessage()
23+
);
24+
}
25+
}

tests/Facade/PriceCalculatorTest.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@
66

77
use MarcelStrahl\PriceCalculator\Facade\PriceCalculator as PriceCalculatorFacade;
88
use MarcelStrahl\PriceCalculator\PriceCalculatorInterface;
9+
use PHPUnit\Framework\Attributes\CoversClass;
10+
use PHPUnit\Framework\Attributes\Test;
911
use PHPUnit\Framework\TestCase;
1012

1113
/**
1214
* @author Marcel Strahl <info@marcel-strahl.de>
1315
*/
14-
class PriceCalculatorTest extends TestCase
16+
#[CoversClass(className: PriceCalculatorFacade::class)]
17+
final class PriceCalculatorTest extends TestCase
1518
{
16-
/**
17-
* @return void
18-
*/
19-
public function testCanInitPriceCalculatorFacade(): void
19+
#[Test]
20+
public function canInitPriceCalculatorFacade(): void
2021
{
2122
$facade = new PriceCalculatorFacade();
2223
$this->assertInstanceOf(PriceCalculatorFacade::class, $facade);
2324
}
2425

25-
/**
26-
* @return void
27-
*/
28-
public function testGetPriceCalculator(): void
26+
#[Test]
27+
public function canGetPriceCalculator(): void
2928
{
3029
$facade = new PriceCalculatorFacade();
3130
$priceCalculator = $facade::getPriceCalculator();

tests/Facade/UnitConverterTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@
55
namespace MarcelStrahl\PriceCalculator\Tests\Facade;
66

77
use MarcelStrahl\PriceCalculator\Facade\UnitConverter as UnitConverterFacade;
8+
use MarcelStrahl\PriceCalculator\UnitConverter;
89
use MarcelStrahl\PriceCalculator\UnitConverterInterface;
10+
use PHPUnit\Framework\Attributes\CoversClass;
11+
use PHPUnit\Framework\Attributes\Test;
12+
use PHPUnit\Framework\Attributes\UsesClass;
913
use PHPUnit\Framework\TestCase;
1014

1115
/**
12-
* Class UnitConverterTest
1316
* @author Marcel Strahl <info@marcel-strahl.de>
14-
* @package MarcelStrahl\PriceCalculator\Tests\Facade
1517
*/
16-
class UnitConverterTest extends TestCase
18+
#[CoversClass(className: UnitConverterFacade::class)]
19+
#[UsesClass(className: UnitConverter::class)]
20+
final class UnitConverterTest extends TestCase
1721
{
18-
/**
19-
* @return void
20-
*/
21-
public function testCanInitPriceCalculatorFacade(): void
22+
#[Test]
23+
public function canInitPriceCalculatorFacade(): void
2224
{
2325
$facade = new UnitConverterFacade();
2426
$this->assertInstanceOf(UnitConverterFacade::class, $facade);
2527
}
2628

27-
/**
28-
* @return void
29-
*/
30-
public function testCanGetUnitConverter(): void
29+
#[Test]
30+
public function canGetUnitConverter(): void
3131
{
3232
$facade = new UnitConverterFacade();
3333
$unitConverter = $facade::getConverter();

0 commit comments

Comments
 (0)