Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
php: ['8.2', '8.3', '8.4', '8.5']

steps:
- name: Checkout
Expand Down Expand Up @@ -51,8 +51,8 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction

- name: Coding standards (phpcs)
run: composer cs-ci
- name: Coding standards (PHP-CS-Fixer)
run: vendor/bin/php-cs-fixer fix --dry-run --diff

- name: Static analysis (PHPStan)
run: composer stan
Expand Down
45 changes: 45 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/*
* Shared php-cs-fixer configuration for every InitPHP package (ADR-005).
*
* This file is identical in all repositories as `.php-cs-fixer.dist.php`.
* The only package-specific part is the two lines below; scripts/check-cs-config.sh
* ignores exactly those two lines when it compares a package with this template.
* Keep each of them on a single line.
*/
$excludeDirs = [];
$excludePaths = [];

$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests'])
->name('*.php');

foreach ($excludeDirs as $excludeDir) {
$finder->exclude($excludeDir);
}

foreach ($excludePaths as $excludePath) {
$finder->notPath($excludePath);
}

return (new PhpCsFixer\Config())
->setRiskyAllowed(false)
->setRules([
'@PER-CS' => true,
'@PHP8x2Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'no_unused_imports' => true,
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
'sort_algorithm' => 'alpha',
],
'single_quote' => true,
'trailing_comma_in_multiline' => [
'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters'],
],
])
->setFinder($finder)
->setCacheFile(__DIR__ . '/build/php-cs-fixer.cache');
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

All notable changes to `initphp/database` are documented here. The format is based
on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed (breaking)

- Requires PHP `^8.2` (was `^8.1`); PHP 8.1 is no longer supported. CI now
covers PHP 8.2, 8.3, 8.4 and 8.5.
- Code style moved to PER-CS (php-cs-fixer, shared `.php-cs-fixer.dist.php`),
replacing PHP_CodeSniffer (PSR-12); the codebase has been reformatted
accordingly. The `cs`, `cs-ci` and `cs-fix` Composer scripts now run
php-cs-fixer, and `cs-check` was added.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ If a feature is documented for InitORM, it works here under the InitPHP namespac

## Requirements

- PHP **8.1** or later
- PHP **8.2** or later
- `ext-pdo` and a PDO driver for your target database (`pdo_mysql`, `pdo_pgsql`, `pdo_sqlite`, …)

## Installation
Expand Down Expand Up @@ -99,7 +99,7 @@ Org-wide guidelines (PSR-12, `declare(strict_types=1)`, Conventional Commits, PH
Local checks before opening a PR:

```bash
composer qa # phpcs + phpstan + phpunit
composer qa # php-cs-fixer + phpstan + phpunit
composer cs-fix # auto-format
```

Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-pdo": "*",
"initorm/orm": "^2.0"
},
"require-dev": {
"ext-pdo_sqlite": "*",
"friendsofphp/php-cs-fixer": "^3.88",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^10.5",
"squizlabs/php_codesniffer": "^3.10"
"phpunit/phpunit": "^10.5"
},
"suggest": {
"ext-pdo_mysql": "Required for MySQL / MariaDB connections.",
Expand All @@ -60,9 +60,10 @@
"scripts": {
"test": "phpunit",
"test:coverage": "phpunit --coverage-text --coverage-html=build/coverage",
"cs": "phpcs",
"cs-ci": "phpcs --warning-severity=0",
"cs-fix": "phpcbf",
"cs": "@cs-check",
"cs-ci": "@cs-check",
"cs-check": "php-cs-fixer fix --dry-run --diff",
"cs-fix": "php-cs-fixer fix",
"stan": "phpstan analyse",
"qa": [
"@cs-ci",
Expand Down
16 changes: 0 additions & 16 deletions phpcs.xml.dist

This file was deleted.

10 changes: 4 additions & 6 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ final class DB
/**
* Prevent instantiation — this class is a pure static facade.
*/
private function __construct()
{
}
private function __construct() {}

/**
* Build a Database from the supplied connection (array or
Expand All @@ -54,7 +52,7 @@ public static function createImmutable(array|ConnectionInterface $connection): D
if (self::$database !== null) {
throw new DatabaseException(
'An immutable Database instance has already been set. '
. 'Call DB::replaceImmutable() to swap it explicitly.'
. 'Call DB::replaceImmutable() to swap it explicitly.',
);
}

Expand All @@ -72,7 +70,7 @@ public static function createImmutable(array|ConnectionInterface $connection): D
* @param array<string, mixed>|ConnectionInterface|DatabaseInterface|null $connection
*/
public static function replaceImmutable(
array|ConnectionInterface|DatabaseInterface|null $connection
array|ConnectionInterface|DatabaseInterface|null $connection,
): ?DatabaseInterface {
if ($connection === null) {
self::$database = null;
Expand Down Expand Up @@ -107,7 +105,7 @@ public static function getDatabase(): DatabaseInterface
{
if (self::$database === null) {
throw new DatabaseException(
'No immutable Database instance is configured. Call DB::createImmutable($connection) first.'
'No immutable Database instance is configured. Call DB::createImmutable($connection) first.',
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@
* stacks; if the wrapper ever needs real behaviour, it should be added to
* upstream {@see InitORMDatabase} (or composed, not inherited) instead.
*/
class Database extends InitORMDatabase
{
}
class Database extends InitORMDatabase {}
4 changes: 1 addition & 3 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@
* bypasses {@see InitORMEntity::__set()} and creates a dynamic property
* instead — deprecated in PHP 8.2+, fatal in a future PHP version.
*/
class Entity extends InitORMEntity
{
}
class Entity extends InitORMEntity {}
4 changes: 1 addition & 3 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
*
* No behaviour lives here on purpose — see the same note on {@see Database}.
*/
abstract class Model extends InitORMModel
{
}
abstract class Model extends InitORMModel {}
2 changes: 1 addition & 1 deletion src/Utils/Datatables/Datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ final class Datatables
public function __construct(
private readonly DatabaseInterface|ModelInterface $db,
?RequestParser $request = null,
?Renderer $renderer = null
?Renderer $renderer = null,
) {
$this->request = $request ?? RequestParser::fromGlobals();
$this->renderer = $renderer ?? new Renderer();
Expand Down
4 changes: 1 addition & 3 deletions src/Utils/Datatables/RequestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ final class RequestParser
* from whichever transport(s) the caller chose (query string, form
* body, JSON body).
*/
public function __construct(private readonly array $payload)
{
}
public function __construct(private readonly array $payload) {}

/**
* Build a parser from the live request — $_GET + $_POST merged, plus the
Expand Down
6 changes: 3 additions & 3 deletions tests/ReservedKeywordRegressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ protected function setUp(): void
title TEXT,
"order" INTEGER,
"select" TEXT
)'
)',
);
$this->connection->getPDO()->exec(
"INSERT INTO posts (title, \"order\", \"select\") VALUES
('First', 1, 'a'),
('Second', 2, 'b'),
('Third', 3, 'c')"
('Third', 3, 'c')",
);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ public function testCompiledSqlActuallyQuotesTheIdentifier(): void
$logs[0]['query'],
'Reserved identifiers must be emitted in their quoted form. If this assertion fails, '
. 'upstream initorm/query-builder stopped escaping identifiers — file a bug there before '
. 'shipping a release.'
. 'shipping a release.',
);
}
}
8 changes: 4 additions & 4 deletions tests/Support/SqliteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public static function seedUsers(ConnectionInterface $connection): void
email TEXT NOT NULL,
active INTEGER NOT NULL DEFAULT 1,
score INTEGER
)'
)',
);
$pdo->exec(
"INSERT INTO users (name, email, active, score) VALUES
('Alice', 'alice@example.com', 1, 42),
('Bob', 'bob@example.com', 0, 13),
('Carol', 'carol@example.com', 1, 99)"
('Carol', 'carol@example.com', 1, 99)",
);
}

Expand All @@ -77,7 +77,7 @@ public static function seedPostsForGrouping(ConnectionInterface $connection): vo
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
title TEXT NOT NULL
)'
)',
);
$pdo->exec(
"INSERT INTO posts (user_id, title) VALUES
Expand All @@ -86,7 +86,7 @@ public static function seedPostsForGrouping(ConnectionInterface $connection): vo
(2, 'Bob only'),
(3, 'Carol first'),
(3, 'Carol second'),
(3, 'Carol third')"
(3, 'Carol third')",
);
}
}
2 changes: 1 addition & 1 deletion tests/Utils/Datatables/DatatablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function testRendererTransformsTheReturnedData(): void
$datatables
->from('users')
->setColumns('id', 'name')
->addRender('name', fn (string $name): string => '*' . $name . '*');
->addRender('name', fn(string $name): string => '*' . $name . '*');

$rows = $datatables->toArray()['data'];
$names = array_column($rows, 'name');
Expand Down
14 changes: 7 additions & 7 deletions tests/Utils/Datatables/RendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testEmptyRendererIsANoOp(): void
public function testRegisteredCallbackTransformsTheTargetColumn(): void
{
$renderer = new Renderer();
$renderer->add('name', fn (string $value): string => strtoupper($value));
$renderer->add('name', fn(string $value): string => strtoupper($value));

$output = $renderer->apply([
['id' => 1, 'name' => 'Alice'],
Expand All @@ -41,8 +41,8 @@ public function testRegisteredCallbackTransformsTheTargetColumn(): void
public function testCallbackReceivesTheFullRow(): void
{
$renderer = new Renderer();
$renderer->add('full_name', static fn (?string $value, array $row): string =>
($row['first'] ?? '') . ' ' . ($row['last'] ?? ''));
$renderer->add('full_name', static fn(?string $value, array $row): string
=> ($row['first'] ?? '') . ' ' . ($row['last'] ?? ''));

$output = $renderer->apply([
['first' => 'Ada', 'last' => 'Lovelace', 'full_name' => ''],
Expand All @@ -54,7 +54,7 @@ public function testCallbackReceivesTheFullRow(): void
public function testColumnsWithoutAnyRendererPassThrough(): void
{
$renderer = new Renderer();
$renderer->add('only_this', fn ($v) => 'X');
$renderer->add('only_this', fn($v) => 'X');

$output = $renderer->apply([['only_this' => 'a', 'untouched' => 'b']]);

Expand All @@ -65,7 +65,7 @@ public function testColumnsWithoutAnyRendererPassThrough(): void
public function testNonAssociativeRowsArePassedThroughUnchanged(): void
{
$renderer = new Renderer();
$renderer->add('name', fn ($v) => 'X');
$renderer->add('name', fn($v) => 'X');

$object = (object) ['name' => 'Alice'];
$output = $renderer->apply([$object]);
Expand All @@ -76,8 +76,8 @@ public function testNonAssociativeRowsArePassedThroughUnchanged(): void
public function testReAddingAColumnOverwritesThePreviousRenderer(): void
{
$renderer = new Renderer();
$renderer->add('name', fn ($v) => 'first');
$renderer->add('name', fn ($v) => 'second');
$renderer->add('name', fn($v) => 'first');
$renderer->add('name', fn($v) => 'second');

$output = $renderer->apply([['name' => 'whatever']]);

Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/Datatables/RequestParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testOrderEntriesAreNormalisedToAscOrDescPairs(): void

self::assertSame(
[[2, 'ASC'], [1, 'DESC'], [3, 'DESC']],
$parser->orders()
$parser->orders(),
);
}

Expand Down
Loading