Skip to content

Commit

Permalink
Require PHP 8.2, upgrade code to new features
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-challis committed Sep 1, 2023
1 parent 1b53595 commit 40f08f3
Show file tree
Hide file tree
Showing 25 changed files with 56 additions and 54 deletions.
3 changes: 1 addition & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'@PHP80Migration' => true,
'@PHP81Migration' => true,
'@PHP82Migration' => true,
'@DoctrineAnnotation' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"minimum-stability": "beta",
"require": {
"php": ">=8.1,<8.3",
"php": ">=8.2,<8.3",
"ext-json": "*",
"ext-pcntl": "*",
"amphp/byte-stream": "^2.0",
Expand Down Expand Up @@ -56,7 +56,7 @@
"config": {
"sort-packages": true,
"platform": {
"php": "8.1.13"
"php": "8.2.9"
}
},
"scripts": {
Expand All @@ -72,6 +72,9 @@
"rector": [
"rector --dry-run"
],
"rector:fix": [
"rector"
],
"static-analysis": [
"@composer validate",
"@phpstan",
Expand Down
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpstan-rector.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ includes:
- vendor/php-standard-library/phpstan-extension/extension.neon

parameters:
phpVersion: 80100
phpVersion: 80200
tmpDir: tmp/phpstan
paths:
- src
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ includes:

parameters:
level: max
phpVersion: 80100
phpVersion: 80200
tmpDir: tmp/phpstan
paths:
- src
Expand Down
4 changes: 2 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->parallel();
$rectorConfig->paths([__DIR__.'/src', __DIR__.'/tests']);
$rectorConfig->phpVersion(PhpVersion::PHP_81);
$rectorConfig->phpVersion(PhpVersion::PHP_82);
$rectorConfig->phpstanConfig(__DIR__.'/phpstan-rector.neon');
$rectorConfig->cacheClass(FileCacheStorage::class);
$rectorConfig->cacheDirectory(__DIR__.'/tmp/rector');
Expand All @@ -26,7 +26,7 @@

$rectorConfig->sets([
SetList::CODE_QUALITY,
LevelSetList::UP_TO_PHP_81,
LevelSetList::UP_TO_PHP_82,
PHPUnitSetList::PHPUNIT_91,
]);
};
4 changes: 2 additions & 2 deletions src/ClassDiscovery/Composer/ClassMapClassDiscoverer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use BenChallis\SqlMigrations\ClassDiscovery\ClassDiscoverer;
use BenChallis\SqlMigrations\ClassDiscovery\PhpNamespace;

final class ClassMapClassDiscoverer implements ClassDiscoverer
final readonly class ClassMapClassDiscoverer implements ClassDiscoverer
{
/**
* @param array<class-string, non-empty-string> $config
*/
public function __construct(private readonly array $config)
public function __construct(private array $config)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/ClassDiscovery/DeDuplicatingClassDiscoverer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace BenChallis\SqlMigrations\ClassDiscovery;

final class DeDuplicatingClassDiscoverer implements ClassDiscoverer
final readonly class DeDuplicatingClassDiscoverer implements ClassDiscoverer
{
public function __construct(private readonly ClassDiscoverer $delegate)
public function __construct(private ClassDiscoverer $delegate)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/ClassDiscovery/PhpNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use Psl\Regex;

final class PhpNamespace
final readonly class PhpNamespace
{
/**
* @param non-empty-string $namespace
*/
private function __construct(private readonly string $namespace)
private function __construct(private string $namespace)
{
\assert($namespace[\strlen($namespace) - 1] !== '\\');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Discovery/RevisionClassDiscoverer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
/**
* Discovers {@see Revision} implementing classes from classes that are yielded from another {@see ClassDiscoverer}.
*/
final class RevisionClassDiscoverer implements ClassDiscoverer
final readonly class RevisionClassDiscoverer implements ClassDiscoverer
{
public function __construct(private readonly ClassDiscoverer $delegate)
public function __construct(private ClassDiscoverer $delegate)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/Migration/Discovery/RevisionDiscoverer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* Discovers {@see Revision}s via a {@see RevisionClassDiscoverer} to discover classes, and a {@see RevisionFactory}
* to instantiate them.
*/
final class RevisionDiscoverer
final readonly class RevisionDiscoverer
{
public function __construct(
private readonly RevisionClassDiscoverer $classDiscoverer,
private readonly RevisionFactory $factory,
private RevisionClassDiscoverer $classDiscoverer,
private RevisionFactory $factory,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Metadata/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use BenChallis\SqlMigrations\Migration\Version;

final class Metadata
final readonly class Metadata
{
private function __construct(public readonly Version $version, public readonly State $state)
private function __construct(public Version $version, public State $state)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Metadata/MySql/MySqlMetadataStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
use Psl\Collection\MapInterface;
use Psl\Type;

final class MySqlMetadataStore implements MetadataStore
final readonly class MySqlMetadataStore implements MetadataStore
{
/**
* @param Executor<MysqlResult, MysqlStatement> $executor
*/
public function __construct(private readonly Executor $executor)
public function __construct(private Executor $executor)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Metadata/MySql/MySqlSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
/**
* @implements SchemaManager<MysqlResult, MysqlStatement>
*/
final class MySqlSchemaManager implements SchemaManager
final readonly class MySqlSchemaManager implements SchemaManager
{
/**
* @param non-empty-string $databaseName
*/
public function __construct(private readonly string $databaseName)
public function __construct(private string $databaseName)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/Migration/MetadataUpdatingMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
/**
* Decorator that updates a {@see MetadataStore} when state changes are performed.
*/
final class MetadataUpdatingMigrations implements Migrations
final readonly class MetadataUpdatingMigrations implements Migrations
{
public function __construct(
private readonly Migrations $migrations,
private readonly MetadataStore $metadata,
private Migrations $migrations,
private MetadataStore $metadata,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use BenChallis\SqlMigrations\Migration\Metadata\State;
use BenChallis\SqlMigrations\Migration\Revision\Revision;

final class Migration
final readonly class Migration
{
public function __construct(public readonly Revision $revision, public readonly Metadata $metadata)
public function __construct(public Revision $revision, public Metadata $metadata)
{
}

Expand Down
8 changes: 4 additions & 4 deletions src/Migration/MigrationCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
use BenChallis\SqlMigrations\Migration\Metadata\MetadataStore;
use BenChallis\SqlMigrations\Migration\Metadata\State;

final class MigrationCollector
final readonly class MigrationCollector
{
public function __construct(
private readonly MetadataStore $metadata,
private readonly RevisionDiscoverer $revisionDiscoverer,
private readonly VersionExtractor $versionExtractor,
private MetadataStore $metadata,
private RevisionDiscoverer $revisionDiscoverer,
private VersionExtractor $versionExtractor,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
use Amp\Sync\Mutex;
use BenChallis\SqlMigrations\Migration\Metadata\State;

final class Migrator
final readonly class Migrator
{
/**
* @template TResult of Result
* @template TStatement of Statement
*
* @param Executor<TResult, TStatement> $executor
*/
public function __construct(private readonly Migrations $migrations, private readonly Executor $executor)
public function __construct(private Migrations $migrations, private Executor $executor)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Revision/RevisionClassNameGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Psl\Regex;
use Psr\Clock\ClockInterface;

final class RevisionClassNameGenerator
final readonly class RevisionClassNameGenerator
{
public function __construct(private readonly ClockInterface $clock)
public function __construct(private ClockInterface $clock)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Revision/RevisionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Amp\File;

final class RevisionGenerator
final readonly class RevisionGenerator
{
public function __construct(private readonly RevisionClassNameGenerator $classNameGenerator)
public function __construct(private RevisionClassNameGenerator $classNameGenerator)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Revision/ServiceLocatorRevisionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;

final class ServiceLocatorRevisionFactory implements RevisionFactory
final readonly class ServiceLocatorRevisionFactory implements RevisionFactory
{
public function __construct(private readonly ContainerInterface $revisions)
public function __construct(private ContainerInterface $revisions)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
*
* The schema versions are treated as being in ascending order, but not sequential.
*/
final class Version
final readonly class Version
{
/**
* @param positive-int $value
*/
private function __construct(private readonly int $value)
private function __construct(private int $value)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Amp\Sql\Executor;
use BenChallis\SqlMigrations\Migration\Revision\Revision;

final class RevisionWithConstructorHavingParameters implements Revision
final readonly class RevisionWithConstructorHavingParameters implements Revision
{
public function __construct(private readonly string $foo) // @phpstan-ignore-line
public function __construct(private string $foo) // @phpstan-ignore-line
{
}

Expand Down
4 changes: 2 additions & 2 deletions tests/helper/MetadataAsserter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use BenChallis\SqlMigrations\Migration\Version;
use PHPUnit\Framework\Assert;

final class MetadataAsserter
final readonly class MetadataAsserter
{
private function __construct(private readonly Metadata $metadata)
private function __construct(private Metadata $metadata)
{
}

Expand Down
4 changes: 2 additions & 2 deletions tests/helper/MigrationAsserter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use BenChallis\SqlMigrations\Migration\Version;
use PHPUnit\Framework\Assert;

final class MigrationAsserter
final readonly class MigrationAsserter
{
private function __construct(private readonly Migration $migration)
private function __construct(private Migration $migration)
{
}

Expand Down

0 comments on commit 40f08f3

Please sign in to comment.