Skip to content

Commit 03e4b76

Browse files
test: install and run Rector to upgrade to PHP 8.4
1 parent db8b052 commit 03e4b76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+336
-216
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ jobs:
9494
-
9595
name: Run PHPStan
9696
run: docker compose exec -T php vendor/bin/phpstan --memory-limit=256M
97+
-
98+
name: Run Rector
99+
run: docker compose exec -T php vendor/bin/rector --dry-run
97100
-
98101
name: Check OpenAPI
99102
run: docker compose exec -T php bin/console api:openapi:export --yaml | docker run --rm -i -v $(pwd)/redocly.yaml:/spec/redocly.yaml redocly/cli lint /dev/stdin
@@ -207,34 +210,35 @@ jobs:
207210
recursive: true
208211

209212
# Lint API
210-
-
211-
name: PHP CS Fixer Cache
212-
uses: actions/cache@v4
213-
with:
214-
path: api/.php-cs-fixer.cache
215-
key: ${{ runner.OS }}-phpcsfixer-${{ github.sha }}
216-
restore-keys: |
217-
${{ runner.OS }}-phpcsfixer-
218-
-
219-
name: Get API changed files
220-
id: api-changed-files
221-
uses: tj-actions/changed-files@v46
222-
with:
223-
files: api/**/*.php
224-
-
225-
name: Get Extra Arguments for PHP-CS-Fixer
226-
id: phpcs-intersection
227-
run: |
228-
CHANGED_FILES=$(echo "${{ steps.api-changed-files.outputs.all_changed_and_modified_files }}" | tr ' ' '\n')
229-
if ! echo "${CHANGED_FILES}" | grep -qE "^api\/(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
230-
echo "PHPCS_EXTRA_ARGS<<EOF" >> $GITHUB_ENV
231-
echo "$EXTRA_ARGS" >> $GITHUB_ENV
232-
echo "EOF" >> $GITHUB_ENV
233-
-
234-
name: Lint API
235-
uses: docker://oskarstark/php-cs-fixer-ga
236-
with:
237-
args: --config=api/.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${{ env.PHPCS_EXTRA_ARGS }}"
213+
# todo Waiting for PHP CS Fixer to support PHP 8.4
214+
# -
215+
# name: PHP CS Fixer Cache
216+
# uses: actions/cache@v4
217+
# with:
218+
# path: api/.php-cs-fixer.cache
219+
# key: ${{ runner.OS }}-phpcsfixer-${{ github.sha }}
220+
# restore-keys: |
221+
# ${{ runner.OS }}-phpcsfixer-
222+
# -
223+
# name: Get API changed files
224+
# id: api-changed-files
225+
# uses: tj-actions/changed-files@v46
226+
# with:
227+
# files: api/**/*.php
228+
# -
229+
# name: Get Extra Arguments for PHP-CS-Fixer
230+
# id: phpcs-intersection
231+
# run: |
232+
# CHANGED_FILES=$(echo "${{ steps.api-changed-files.outputs.all_changed_and_modified_files }}" | tr ' ' '\n')
233+
# if ! echo "${CHANGED_FILES}" | grep -qE "^api\/(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
234+
# echo "PHPCS_EXTRA_ARGS<<EOF" >> $GITHUB_ENV
235+
# echo "$EXTRA_ARGS" >> $GITHUB_ENV
236+
# echo "EOF" >> $GITHUB_ENV
237+
# -
238+
# name: Lint API
239+
# uses: docker://oskarstark/php-cs-fixer-ga
240+
# with:
241+
# args: --config=api/.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${{ env.PHPCS_EXTRA_ARGS }}"
238242

239243
# Lint PWA
240244
-

api/.php-cs-fixer.dist.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
$finder = (new PhpCsFixer\Finder())
3+
$finder = new PhpCsFixer\Finder()
44
->in(__DIR__)
55
->exclude('var')
66
;
77

8-
return (new PhpCsFixer\Config())
8+
return new PhpCsFixer\Config()
99
->setRiskyAllowed(true)
1010
->setRules([
1111
'@PhpCsFixer' => true,

api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
# Versions
7-
FROM dunglas/frankenphp:1-php8.3 AS frankenphp_upstream
7+
FROM dunglas/frankenphp:1-php8.4 AS frankenphp_upstream
88

99

1010
# The different stages of this Dockerfile are meant to be built into separate images

api/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"type": "project",
33
"license": "MIT",
44
"require": {
5-
"php": ">=8.3",
5+
"php": ">=8.4",
66
"ext-ctype": "*",
77
"ext-iconv": "*",
88
"api-platform/doctrine-orm": "^4.1.18",
@@ -51,6 +51,7 @@
5151
"phpstan/phpstan-phpunit": "^2.0.6",
5252
"phpstan/phpstan-symfony": "^2.0.6",
5353
"phpunit/phpunit": "^12.2.5",
54+
"rector/rector": "^2.1",
5455
"symfony/browser-kit": "7.3.*",
5556
"symfony/css-selector": "7.3.*",
5657
"symfony/debug-bundle": "7.3.*",

api/composer.lock

Lines changed: 62 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/config/bootstrap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
// Load cached env vars if the .env.local.php file exists
1414
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
1515
if (is_array($env = @include dirname(__DIR__) . '/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) {
16-
(new Dotenv())->usePutenv(false)->populate($env);
16+
new Dotenv()->usePutenv(false)->populate($env);
1717
} else {
1818
// load all the .env files
19-
(new Dotenv())->usePutenv(false)->loadEnv(dirname(__DIR__) . '/.env');
19+
new Dotenv()->usePutenv(false)->loadEnv(dirname(__DIR__) . '/.env');
2020
}
2121

2222
$_SERVER += $_ENV;
2323
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
24-
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
24+
$_SERVER['APP_DEBUG'] ??= $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
2525
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0';

api/migrations/Version20230906094949.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
final class Version20230906094949 extends AbstractMigration
1414
{
15+
#[\Override]
1516
public function getDescription(): string
1617
{
1718
return '';
@@ -22,25 +23,25 @@ public function up(Schema $schema): void
2223
// this up() migration is auto-generated, please modify it to your needs
2324
$this->addSql('CREATE TABLE book (id UUID NOT NULL, book VARCHAR(255) NOT NULL, title TEXT NOT NULL, author VARCHAR(255) DEFAULT NULL, "condition" VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
2425
$this->addSql('CREATE UNIQUE INDEX UNIQ_CBE5A331CBE5A331 ON book (book)');
25-
$this->addSql('COMMENT ON COLUMN book.id IS \'(DC2Type:uuid)\'');
26+
$this->addSql("COMMENT ON COLUMN book.id IS '(DC2Type:uuid)'");
2627
$this->addSql('CREATE TABLE bookmark (id UUID NOT NULL, user_id UUID NOT NULL, book_id UUID NOT NULL, bookmarked_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))');
2728
$this->addSql('CREATE INDEX IDX_DA62921DA76ED395 ON bookmark (user_id)');
2829
$this->addSql('CREATE INDEX IDX_DA62921D16A2B381 ON bookmark (book_id)');
2930
$this->addSql('CREATE UNIQUE INDEX UNIQ_DA62921DA76ED39516A2B381 ON bookmark (user_id, book_id)');
30-
$this->addSql('COMMENT ON COLUMN bookmark.id IS \'(DC2Type:uuid)\'');
31-
$this->addSql('COMMENT ON COLUMN bookmark.user_id IS \'(DC2Type:uuid)\'');
32-
$this->addSql('COMMENT ON COLUMN bookmark.book_id IS \'(DC2Type:uuid)\'');
33-
$this->addSql('COMMENT ON COLUMN bookmark.bookmarked_at IS \'(DC2Type:datetime_immutable)\'');
31+
$this->addSql("COMMENT ON COLUMN bookmark.id IS '(DC2Type:uuid)'");
32+
$this->addSql("COMMENT ON COLUMN bookmark.user_id IS '(DC2Type:uuid)'");
33+
$this->addSql("COMMENT ON COLUMN bookmark.book_id IS '(DC2Type:uuid)'");
34+
$this->addSql("COMMENT ON COLUMN bookmark.bookmarked_at IS '(DC2Type:datetime_immutable)'");
3435
$this->addSql('CREATE TABLE parchment (id UUID NOT NULL, title VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
35-
$this->addSql('COMMENT ON COLUMN parchment.id IS \'(DC2Type:uuid)\'');
36+
$this->addSql("COMMENT ON COLUMN parchment.id IS '(DC2Type:uuid)'");
3637
$this->addSql('CREATE TABLE review (id UUID NOT NULL, user_id UUID NOT NULL, book_id UUID NOT NULL, published_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, body TEXT NOT NULL, rating SMALLINT NOT NULL, letter VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))');
3738
$this->addSql('CREATE INDEX IDX_794381C6A76ED395 ON review (user_id)');
3839
$this->addSql('CREATE INDEX IDX_794381C616A2B381 ON review (book_id)');
3940
$this->addSql('CREATE UNIQUE INDEX UNIQ_794381C6A76ED39516A2B381 ON review (user_id, book_id)');
40-
$this->addSql('COMMENT ON COLUMN review.id IS \'(DC2Type:uuid)\'');
41-
$this->addSql('COMMENT ON COLUMN review.user_id IS \'(DC2Type:uuid)\'');
42-
$this->addSql('COMMENT ON COLUMN review.book_id IS \'(DC2Type:uuid)\'');
43-
$this->addSql('COMMENT ON COLUMN review.published_at IS \'(DC2Type:datetime_immutable)\'');
41+
$this->addSql("COMMENT ON COLUMN review.id IS '(DC2Type:uuid)'");
42+
$this->addSql("COMMENT ON COLUMN review.user_id IS '(DC2Type:uuid)'");
43+
$this->addSql("COMMENT ON COLUMN review.book_id IS '(DC2Type:uuid)'");
44+
$this->addSql("COMMENT ON COLUMN review.published_at IS '(DC2Type:datetime_immutable)'");
4445
$this->addSql('CREATE TABLE "user" (id UUID NOT NULL, email VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
4546
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649E7927C74 ON "user" (email)');
4647
$this->addSql('COMMENT ON COLUMN "user".id IS \'(DC2Type:uuid)\'');
@@ -50,6 +51,7 @@ public function up(Schema $schema): void
5051
$this->addSql('ALTER TABLE review ADD CONSTRAINT FK_794381C616A2B381 FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
5152
}
5253

54+
#[\Override]
5355
public function down(Schema $schema): void
5456
{
5557
// this down() migration is auto-generated, please modify it to your needs

api/public/index.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
// Support CloudFlare Flexible SSL
1010
// https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#cf-visitor
1111
if ($_SERVER['HTTP_CF_VISITOR'] ?? false) {
12-
$_SERVER['HTTP_X_FORWARDED_PROTO'] = json_decode($_SERVER['HTTP_CF_VISITOR'], true)['scheme'];
12+
$_SERVER['HTTP_X_FORWARDED_PROTO'] = json_decode((string) $_SERVER['HTTP_CF_VISITOR'], true)['scheme'];
1313
}
1414

15-
return static function (array $context) {
16-
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
17-
};
15+
return static fn (array $context): Kernel => new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

api/rector.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\SetList;
8+
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
9+
10+
$rector = RectorConfig::configure()
11+
->withPaths([
12+
__DIR__ . '/config',
13+
__DIR__ . '/migrations',
14+
__DIR__ . '/public',
15+
__DIR__ . '/src',
16+
__DIR__ . '/tests',
17+
])
18+
->withRootFiles()
19+
->withPhpSets() // empty means use the version from composer.json
20+
->withSets([
21+
SetList::CODE_QUALITY,
22+
SetList::CODING_STYLE,
23+
SetList::DEAD_CODE,
24+
SetList::INSTANCEOF,
25+
SetList::PRIVATIZATION,
26+
SetList::TYPE_DECLARATION,
27+
SetList::STRICT_BOOLEANS,
28+
])
29+
->withAttributesSets()
30+
->withComposerBased(doctrine: true, phpunit: true)
31+
->withSkip([
32+
__DIR__ . '/config/bundles.php',
33+
DisallowedEmptyRuleFixerRector::class,
34+
SimplifyEmptyCheckOnEmptyArrayRector::class,
35+
])
36+
;
37+
38+
$kernelFilename = __DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml';
39+
if (is_file($kernelFilename)) {
40+
$rector->withSymfonyContainerXml($kernelFilename);
41+
}
42+
43+
return $rector;

api/src/DataFixtures/Factory/BookFactory.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ protected function defaults(): array
7878
/**
7979
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
8080
*/
81+
#[\Override]
8182
protected function initialize(): static
8283
{
8384
return $this
@@ -95,10 +96,8 @@ protected function initialize(): static
9596
}
9697

9798
// An Open Library book URI has been specified: try to find it in the array of books
98-
$data = array_filter($this->data, static function (array $datum) use ($book) {
99-
return $book->book === $datum['book'];
100-
});
101-
if ($data) {
99+
$data = array_filter($this->data, static fn (array $datum): bool => $book->book === $datum['book']);
100+
if ([] !== $data) {
102101
$datum = current($data);
103102
$book->title ??= $datum['title'];
104103
// A book can have no author

0 commit comments

Comments
 (0)