💄 Ajout PHP CS Fixer
All checks were successful
Apply PHP CS Fixer / php-cs-fixer (push) Successful in 1m33s

This commit is contained in:
Melaine Gérard 2025-01-16 21:31:32 +01:00
parent f858359a51
commit 4cab96f9b6
30 changed files with 1201 additions and 88 deletions

View File

@ -0,0 +1,17 @@
name: Apply PHP CS Fixer
on: [push]
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --diff --dry-run

4
.gitignore vendored
View File

@ -34,3 +34,7 @@
!uploads/.gitkeep
/public/kumora/
###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

103
.php-cs-fixer.dist.php Normal file
View File

@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
$finder = PhpCsFixer\Finder::create()
->ignoreVCSIgnored(true)
->in(__DIR__)
->append([
__DIR__ . '/dev-tools/doc.php',
// __DIR__.'/php-cs-fixer', disabled, as we want to be able to run bootstrap file even on lower PHP version, to show nice message
__FILE__,
])
;
$config = new PhpCsFixer\Config();
$config
->setRiskyAllowed(true)
->setRules([
'@PHP82Migration' => true,
'@PHP80Migration:risky' => true,
'@PhpCsFixer:risky' => true,
'@PSR1' => true,
'@PSR2' => true,
'@PSR12' => true,
'align_multiline_comment' => [
'comment_type' => 'phpdocs_only',
],
'array_indentation' => true,
'array_syntax' => [
'syntax' => 'short',
],
// Anciennement 'braces'
'single_space_around_construct' => true,
'control_structure_braces' => true,
'control_structure_continuation_position' => true,
'declare_parentheses' => true,
'no_multiple_statements_per_line' => true,
'braces_position' => true,
'statement_indentation' => true,
'compact_nullable_type_declaration' => true,
'concat_space' => ['spacing' => 'one'],
'doctrine_annotation_array_assignment' => [
'operator' => '=',
],
'doctrine_annotation_spaces' => [
'after_array_assignments_equals' => false,
'before_array_assignments_equals' => false,
],
'php_unit_internal_class' => false,
'php_unit_test_class_requires_covers' => false,
'no_extra_blank_lines' => [
'tokens' => [
'break',
'continue',
'curly_brace_block',
'extra',
'parenthesis_brace_block',
'return',
'square_brace_block',
'throw',
'use',
],
],
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'php_unit_method_casing' => [
'case' => 'camel_case',
],
'phpdoc_order' => true,
'phpdoc_separation' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last'],
'strict_comparison' => true,
'strict_param' => true,
'yoda_style' => true,
'modernize_strpos' => true, // needs PHP 8+ or polyfill
'native_constant_invocation' => false,
'php_unit_strict' => false,
'native_function_invocation' => false,
])
->setFinder($finder)
;
return $config;

View File

@ -107,6 +107,7 @@
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.68",
"phpunit/phpunit": "^11.5.2",
"symfony/browser-kit": "7.2.*",
"symfony/css-selector": "7.2.*",

1036
composer.lock generated Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],

View File

@ -1,5 +1,7 @@
<?php
if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
declare(strict_types=1);
if (file_exists(dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php';
}

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/**
* Returns the importmap for this application.
*

View File

@ -1,9 +1,9 @@
<?php
declare(strict_types=1);
use App\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
return static fn (array $context) => new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Entity\User;
@ -24,8 +26,7 @@ class CreateUserCommand extends Command
private readonly UserPasswordHasherInterface $passwordHasher,
private readonly EntityManagerInterface $entityManager,
private readonly UserRepository $userRepository
)
{
) {
parent::__construct();
}
@ -57,7 +58,6 @@ class CreateUserCommand extends Command
$io->error('Une erreur est survenue lors de la création de l\'utilisateur');
}
return Command::SUCCESS;
}
}

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Entity\User;
@ -40,7 +42,6 @@ class AdminController extends AbstractController
]);
}
#[Route('/users/create', name: 'user_create')]
#[Route('/users/edit/{user}', name: 'user_edit')]
public function editUsers(#[MapEntity(id: 'user')] ?User $user, Request $request): Response

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Form\CreateDirectoryType;
@ -31,7 +33,7 @@ class FilesController extends AbstractController
{
$path = $this->normalizePath($path);
if ($path !== '' && !$defaultAdapter->directoryExists($path)) {
if ('' !== $path && !$defaultAdapter->directoryExists($path)) {
throw $this->createNotFoundException("Ce dossier n'existe pas !");
}
@ -47,7 +49,7 @@ class FilesController extends AbstractController
'path' => $file['path'],
'last_modified' => $file['lastModified'],
'size' => $file['fileSize'] ?? null,
'url' => $file['type'] === 'file'
'url' => 'file' === $file['type']
? $this->generateUrl('app_files_app_file_proxy', ['filename' => $file['path']], UrlGeneratorInterface::ABSOLUTE_URL)
: $this->generateUrl('app_files_index', ['path' => $file['path']]),
];
@ -58,9 +60,8 @@ class FilesController extends AbstractController
usort($realFiles, static function ($a, $b) {
if ($a['type'] === $b['type']) {
return $a['path'] <=> $b['path'];
} else {
return $a['type'] <=> $b['type'];
}
return $a['type'] <=> $b['type'];
});
return $this->render('files/index.html.twig', [
@ -70,11 +71,11 @@ class FilesController extends AbstractController
}
#[Route('/file-proxy', name: 'app_file_proxy')]
public function fileProxy(Filesystem $defaultAdapter, #[MapQueryParameter('filename')]string $filename)
public function fileProxy(Filesystem $defaultAdapter, #[MapQueryParameter('filename')] string $filename)
{
$file = $this->normalizePath($filename);
$mimetype = $defaultAdapter->mimeType($file);
if ($mimetype === '') {
if ('' === $mimetype) {
$mimetype = 'application/octet-stream';
}
@ -102,7 +103,7 @@ class FilesController extends AbstractController
{
$file = $this->normalizePath($filename);
if ($file !== '' && !str_starts_with($file, '.') && $defaultAdapter->fileExists($file)) {
if ('' !== $file && !str_starts_with($file, '.') && $defaultAdapter->fileExists($file)) {
$defaultAdapter->delete($file);
$this->addFlash('success', 'Le fichier a bien été supprimé.');
@ -123,8 +124,7 @@ class FilesController extends AbstractController
{
$path = $this->normalizePath($path);
if ($path !== '' && !str_starts_with($path, '.') && $defaultAdapter->directoryExists($path)) {
if ('' !== $path && !str_starts_with($path, '.') && $defaultAdapter->directoryExists($path)) {
$defaultAdapter->deleteDirectory($path);
$this->addFlash('success', 'Le dossier a bien été supprimé.');
@ -145,7 +145,7 @@ class FilesController extends AbstractController
{
$filepath = $this->normalizePath($filepath);
if ($filepath === '' || str_starts_with($filepath, '.') || !$defaultAdapter->fileExists($filepath)) {
if ('' === $filepath || str_starts_with($filepath, '.') || !$defaultAdapter->fileExists($filepath)) {
throw $this->createNotFoundException("Ce fichier n'existe pas !");
}
@ -220,7 +220,7 @@ class FilesController extends AbstractController
{
$filepath = $this->normalizePath($filepath);
if ($filepath === '' || str_starts_with($filepath, '.') || !$defaultAdapter->directoryExists($filepath)) {
if ('' === $filepath || str_starts_with($filepath, '.') || !$defaultAdapter->directoryExists($filepath)) {
throw $this->createNotFoundException("Ce dossier n'existe pas !");
}
@ -264,7 +264,7 @@ class FilesController extends AbstractController
$form = $this->createForm(UploadType::class);
if ($path !== '' && !$defaultAdapter->directoryExists($path)) {
if ('' !== $path && !$defaultAdapter->directoryExists($path)) {
throw $this->createNotFoundException("Ce dossier n'existe pas !");
}

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

View File

@ -1,12 +1,14 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\UserRepository;
@ -34,10 +36,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column]
private ?string $password = null;
public function initId(): void
{
if ($this->id !== null) {
if (null !== $this->id) {
return;
}

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Form;
use Symfony\Component\Form\AbstractType;

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Form;
use Symfony\Component\Form\AbstractType;

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Form;
use Symfony\Component\Form\AbstractType;

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Form;
use App\Entity\User;
@ -44,7 +46,6 @@ class UserAdminType extends AbstractType
$builder->add('submit', SubmitType::class, [
'label' => 'Enregistrer',
]);
}
public function configureOptions(OptionsResolver $resolver): void

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Repository;
use App\Entity\User;

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Security\Authentication;
use Symfony\Component\HttpFoundation\RedirectResponse;

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Twig\Extension;
use App\Twig\Runtime\BasenameExtensionRuntime;

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Twig\Extension;
use App\Twig\Runtime\SizeExtensionRuntime;

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Twig\Extension;
use App\Twig\Runtime\TimeExtensionRuntime;

View File

@ -1,12 +1,13 @@
<?php
declare(strict_types=1);
namespace App\Twig\Runtime;
use Twig\Extension\RuntimeExtensionInterface;
class BasenameExtensionRuntime implements RuntimeExtensionInterface
{
public function basename($value)
{
return \basename($value);

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Twig\Runtime;
use Twig\Extension\RuntimeExtensionInterface;
@ -17,6 +19,6 @@ class SizeExtensionRuntime implements RuntimeExtensionInterface
$size = ['B', 'KB', 'MB', 'GB','TB'];
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf('%.1f', $bytes / pow(1024, $factor)) . ' ' . @$size[$factor];
return sprintf('%.1f', $bytes / 1024 ** $factor) . ' ' . @$size[$factor];
}
}

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Twig\Runtime;
use Twig\Extension\RuntimeExtensionInterface;

View File

@ -26,6 +26,18 @@
"migrations/.gitignore"
]
},
"friendsofphp/php-cs-fixer": {
"version": "3.68",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.0",
"ref": "be2103eb4a20942e28a6dd87736669b757132435"
},
"files": [
".php-cs-fixer.dist.php"
]
},
"oneup/flysystem-bundle": {
"version": "4.12",
"recipe": {

View File

@ -1,11 +1,13 @@
<?php
declare(strict_types=1);
use Symfony\Component\Dotenv\Dotenv;
require dirname(__DIR__).'/vendor/autoload.php';
require dirname(__DIR__) . '/vendor/autoload.php';
if (file_exists(dirname(__DIR__).'/config/bootstrap.php')) {
require dirname(__DIR__).'/config/bootstrap.php';
if (file_exists(dirname(__DIR__) . '/config/bootstrap.php')) {
require dirname(__DIR__) . '/config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');
}