Skip to content

Commit

Permalink
Bump minimal required PHP version to 8.1 (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Feb 6, 2025
1 parent eff507e commit 4cdcc85
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['8.0', '8.1', '8.2', '8.3']
['8.1', '8.2', '8.3']
2 changes: 1 addition & 1 deletion .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1', '8.2', '8.3']
['8.1', '8.2', '8.3']
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1', '8.2', '8.3']
['8.1', '8.2', '8.3']
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ composer.phar
# Mac DS_Store Files
.DS_Store

# phpunit itself is not needed
phpunit.phar
# local phpunit config
# PHPUnit
/phpunit.phar
/phpunit.xml
# phpunit cache
.phpunit.result.cache
/.phpunit.cache
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.5.1 under development

- Bug #138: Explicitly mark nullable parameters (@ferrumfist)
- Chg #140: Bump minimal required PHP version to 8.1 and minor refactoring (@vjik)

## 2.5.0 January 19, 2025

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The package provides:

## Requirements

- PHP 8.0 or higher.
- PHP 8.1 or higher.
- `mbstring` PHP extension.

## Installation
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-mbstring": "*"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.2",
"phpunit/phpunit": "^9.5",
"maglnet/composer-require-checker": "^4.7.1",
"phpunit/phpunit": "^10.5.44",
"rector/rector": "^2.0.7",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.25"
"roave/infection-static-analysis-plugin": "^1.35",
"spatie/phpunit-watcher": "^1.24",
"vimeo/psalm": "^5.26.1"
},
"autoload": {
"psr-4": {
Expand All @@ -51,6 +51,7 @@
},
"config": {
"sort-packages": true,
"bump-after-update": "dev",
"allow-plugins": {
"infection/extension-installer": true,
"composer/package-versions-deprecated": true
Expand Down
28 changes: 15 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="false"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
executionOrder="random"
failOnRisky="true"
failOnWarning="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
executionOrder="random"
resolveDependencies="true">
colors="true"
displayDetailsOnPhpunitDeprecations="true"
>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
Expand All @@ -21,9 +23,9 @@
</testsuite>
</testsuites>

<coverage>
<source>
<include>
<directory>./src</directory>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</source>
</phpunit>
25 changes: 10 additions & 15 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
]);

$rectorConfig->skip([
])
->withPhpSets(php81: true)
->withRules([
InlineConstructorDefaultToPropertyRector::class,
])
->withSkip([
ClosureToArrowFunctionRector::class,
NullToStrictStringFuncCallArgRector::class,
]);
};
4 changes: 2 additions & 2 deletions src/CombinedRegexp.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ final class CombinedRegexp extends AbstractCombinedRegexp
/**
* @psalm-var non-empty-string
*/
private string $compiledPattern;
private readonly string $compiledPattern;

/**
* @param string[] $patterns Regular expressions to combine.
* @param string $flags Flags to apply to all regular expressions.
*/
public function __construct(
array $patterns,
private string $flags = ''
private readonly string $flags = ''
) {
if (empty($patterns)) {
throw new InvalidArgumentException('At least one pattern should be specified.');
Expand Down
2 changes: 1 addition & 1 deletion src/MemoizedCombinedRegexp.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class MemoizedCombinedRegexp extends AbstractCombinedRegexp
private array $results = [];

public function __construct(
private AbstractCombinedRegexp $decorated,
private readonly AbstractCombinedRegexp $decorated,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

namespace Yiisoft\Strings\Tests;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Strings\AbstractCombinedRegexp;

abstract class AbstractCombinedRegexpTest extends TestCase
abstract class AbstractCombinedRegexpTestCase extends TestCase
{
/**
* @dataProvider dataMatchAny
*/
#[DataProvider('dataMatchAny')]
public function testMatchAny(array $patterns, string $string, bool $expectedResult): void
{
$regexp = $this->createCombinedRegexp($patterns);
Expand Down Expand Up @@ -106,9 +105,7 @@ public static function dataMatchAny(): iterable
];
}

/**
* @dataProvider dataMatchingPattern
*/
#[DataProvider('dataMatchingPattern')]
public function testMatchingPattern(array $patterns, string $string, string $expectedResult): void
{
$regexp = $this->createCombinedRegexp($patterns);
Expand Down Expand Up @@ -153,9 +150,7 @@ public static function dataMatchingPattern(): iterable
];
}

/**
* @dataProvider dataMatchingPatternPosition
*/
#[DataProvider('dataMatchingPatternPosition')]
public function testMatchingPatternPosition(array $patterns, string $string, int $expectedResult): void
{
$regexp = $this->createCombinedRegexp($patterns);
Expand Down Expand Up @@ -200,9 +195,7 @@ public static function dataMatchingPatternPosition(): iterable
];
}

/**
* @dataProvider dataMatchDifferentDelimiters
*/
#[DataProvider('dataMatchDifferentDelimiters')]
public function testMatchDifferentDelimiters(
array $patterns,
string $flags,
Expand Down
2 changes: 1 addition & 1 deletion tests/CombinedRegexpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Yiisoft\Strings\AbstractCombinedRegexp;
use Yiisoft\Strings\CombinedRegexp;

final class CombinedRegexpTest extends AbstractCombinedRegexpTest
final class CombinedRegexpTest extends AbstractCombinedRegexpTestCase
{
protected function createCombinedRegexp(array $patterns, string $flags = ''): AbstractCombinedRegexp
{
Expand Down
19 changes: 7 additions & 12 deletions tests/InflectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Strings\Tests;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Strings\Inflector;

Expand Down Expand Up @@ -135,9 +136,7 @@ public function testToWords(): void
$this->assertEquals('і це дійсно так!', $inflector->toWords('ІЦеДійсноТак!'));
}

/**
* @dataProvider pascalCaseToIdProvider()
*/
#[DataProvider('pascalCaseToIdProvider')]
public function testPascalCaseToId(string $expectedResult, array $arguments): void
{
$inflector = new Inflector();
Expand All @@ -162,7 +161,7 @@ public function testToCamelCase(): void
$this->assertEquals('ひらがなHepimiz', $inflector->toCamelCase('ひらがな_hepimiz'));
}

public function dataToSnakeCase(): array
public static function dataToSnakeCase(): array
{
return [
[['input' => 'userName'], 'user_name'],
Expand All @@ -176,9 +175,7 @@ public function dataToSnakeCase(): array
];
}

/**
* @dataProvider dataToSnakeCase
*/
#[DataProvider('dataToSnakeCase')]
public function testToSnakeCase(array $arguments, string $expectedOutput): void
{
$inflector = new Inflector();
Expand All @@ -193,7 +190,7 @@ public function testToTable(): void
$this->assertEquals('customer_tables', $inflector->classToTable('customerTable'));
}

public function toSlugCommonsDataProvider(): array
public static function toSlugCommonsDataProvider(): array
{
return [
['', ''],
Expand All @@ -216,9 +213,7 @@ public function toSlugCommonsDataProvider(): array
];
}

/**
* @dataProvider toSlugCommonsDataProvider
*/
#[DataProvider('toSlugCommonsDataProvider')]
public function testToSlugCommons(string $input, string $expected, string $replacement = '-'): void
{
$inflector = new Inflector();
Expand Down Expand Up @@ -489,7 +484,7 @@ private function assertIsOneOf(mixed $actual, array $expected, $message = ''): v
self::assertThat($actual, new IsOneOfAssert($expected), $message);
}

public function pascalCaseToIdProvider(): array
public static function pascalCaseToIdProvider(): array
{
return [
['photo\\album-controller', ['Photo\\AlbumController', '-', false]],
Expand Down
2 changes: 1 addition & 1 deletion tests/IsOneOfAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
final class IsOneOfAssert extends Constraint
{
public function __construct(private array $allowedValues)
public function __construct(private readonly array $allowedValues)
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/MemoizedCombinedRegexpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Yiisoft\Strings\CombinedRegexp;
use Yiisoft\Strings\MemoizedCombinedRegexp;

final class MemoizedCombinedRegexpTest extends AbstractCombinedRegexpTest
final class MemoizedCombinedRegexpTest extends AbstractCombinedRegexpTestCase
{
protected function createCombinedRegexp(array $patterns, string $flags = ''): AbstractCombinedRegexp
{
Expand Down
13 changes: 5 additions & 8 deletions tests/NumericHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Strings\Tests;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Strings\NumericHelper;
use Yiisoft\Strings\Tests\Support\StringableObject;
Expand Down Expand Up @@ -38,7 +39,7 @@ public function testToOrdinalWithIncorrectType(): void
NumericHelper::toOrdinal('bla-bla');
}

public function dataNormalize(): array
public static function dataNormalize(): array
{
return [
'French' => ['4 294 967 295,000', '4294967295.000'],
Expand All @@ -54,9 +55,7 @@ public function dataNormalize(): array
];
}

/**
* @dataProvider dataNormalize
*/
#[DataProvider('dataNormalize')]
public function testNormalize(mixed $input, string $expected): void
{
$this->assertSame($expected, NumericHelper::normalize($input));
Expand All @@ -68,7 +67,7 @@ public function testNormalizeWithIncorrectType(): void
NumericHelper::normalize([]);
}

public function dataIsInteger(): array
public static function dataIsInteger(): array
{
return [
[new \stdClass(), false],
Expand All @@ -83,9 +82,7 @@ public function dataIsInteger(): array
];
}

/**
* @dataProvider dataIsInteger
*/
#[DataProvider('dataIsInteger')]
public function testIsInteger(mixed $value, bool $expected): void
{
$this->assertSame($expected, NumericHelper::isInteger($value));
Expand Down
5 changes: 2 additions & 3 deletions tests/StringHelper/MatchAnyRegexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Strings\Tests\StringHelper;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Strings\StringHelper;

Expand All @@ -19,9 +20,7 @@ public static function dataBase(): array
];
}

/**
* @dataProvider dataBase
*/
#[DataProvider('dataBase')]
public function testBase(bool $expected, string $string, array $patterns, string $flags = ''): void
{
$result = StringHelper::matchAnyRegex($string, $patterns, $flags);
Expand Down
Loading

0 comments on commit 4cdcc85

Please sign in to comment.