💄 Ajout phpstan + rector
Some checks failed
Apply PHP CS Fixer / php-cs-fixer (push) Failing after 12s
CI / build-test (push) Failing after 9s
rector / Rector (push) Failing after 21s

This commit is contained in:
Melaine Gérard 2025-01-16 21:42:05 +01:00
parent 4cab96f9b6
commit 6e140f84f7
16 changed files with 388 additions and 11 deletions

View File

@ -0,0 +1,15 @@
name: CI
on: [push]
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: php-actions/composer@v6
- uses: php-actions/phpstan@v3
with:
php_version: 8.2

View File

@ -0,0 +1,12 @@
on: [push, pull_request]
name: rector
jobs:
rector:
name: Rector
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Rector
uses: zingimmick/rector-action@0.0.3
with:
args: --dry-run

4
.gitignore vendored
View File

@ -38,3 +38,7 @@
/.php-cs-fixer.php /.php-cs-fixer.php
/.php-cs-fixer.cache /.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ### ###< friendsofphp/php-cs-fixer ###
###> phpstan/phpstan ###
phpstan.neon
###< phpstan/phpstan ###

View File

@ -58,6 +58,7 @@
"config": { "config": {
"allow-plugins": { "allow-plugins": {
"php-http/discovery": true, "php-http/discovery": true,
"phpstan/extension-installer": true,
"symfony/flex": true, "symfony/flex": true,
"symfony/runtime": true "symfony/runtime": true
}, },
@ -108,7 +109,11 @@
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^3.68", "friendsofphp/php-cs-fixer": "^3.68",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/phpstan-symfony": "^2.0",
"phpunit/phpunit": "^11.5.2", "phpunit/phpunit": "^11.5.2",
"rector/rector": "^2.0",
"symfony/browser-kit": "7.2.*", "symfony/browser-kit": "7.2.*",
"symfony/css-selector": "7.2.*", "symfony/css-selector": "7.2.*",
"symfony/debug-bundle": "7.2.*", "symfony/debug-bundle": "7.2.*",

286
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "40b87990e9b847fe9cac632caac98af7", "content-hash": "ad6bf07457863ff03fcd219a3f64fd2e",
"packages": [ "packages": [
{ {
"name": "composer/semver", "name": "composer/semver",
@ -9273,6 +9273,231 @@
}, },
"time": "2022-02-21T01:04:05+00:00" "time": "2022-02-21T01:04:05+00:00"
}, },
{
"name": "phpstan/extension-installer",
"version": "1.4.3",
"source": {
"type": "git",
"url": "https://github.com/phpstan/extension-installer.git",
"reference": "85e90b3942d06b2326fba0403ec24fe912372936"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936",
"reference": "85e90b3942d06b2326fba0403ec24fe912372936",
"shasum": ""
},
"require": {
"composer-plugin-api": "^2.0",
"php": "^7.2 || ^8.0",
"phpstan/phpstan": "^1.9.0 || ^2.0"
},
"require-dev": {
"composer/composer": "^2.0",
"php-parallel-lint/php-parallel-lint": "^1.2.0",
"phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0"
},
"type": "composer-plugin",
"extra": {
"class": "PHPStan\\ExtensionInstaller\\Plugin"
},
"autoload": {
"psr-4": {
"PHPStan\\ExtensionInstaller\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Composer plugin for automatic installation of PHPStan extensions",
"keywords": [
"dev",
"static analysis"
],
"support": {
"issues": "https://github.com/phpstan/extension-installer/issues",
"source": "https://github.com/phpstan/extension-installer/tree/1.4.3"
},
"time": "2024-09-04T20:21:43+00:00"
},
{
"name": "phpstan/phpstan",
"version": "2.1.1",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7",
"reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7",
"shasum": ""
},
"require": {
"php": "^7.4|^8.0"
},
"conflict": {
"phpstan/phpstan-shim": "*"
},
"bin": [
"phpstan",
"phpstan.phar"
],
"type": "library",
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"keywords": [
"dev",
"static analysis"
],
"support": {
"docs": "https://phpstan.org/user-guide/getting-started",
"forum": "https://github.com/phpstan/phpstan/discussions",
"issues": "https://github.com/phpstan/phpstan/issues",
"security": "https://github.com/phpstan/phpstan/security/policy",
"source": "https://github.com/phpstan/phpstan-src"
},
"funding": [
{
"url": "https://github.com/ondrejmirtes",
"type": "github"
},
{
"url": "https://github.com/phpstan",
"type": "github"
}
],
"time": "2025-01-05T16:43:48+00:00"
},
{
"name": "phpstan/phpstan-strict-rules",
"version": "2.0.1",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-strict-rules.git",
"reference": "ed6fea0ad4ad9c7e25f3ad2e7c4d420cf1e67fe3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/ed6fea0ad4ad9c7e25f3ad2e7c4d420cf1e67fe3",
"reference": "ed6fea0ad4ad9c7e25f3ad2e7c4d420cf1e67fe3",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0",
"phpstan/phpstan": "^2.0.4"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^9.6"
},
"type": "phpstan-extension",
"extra": {
"phpstan": {
"includes": [
"rules.neon"
]
}
},
"autoload": {
"psr-4": {
"PHPStan\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Extra strict and opinionated rules for PHPStan",
"support": {
"issues": "https://github.com/phpstan/phpstan-strict-rules/issues",
"source": "https://github.com/phpstan/phpstan-strict-rules/tree/2.0.1"
},
"time": "2024-12-12T20:21:10+00:00"
},
{
"name": "phpstan/phpstan-symfony",
"version": "2.0.1",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-symfony.git",
"reference": "c08cd8e54a08d651bc402d304cfa161c3c3766c4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/c08cd8e54a08d651bc402d304cfa161c3c3766c4",
"reference": "c08cd8e54a08d651bc402d304cfa161c3c3766c4",
"shasum": ""
},
"require": {
"ext-simplexml": "*",
"php": "^7.4 || ^8.0",
"phpstan/phpstan": "^2.0"
},
"conflict": {
"symfony/framework-bundle": "<3.0"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^9.6",
"psr/container": "1.0 || 1.1.1",
"symfony/config": "^5.4 || ^6.1",
"symfony/console": "^5.4 || ^6.1",
"symfony/dependency-injection": "^5.4 || ^6.1",
"symfony/form": "^5.4 || ^6.1",
"symfony/framework-bundle": "^5.4 || ^6.1",
"symfony/http-foundation": "^5.4 || ^6.1",
"symfony/messenger": "^5.4",
"symfony/polyfill-php80": "^1.24",
"symfony/serializer": "^5.4",
"symfony/service-contracts": "^2.2.0"
},
"type": "phpstan-extension",
"extra": {
"phpstan": {
"includes": [
"extension.neon",
"rules.neon"
]
}
},
"autoload": {
"psr-4": {
"PHPStan\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Lukáš Unger",
"email": "looky.msc@gmail.com",
"homepage": "https://lookyman.net"
}
],
"description": "Symfony Framework extensions and rules for PHPStan",
"support": {
"issues": "https://github.com/phpstan/phpstan-symfony/issues",
"source": "https://github.com/phpstan/phpstan-symfony/tree/2.0.1"
},
"time": "2025-01-04T13:58:15+00:00"
},
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "11.0.8", "version": "11.0.8",
@ -10223,6 +10448,65 @@
], ],
"time": "2024-06-11T12:45:25+00:00" "time": "2024-06-11T12:45:25+00:00"
}, },
{
"name": "rector/rector",
"version": "2.0.6",
"source": {
"type": "git",
"url": "https://github.com/rectorphp/rector.git",
"reference": "fa0cb009dc3df084bf549032ae4080a0481a2036"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/rectorphp/rector/zipball/fa0cb009dc3df084bf549032ae4080a0481a2036",
"reference": "fa0cb009dc3df084bf549032ae4080a0481a2036",
"shasum": ""
},
"require": {
"php": "^7.4|^8.0",
"phpstan/phpstan": "^2.1.1"
},
"conflict": {
"rector/rector-doctrine": "*",
"rector/rector-downgrade-php": "*",
"rector/rector-phpunit": "*",
"rector/rector-symfony": "*"
},
"suggest": {
"ext-dom": "To manipulate phpunit.xml via the custom-rule command"
},
"bin": [
"bin/rector"
],
"type": "library",
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Instant Upgrade and Automated Refactoring of any PHP code",
"keywords": [
"automation",
"dev",
"migration",
"refactoring"
],
"support": {
"issues": "https://github.com/rectorphp/rector/issues",
"source": "https://github.com/rectorphp/rector/tree/2.0.6"
},
"funding": [
{
"url": "https://github.com/tomasvotruba",
"type": "github"
}
],
"time": "2025-01-06T10:38:36+00:00"
},
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",
"version": "3.0.2", "version": "3.0.2",

14
phpstan.dist.neon Normal file
View File

@ -0,0 +1,14 @@
parameters:
level: 5
paths:
- src
excludePaths:
- tests
symfony:
containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml
strictRules:
noVariableVariables: false
reportUnmatchedIgnoredErrors: false
treatPhpDocTypesAsCertain: false

32
rector.php Normal file
View File

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\SymfonySetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82,
SymfonySetList::SYMFONY_71,
SymfonySetList::SYMFONY_CODE_QUALITY,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
SetList::DEAD_CODE,
SetList::CODE_QUALITY,
SetList::PHP_82,
DoctrineSetList::DOCTRINE_CODE_QUALITY,
]);
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/migrations',
]);
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
};

View File

@ -39,7 +39,7 @@ class CreateUserCommand extends Command
try { try {
$user = $this->userRepository->findOneBy(['email' => $email]); $user = $this->userRepository->findOneBy(['email' => $email]);
if ($user) { if ($user !== null) {
$io->error('Un utilisateur existe déjà avec cet email'); $io->error('Un utilisateur existe déjà avec cet email');
return Command::FAILURE; return Command::FAILURE;
} }
@ -54,7 +54,7 @@ class CreateUserCommand extends Command
$this->entityManager->flush(); $this->entityManager->flush();
$io->success('Utilisateur créé avec succès'); $io->success('Utilisateur créé avec succès');
} catch (\Exception $e) { } catch (\Exception) {
$io->error('Une erreur est survenue lors de la création de l\'utilisateur'); $io->error('Une erreur est survenue lors de la création de l\'utilisateur');
} }

View File

@ -47,7 +47,7 @@ class AdminController extends AbstractController
public function editUsers(#[MapEntity(id: 'user')] ?User $user, Request $request): Response public function editUsers(#[MapEntity(id: 'user')] ?User $user, Request $request): Response
{ {
$isNew = false; $isNew = false;
if (!$user) { if (!$user instanceof \App\Entity\User) {
$user = new User(); $user = new User();
$isNew = true; $isNew = true;
} }

View File

@ -42,7 +42,7 @@ class FilesController extends AbstractController
$realFiles = []; $realFiles = [];
foreach ($files as $file) { foreach ($files as $file) {
$filename = basename($file['path']); $filename = basename((string) $file['path']);
if (!str_starts_with($filename, '.')) { if (!str_starts_with($filename, '.')) {
$realFiles[] = [ $realFiles[] = [
'type' => $file['type'], 'type' => $file['type'],
@ -301,8 +301,7 @@ class FilesController extends AbstractController
$path = trim($path, '/'); $path = trim($path, '/');
// On retire les chemins relatifs // On retire les chemins relatifs
$path = str_replace('..', '', $path); $path = str_replace('..', '', $path);
$path = str_replace('//', '/', $path);
return $path; return str_replace('//', '/', $path);
} }
} }

View File

@ -12,7 +12,7 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController class SecurityController extends AbstractController
{ {
public function __construct(private readonly UrlGeneratorInterface $urlGenerator) public function __construct()
{ {
} }

View File

@ -38,7 +38,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
public function initId(): void public function initId(): void
{ {
if (null !== $this->id) { if ($this->id instanceof \Symfony\Component\Uid\Uuid) {
return; return;
} }

View File

@ -10,6 +10,6 @@ class BasenameExtensionRuntime implements RuntimeExtensionInterface
{ {
public function basename($value) public function basename($value)
{ {
return \basename($value); return \basename((string) $value);
} }
} }

View File

@ -17,7 +17,7 @@ class SizeExtensionRuntime implements RuntimeExtensionInterface
{ {
$bytes = $value; $bytes = $value;
$size = ['B', 'KB', 'MB', 'GB','TB']; $size = ['B', 'KB', 'MB', 'GB','TB'];
$factor = floor((strlen($bytes) - 1) / 3); $factor = floor((strlen((string) $bytes) - 1) / 3);
return sprintf('%.1f', $bytes / 1024 ** $factor) . ' ' . @$size[$factor]; return sprintf('%.1f', $bytes / 1024 ** $factor) . ' ' . @$size[$factor];
} }

View File

@ -50,6 +50,18 @@
"config/packages/oneup_flysystem.yaml" "config/packages/oneup_flysystem.yaml"
] ]
}, },
"phpstan/phpstan": {
"version": "2.1",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "main",
"version": "1.0",
"ref": "5e490cc197fb6bb1ae22e5abbc531ddc633b6767"
},
"files": [
"phpstan.dist.neon"
]
},
"phpunit/phpunit": { "phpunit/phpunit": {
"version": "9.6", "version": "9.6",
"recipe": { "recipe": {