Skip to content

Commit

Permalink
Fix implicit nullable to prevent deprecation on PHP 8.4 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored Feb 6, 2025
2 parents e7289b8 + 03461a9 commit 0a99d7f
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
phpunit:
uses: cycle/gh-actions/.github/workflows/db-mssql.yml@master
with:
php: '["8.1","8.2","8.3"]'
php: '["8.1","8.2","8.3","8.4"]'

...
2 changes: 1 addition & 1 deletion .github/workflows/ci-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
phpunit:
uses: cycle/gh-actions/.github/workflows/db-mysql.yml@master
with:
php: '["8.1","8.2","8.3"]'
php: '["8.1","8.2","8.3","8.4"]'

...
2 changes: 1 addition & 1 deletion .github/workflows/ci-pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
phpunit:
uses: cycle/gh-actions/.github/workflows/db-pgsql.yml@master
with:
php: '["8.1","8.2","8.3"]'
php: '["8.1","8.2","8.3","8.4"]'

...
27 changes: 18 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,45 @@ jobs:
matrix:
php-versions: ['8.1']
steps:
- name: Install ODBC driver.
run: |
sudo curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
- name: Checkout
uses: actions/checkout@v2

- name: Setup DB services
run: |
cd tests
docker compose up -d
cd ..
- name: Setup PHP ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: pcov
tools: pecl
extensions: mbstring, pdo, pdo_sqlite, pdo_pgsql, pdo_sqlsrv, pdo_mysql

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Restore Composer Cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies with composer
if: matrix.php-versions != '8.2'
if: matrix.php-versions != '8.5'
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install dependencies with composer php 8.2
if: matrix.php-versions == '8.2'
- name: Install dependencies with composer php 8.5
if: matrix.php-versions == '8.5'
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Execute Tests
Expand All @@ -67,7 +76,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1']
php-versions: ['8.1', '8.4']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -82,18 +91,18 @@ jobs:
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Restore Composer Cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies with composer
if: matrix.php-versions != '8.1'
if: matrix.php-versions != '8.5'
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install dependencies with composer php 8.1
if: matrix.php-versions == '8.1'
- name: Install dependencies with composer php 8.5
if: matrix.php-versions == '8.5'
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Execute Tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
uses: wayofdev/gh-actions/actions/composer/[email protected]

- name: ♻️ Restore cached dependencies installed with composer
uses: actions/cache@v4.0.2
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
Expand Down
15 changes: 15 additions & 0 deletions .idea/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"buggregator/trap": "^1.11",
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^9.5",
"spiral/code-style": "~2.2.0",
"vimeo/psalm": "^5.25"
"spiral/code-style": "^2.2.0",
"vimeo/psalm": "^6.4"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 4 additions & 15 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<files psalm-version="6.4.0@04f312ac6ea48ba1c3e5db4d815bf6d74641c0ee">
<file src="src/Atomizer/Renderer.php">
<ArgumentTypeCoercion>
<code><![CDATA[$comparator]]></code>
Expand Down Expand Up @@ -65,9 +65,6 @@
<ArgumentTypeCoercion>
<code><![CDATA[$table]]></code>
</ArgumentTypeCoercion>
<MixedInferredReturnType>
<code><![CDATA[AbstractTable]]></code>
</MixedInferredReturnType>
<MixedPropertyTypeCoercion>
<code><![CDATA[$this->schemas]]></code>
</MixedPropertyTypeCoercion>
Expand All @@ -80,12 +77,6 @@
</UndefinedInterfaceMethod>
</file>
<file src="src/Config/MigrationConfig.php">
<MixedInferredReturnType>
<code><![CDATA[bool]]></code>
<code><![CDATA[string]]></code>
<code><![CDATA[string]]></code>
<code><![CDATA[string]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$this->config['directory'] ?? '']]></code>
<code><![CDATA[$this->config['directory'] ?? '']]></code>
Expand All @@ -98,13 +89,14 @@
</MixedReturnStatement>
</file>
<file src="src/FileRepository.php">
<ArgumentTypeCoercion>
<code><![CDATA[$directory]]></code>
</ArgumentTypeCoercion>
<MixedArgument>
<code><![CDATA[$directory]]></code>
<code><![CDATA[$filename]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$directory]]></code>
<code><![CDATA[$filename]]></code>
</MixedAssignment>
<MoreSpecificReturnType>
<code><![CDATA[\Generator<int, TFileArray>]]></code>
Expand All @@ -124,9 +116,6 @@
<LessSpecificReturnStatement>
<code><![CDATA[$this->capsule->getDatabase()]]></code>
</LessSpecificReturnStatement>
<MixedInferredReturnType>
<code><![CDATA[?string]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[static::DATABASE]]></code>
</MixedReturnStatement>
Expand Down
7 changes: 0 additions & 7 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,4 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedAttributeClass>
<errorLevel type="suppress">
<referencedClass name="JetBrains\PhpStorm\ExpectedValues" />
</errorLevel>
</UndefinedAttributeClass>
</issueHandlers>
</psalm>
7 changes: 5 additions & 2 deletions src/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class FileRepository implements RepositoryInterface
private FilesInterface $files;
private Inflector $inflector;

public function __construct(private MigrationConfig $config, FactoryInterface $factory = null)
public function __construct(private MigrationConfig $config, ?FactoryInterface $factory = null)
{
$this->files = new Files();
$this->factory = $factory ?? new Container();
Expand Down Expand Up @@ -71,7 +71,7 @@ public function getMigrations(): array
return $migrations;
}

public function registerMigration(string $name, string $class, string $body = null): string
public function registerMigration(string $name, string $class, ?string $body = null): string
{
if (empty($body) && !\class_exists($class)) {
throw new RepositoryException(
Expand Down Expand Up @@ -123,13 +123,16 @@ private function getFilesIterator(): \Generator
$this->config->getVendorDirectories(),
) as $directory
) {
$directory === '' and $directory = '.';
yield from $this->getFiles($directory);
}
}

/**
* Internal method to fetch all migration filenames.
*
* @param non-empty-string $directory
*
* @return \Generator<int, TFileArray>
*/
private function getFiles(string $directory): \Generator
Expand Down
6 changes: 3 additions & 3 deletions src/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function getMigrations(): array
*
* @throws MigrationException
*/
public function run(CapsuleInterface $capsule = null): ?MigrationInterface
public function run(?CapsuleInterface $capsule = null): ?MigrationInterface
{
if (!$this->isConfigured()) {
throw new MigrationException('Unable to run migration, Migrator not configured');
Expand Down Expand Up @@ -158,7 +158,7 @@ static function () use ($migration, $capsule): void {
*
* @throws \Throwable
*/
public function rollback(CapsuleInterface $capsule = null): ?MigrationInterface
public function rollback(?CapsuleInterface $capsule = null): ?MigrationInterface
{
if (!$this->isConfigured()) {
throw new MigrationException('Unable to run migration, Migrator not configured');
Expand Down Expand Up @@ -214,7 +214,7 @@ protected function resolveState(MigrationInterface $migration): State
* Migration table, all migration information will be stored in it.
*
*/
protected function migrationTable(string $database = null): Table
protected function migrationTable(?string $database = null): Table
{
return $this->dbal->database($database)->table($this->config->getTable());
}
Expand Down
2 changes: 1 addition & 1 deletion src/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ public function getMigrations(): array;
* @throws RepositoryException
*
*/
public function registerMigration(string $name, string $class, string $body = null): string;
public function registerMigration(string $name, string $class, ?string $body = null): string;
}
2 changes: 1 addition & 1 deletion src/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getTimeExecuted(): ?\DateTimeInterface
return $this->timeExecuted;
}

public function withStatus(int $status, \DateTimeInterface $timeExecuted = null): self
public function withStatus(int $status, ?\DateTimeInterface $timeExecuted = null): self
{
$state = clone $this;
$state->status = $status;
Expand Down
3 changes: 2 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
database: 'tempdb',
host: '127.0.0.1',
port: 11433,
trustServerCertificate: true,
user: 'SA',
password: 'YourStrong!Passw0rd'
password: 'YourStrong!Passw0rd',
),
queryCache: true
),
Expand Down

0 comments on commit 0a99d7f

Please sign in to comment.