Skip to content

Use Rector to upgrade codebase to PHP 8.4 #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
694d4d5
Set default value for "old_stable" in CI workflow.
koriym Feb 1, 2025
6f45e88
Update pagerfanta dependency to support version 4.x
koriym Mar 11, 2025
108f33c
Add `#[Override]` annotations to methods across the codebase
koriym May 28, 2025
393f658
Make classes final and enhance security with SensitiveParameter
koriym May 28, 2025
5376d33
Update CI workflow to remove old_stable parameter
koriym May 28, 2025
82f059b
fixup! Set default value for "old_stable" in CI workflow.
koriym May 28, 2025
b07e6db
fixup! fixup! Set default value for "old_stable" in CI workflow.
koriym May 28, 2025
fad5427
Update PHPUnit dependency to version ^12.1
koriym May 28, 2025
76231df
Upgrade with rector to PHP 8.4 + PHPUnit 11
koriym May 28, 2025
2864e83
Remove Scrutinizer Code Quality badge from README
koriym May 28, 2025
7732128
Add UPGRADE.md for guidance on v1.x to v2.x transition
koriym May 28, 2025
16601c9
Update README for v2.x with PHP 8.4 and Aura.Sql 6.0 support
koriym May 28, 2025
f5f3f79
Update license year to 2025
koriym May 28, 2025
d81d538
Update README to remove DI trait section
koriym May 28, 2025
1b8888e
fixup! Update README to remove DI trait section
koriym May 28, 2025
f8fbb61
Add PHPUnit configuration and update .gitignore
koriym May 28, 2025
0c62b67
Add Rector configuration file for automated refactoring
koriym May 28, 2025
ffe27ae
Update PHPUnit configuration and remove phpunit.xml
koriym May 28, 2025
f9f9778
Add .phpunit.result.cache to .gitignore
koriym May 28, 2025
0f4617b
Update dependencies in vendor-bin/tools/composer.json
koriym May 28, 2025
8254eba
Update static analysis workflow to exclude PHPMD
koriym May 28, 2025
d1a6d84
Remove UPGRADE.md and add CHANGELOG.md for clarity
koriym May 28, 2025
9096c27
Update README.md to simplify installation section
koriym May 28, 2025
6d10b73
Fix formatting and typos in README.md
koriym May 28, 2025
540241c
Update dependencies in vendor-bin tools
koriym May 28, 2025
3f16ebe
Update Pagerfanta dependency to support version 4.7
koriym May 28, 2025
817e8a1
Update dependencies and remove unused packages.
koriym May 28, 2025
30ac750
Update README to use PHP attributes instead of annotations
koriym May 28, 2025
a590324
Update README.md with corrected PHP use statements
koriym May 28, 2025
5b79ff1
Update PHPUnit schema to version 12.0
koriym May 28, 2025
43a4ffc
Update annotation syntax for AuraSqlQueryConfig
koriym May 28, 2025
7510547
Update composer.json
koriym May 28, 2025
ad24c2f
Update configuration to remove 'old_stable' PHP version
koriym May 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ jobs:
ci:
uses: ray-di/.github/.github/workflows/continuous-integration.yml@v1
with:
current_stable: 8.4
old_stable: '["8.4"]'
current_stable: "8.4"
8 changes: 6 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: Static Analysis
# This workflow runs static analysis on the codebase using PHPStan and Psalm.
# PHPMD is not included in this workflow, as it is not supported by the PHP 8.4 yet.
# Use this workflow temporarily until PHPMD supports PHP 8.4.

name: Static Analysis (No PHPMD)

on:
push:
Expand All @@ -7,7 +11,7 @@ on:

jobs:
sa:
uses: ray-di/.github/.github/workflows/static-analysis.yml@v1
uses: ray-di/.github/.github/workflows/static-analysis-no-phpmd.yml@v1
with:
php_version: 8.4
has_crc_config: false
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/build/
/vendor/
/composer.lock
/.phpunit.result.cache
/tests/tmp/*
/.phpcs-cache
/.php_cs.cache
/.phpcs-cache
/vendor-bin/tools/vendor/
/.phpunit.cache
/vendor-bin/tools/vendor/
/.phpunit.result.cache
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2012-2024 Akihito Koriyama
Copyright (c) 2012-2025 Akihito Koriyama

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
# Ray.AuraSqlModule

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Ray-Di/Ray.AuraSqlModule/badges/quality-score.png?b=1.x)](https://scrutinizer-ci.com/g/Ray-Di/Ray.AuraSqlModule/?branch=1.x)
[![codecov](https://codecov.io/gh/ray-di/Ray.AuraSqlModule/branch/1.x/graph/badge.svg?token=gcWaftzoXp)](https://codecov.io/gh/ray-di/Ray.AuraSqlModule)
[![Type Coverage](https://shepherd.dev/github/ray-di/Ray.AuraSqlModule/coverage.svg)](https://shepherd.dev/github/ray-di/Ray.AuraSqlModule)
![Continuous Integration](https://github.com/ray-di/Ray.AuraSqlModule/workflows/Continuous%20Integration/badge.svg)
[![Continuous Integration](https://github.com/ray-di/Ray.AuraSqlModule/actions/workflows/continuous-integration.yml/badge.svg?branch=2.x)](https://github.com/ray-di/Ray.AuraSqlModule/actions/workflows/continuous-integration.yml)

An [Aura.Sql](https://github.com/auraphp/Aura.Sql) Module for [Ray.Di](https://github.com/koriym/Ray.Di)

## Requirements

- PHP ^8.4
- Aura.Sql ^6.0

## Installation

### Composer install

$ composer require ray/aura-sql-module

```bash
composer require ray/aura-sql-module:^2.0
```

## Version Compatibility

| Version | PHP | Aura.Sql | Branch | Status |
|---------|---------|----------|--------|--------|
| 2.x | ^8.4 | ^6.0 | 2.x | Current |
| 1.x | ^8.1-8.3| ^5.0 | [1.x](https://github.com/ray-di/Ray.AuraSqlModule/tree/1.x) | Maintained |

> **Note**: For PHP 8.1-8.3 users, please use [v1.x](https://github.com/ray-di/Ray.AuraSqlModule/tree/1.x).

## Getting started

### Module install

```php
Expand Down Expand Up @@ -51,11 +68,7 @@ Use AuraSqlEnvModule to get the value from the environment variable each time at
);
```

### DI trait

* [AuraSqlInject](https://github.com/ray-di/Ray.AuraSqlModule/blob/1.x/src/AuraSqlInject.php) for `Aura\Sql\ExtendedPdoInterface` interface

## Replication
## Replication

Installing `AuraSqlReplicationModule` using a `connection locator` for master/slave connections.

Expand Down Expand Up @@ -120,7 +133,7 @@ class AppModule extends AbstractModule
$this->install(new NamedPdoEnvModule('log_db', 'LOG_DSN', 'LOG_USERNAME',
}
}

```

### with replication

Expand Down
90 changes: 90 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# UPGRADE

## From v1.x to v2.x

### Overview

Ray.AuraSqlModule v2.x is released to support PHP 8.4+, which introduced breaking changes in PDO connection handling. This major version bump is **only** due to dependency updates and **does not include any API or interface changes**.

### What Changed

- **PHP version requirement**: `^8.1` → `^8.4`
- **Aura.Sql dependency**: `^5.0` → `^6.0`
- **Internal PDO compatibility**: Updated to work with PHP 8.4's PDO changes

### What Didn't Change

- ✅ **All public APIs remain identical**
- ✅ **No interface changes**
- ✅ **No behavioral changes**
- ✅ **No configuration changes**
- ✅ **No breaking changes in your application code**

### Migration Guide

#### Step 1: Check Your PHP Version

**If you're using PHP 8.4+:**
```bash
composer require ray/aura-sql-module:^2.0
```

**If you're using PHP 8.1-8.3:**
```bash
composer require ray/aura-sql-module:^1.0
```

#### Step 2: Update Dependencies

No code changes are required. Simply update your `composer.json`:

```diff
{
"require": {
- "ray/aura-sql-module": "^1.0"
+ "ray/aura-sql-module": "^2.0"
}
}
```

#### Step 3: Test Your Application

Since there are no API changes, your existing code should work without modification. However, we recommend running your test suite to ensure everything works as expected with the updated dependencies.

### Version Compatibility

| Ray.AuraSqlModule | PHP Version | Aura.Sql | Status |
|-------------------|-------------|----------|--------|
| v1.x | ^8.1 | ^5.0 | Maintained |
| v2.x | ^8.4 | ^6.0 | Current |

### Support Policy

- **v1.x**: Continues to be maintained for PHP 8.1-8.3 users
- **v2.x**: New development for PHP 8.4+ users

### Frequently Asked Questions

#### Q: Do I need to change my code?
**A: No.** All public APIs and interfaces remain exactly the same.

#### Q: Why the major version bump?
**A: PHP 8.4 introduced breaking changes in PDO that required Aura.Sql v6. Following semantic versioning, we bumped the major version even though no user-facing changes were made.**

#### Q: Can I stay on v1.x?
**A: Yes.** If you're using PHP 8.1-8.3, you can continue using v1.x, which will be maintained.

#### Q: When should I upgrade?
**A: Only when you upgrade to PHP 8.4+.** There's no urgency if you're on PHP 8.1-8.3.

### Need Help?

If you encounter any issues during the upgrade:

1. Check that you're using the correct version for your PHP version
2. Ensure all dependencies are properly updated
3. [Open an issue](https://github.com/ray-di/Ray.AuraSqlModule/issues) if you find any problems

### Technical Details

The upgrade addresses PDO connection signature changes introduced in PHP 8.4. The underlying Aura.Sql library handles these changes transparently, maintaining full backward compatibility at the application level.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"ray/di": "^2.18",
"ray/aop": "^2.17",
"aura/sql": "^6.0",
"pagerfanta/pagerfanta": "^3.5",
"pagerfanta/pagerfanta": "^3.5 || ^4.0",
"rize/uri-template": "^0.4",
"doctrine/annotations": "^1.11 || ^2.0",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"aura/sqlquery": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^11.5.6",
"phpunit/phpunit": "^12.1",
"bamarni/composer-bin-plugin": "^1.4"
},
"autoload": {
Expand Down
15 changes: 13 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="tests/bootstrap.php">
<coverage processUncoveredFiles="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
bootstrap="tests/bootstrap.php"
requireCoverageMetadata="false">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>

<coverage>
<report>
<html outputDirectory="coverage-html"/>
<text outputFile="php://stdout"/>
</report>
</coverage>

<testsuites>
<testsuite name="all">
<directory>tests</directory>
Expand Down
25 changes: 25 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/src-files',
__DIR__ . '/tests',
])
// uncomment to reach your current PHP version
->withPhpSets()
->withSets(
[
PHPUnitSetList::PHPUNIT_90,
PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::PHPUNIT_110,
]
)
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0);
4 changes: 3 additions & 1 deletion src/AuraSqlBaseModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace Ray\AuraSqlModule;

use Override;
use Ray\AuraSqlModule\Pagerfanta\AuraSqlPagerModule;
use Ray\Di\AbstractModule;

use function preg_match;

class AuraSqlBaseModule extends AbstractModule
final class AuraSqlBaseModule extends AbstractModule
{
public function __construct(private readonly string $dsn, ?AbstractModule $module = null)
{
Expand All @@ -19,6 +20,7 @@ public function __construct(private readonly string $dsn, ?AbstractModule $modul
/**
* {@inheritDoc}
*/
#[Override]
protected function configure(): void
{
// @Transactional
Expand Down
10 changes: 6 additions & 4 deletions src/AuraSqlConnectionInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@

use Aura\Sql\ConnectionLocatorInterface;
use Aura\Sql\ExtendedPdoInterface;
use Override;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;
use Ray\AuraSqlModule\Annotation\Read;
use ReflectionProperty;

use function in_array;

class AuraSqlConnectionInterceptor implements MethodInterceptor
final readonly class AuraSqlConnectionInterceptor implements MethodInterceptor
{
public const PROP = 'pdo';
public const string PROP = 'pdo';

/** @phpstan-param array<string> $readsMethods */
public function __construct(
private readonly ConnectionLocatorInterface $connectionLocator,
private ConnectionLocatorInterface $connectionLocator,
/** @var string[] */
#[Read]
private readonly array $readsMethods
private array $readsMethods
) {
}

/**
* {@inheritDoc}
*/
#[Override]
public function invoke(MethodInvocation $invocation)
{
$connection = $this->getConnection($invocation);
Expand Down
4 changes: 3 additions & 1 deletion src/AuraSqlEnvModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace Ray\AuraSqlModule;

use Override;
use Ray\Di\AbstractModule;

class AuraSqlEnvModule extends AbstractModule
final class AuraSqlEnvModule extends AbstractModule
{
/**
* @param string $dsn Env key for Data Source Name (DSN)
Expand All @@ -30,6 +31,7 @@ public function __construct(
/**
* {@inheritDoc}
*/
#[Override]
protected function configure(): void
{
$this->install(new NamedPdoEnvModule('', $this->dsn, $this->username, $this->password, $this->slave, $this->options, $this->queries));
Expand Down
4 changes: 3 additions & 1 deletion src/AuraSqlLocatorModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Ray\AuraSqlModule;

use Aura\Sql\ConnectionLocatorInterface;
use Override;
use Ray\AuraSqlModule\Annotation\AuraSql;
use Ray\AuraSqlModule\Annotation\Read;
use Ray\AuraSqlModule\Annotation\ReadOnlyConnection;
Expand All @@ -14,7 +15,7 @@

use function array_merge;

class AuraSqlLocatorModule extends AbstractModule
final class AuraSqlLocatorModule extends AbstractModule
{
/**
* @phpstan-param array<string> $readMethods
Expand All @@ -34,6 +35,7 @@ public function __construct(
/**
* {@inheritDoc}
*/
#[Override]
protected function configure(): void
{
if ((bool) $this->readMethods && (bool) $this->writeMethods) {
Expand Down
8 changes: 5 additions & 3 deletions src/AuraSqlMasterDbInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
namespace Ray\AuraSqlModule;

use Aura\Sql\ConnectionLocatorInterface;
use Override;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;
use ReflectionProperty;

class AuraSqlMasterDbInterceptor implements MethodInterceptor
final readonly class AuraSqlMasterDbInterceptor implements MethodInterceptor
{
public const PROP = 'pdo';
public const string PROP = 'pdo';

public function __construct(private readonly ConnectionLocatorInterface $connectionLocator)
public function __construct(private ConnectionLocatorInterface $connectionLocator)
{
}

/**
* {@inheritDoc}
*/
#[Override]
public function invoke(MethodInvocation $invocation)
{
$object = $invocation->getThis();
Expand Down
Loading
Loading