Skip to content

Commit

Permalink
[TASK] Use php-cs-fixer config from typo3/typo3
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott committed Nov 21, 2024
1 parent 1d808d4 commit 87a6b90
Show file tree
Hide file tree
Showing 45 changed files with 248 additions and 326 deletions.
97 changes: 61 additions & 36 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,69 @@
true
)
->addRules([
'@PHP81Migration' => true,
'@PSR12' => true,
'declare_strict_types' => true,
//'fully_qualified_strict_types' => true, // conflicts currently with Rector
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
'@DoctrineAnnotation' => true,
// @todo: Switch to @PER-CS2.0 once php-cs-fixer's todo list is done: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7247
'@PER-CS1.0' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'cast_spaces' => ['space' => 'none'],
// @todo: Can be dropped once we enable @PER-CS2.0
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'declare_parentheses' => true,
'dir_constant' => true,
// @todo: Can be dropped once we enable @PER-CS2.0
'function_declaration' => [
'closure_fn_spacing' => 'none',
],
'no_unneeded_import_alias' => true,
'phpdoc_align' => true,
'phpdoc_annotation_without_dot' => true,
'phpdoc_indent' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_line_span' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_order_by_value' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_summary' => true,
'phpdoc_tag_casing' => true,
'phpdoc_tag_type' => true,
'phpdoc_to_comment' => [
'ignored_tags' => [
'phpstan-ignore-line',
'phpstan-ignore-next-line',
'todo',
],
'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']],
'type_declaration_spaces' => true,
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
'list_syntax' => ['syntax' => 'short'],
// @todo: Can be dropped once we enable @PER-CS2.0
'method_argument_space' => true,
'modernize_strpos' => true,
'modernize_types_casting' => true,
'native_function_casing' => true,
'no_alias_functions' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_namespace_whitespace' => true,
'no_null_property_initialization' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_singleline' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_nullsafe_operator' => true,
'nullable_type_declaration' => [
'syntax' => 'question_mark',
],
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types_order' => [
'null_adjustment' => 'always_last',
'sort_algorithm' => 'alpha',
],
'phpdoc_var_annotation_correct_order' => true,
'phpdoc_var_without_name' => true,
'self_accessor' => true,
'nullable_type_declaration_for_default_null_value' => true,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
'php_unit_mock_short_will_return' => true,
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'return_type_declaration' => ['space_before' => 'none'],
'single_quote' => true,
'single_space_around_construct' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
// @todo: Can be dropped once we enable @PER-CS2.0
'single_line_empty_body' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
])
;
$config->getFinder()
Expand Down
46 changes: 20 additions & 26 deletions src/Command/ExtensionsTerJsonCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,12 @@

use Composer\Semver\Semver;
use Composer\Semver\VersionParser;
use DateTimeImmutable;
use GuzzleHttp\Client;
use RuntimeException;
use SimpleXMLElement;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use function is_array;
use function is_string;

/**
* @codeCoverageIgnore
*/
Expand Down Expand Up @@ -83,12 +77,12 @@ class ExtensionsTerJsonCreateCommand extends Command
private const ALIASES_FILE = 'aliases.json';

/**
* @var array<int, SimpleXMLElement>
* @var array<int, \SimpleXMLElement>
*/
protected array $extensions = [];

/**
* @var array<string, SimpleXMLElement>
* @var array<string, \SimpleXMLElement>
*/
protected array $extensionKeys = [];

Expand Down Expand Up @@ -199,7 +193,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var string $outputDir */
$outputDir = $input->getArgument('output-dir');
if (($outputPath = realpath($outputDir)) === false) {
throw new RuntimeException(\sprintf('Path "%s" not found.', $outputDir), 1_660_250_640);
throw new \RuntimeException(\sprintf('Path "%s" not found.', $outputDir), 1_660_250_640);
}

$this->outputDir = $outputPath;
Expand Down Expand Up @@ -241,27 +235,27 @@ protected function fetchComposerNames(): void
);
$responseBody = $response->getBody()->getContents();

if (!is_array($json = \json_decode($responseBody, true, 512, JSON_THROW_ON_ERROR))) {
throw new RuntimeException('Invalid response.', 1_660_251_247);
if (!\is_array($json = \json_decode($responseBody, true, 512, JSON_THROW_ON_ERROR))) {
throw new \RuntimeException('Invalid response.', 1_660_251_247);
}

if ($json['meta'] !== null) {
throw new RuntimeException($json['meta']['error']);
throw new \RuntimeException($json['meta']['error']);
}

if (is_array($json['data'])) {
if (\is_array($json['data'])) {
// Assign core extensions
foreach (self::$coreExtensions as $extKey => $composerName) {
$json['data'][$extKey]['composer_name'] = $composerName;
}

foreach ($json['data'] as $extKey => $settings) {
if (!is_string($extKey)) {
throw new RuntimeException('Invalid extension key.', 1_660_251_470);
if (!\is_string($extKey)) {
throw new \RuntimeException('Invalid extension key.', 1_660_251_470);
}

if (!is_string($settings['composer_name'])) {
throw new RuntimeException('Invalid package name.', 1_660_251_471);
if (!\is_string($settings['composer_name'])) {
throw new \RuntimeException('Invalid package name.', 1_660_251_471);
}

self::$abandonedExtensionKeys[$extKey] = $settings['composer_name'];
Expand All @@ -287,7 +281,7 @@ protected function saveAliases(): string
}

/**
* @return SimpleXMLElement[]
* @return \SimpleXMLElement[]
*/
protected function getExtensions(): array
{
Expand All @@ -302,10 +296,10 @@ protected function getExtensions(): array
]
);
if (($extensionsXml = gzdecode($response->getBody()->getContents())) === false) {
throw new RuntimeException('Invalid response.', 1_660_251_597);
throw new \RuntimeException('Invalid response.', 1_660_251_597);
}

$extensionsObject = new SimpleXMLElement($extensionsXml);
$extensionsObject = new \SimpleXMLElement($extensionsXml);
$this->extensions = $extensionsObject->xpath('/extensions/extension');
$this->initExtensionKeys($this->extensions);
}
Expand All @@ -314,7 +308,7 @@ protected function getExtensions(): array
}

/**
* @param SimpleXMLElement[] $extensions
* @param \SimpleXMLElement[] $extensions
*/
protected function initExtensionKeys(array $extensions): void
{
Expand All @@ -328,15 +322,15 @@ protected function initExtensionKeys(array $extensions): void
}

/**
* @param SimpleXMLElement[] $extensions
* @param \SimpleXMLElement[] $extensions
*
* @return array<string, array<int|string, array<int|string, mixed[]>&mixed[]>&mixed[]>
*/
protected function getPackages(array $extensions): array
{
$packages = [];
//$quarter = mktime(0, 0, 0, floor((date('m') - 1) / 3) * 3 + 1, 1, date('Y'));
$dateTimeToday = new DateTimeImmutable();
$dateTimeToday = new \DateTimeImmutable();
$new = $dateTimeToday->modify('yesterday')->getTimestamp();

foreach ($extensions as $extension) {
Expand Down Expand Up @@ -410,7 +404,7 @@ protected function getPackages(array $extensions): array
* dist: array<string, string>
* }|array{}
*/
protected function getPackageArray(SimpleXMLElement $extension, SimpleXMLElement $version): array
protected function getPackageArray(\SimpleXMLElement $extension, \SimpleXMLElement $version): array
{
$extKey = (string)$extension['extensionkey'];
$autoload = [
Expand All @@ -424,7 +418,7 @@ protected function getPackageArray(SimpleXMLElement $extension, SimpleXMLElement
];
if ($version->composerinfo !== null) {
$composerInfo = json_decode((string)$version->composerinfo, true, 512);
if (is_array($composerInfo) && is_array($composerInfo['autoload'] ?? null)) {
if (\is_array($composerInfo) && \is_array($composerInfo['autoload'] ?? null)) {
$autoload = $composerInfo['autoload'];
}
}
Expand Down Expand Up @@ -463,7 +457,7 @@ protected function getPackageArray(SimpleXMLElement $extension, SimpleXMLElement

$dependencies = unserialize((string)$version->dependencies);

if (!is_array($dependencies)) {
if (!\is_array($dependencies)) {
// Ignore extensions with invalid dependencies
return [];
}
Expand Down
7 changes: 3 additions & 4 deletions src/Command/ListMissingDownloadsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Symfony\Component\HttpClient\Exception\RedirectionException;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\Yaml\Yaml;
use Exception;

/**
* @codeCoverageIgnore
Expand Down Expand Up @@ -115,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$yaml = Yaml::dump($result, 4);
file_put_contents('missing-downloads.yaml', $yaml);
} else {
throw new Exception(
throw new \Exception(
'Invalid response with status code ' . $statusCode . ' and content type ' . $contentType
);
}
Expand Down Expand Up @@ -146,7 +145,7 @@ private function getFixedUrl(string $url, string $release, int $format): string
}

return 'redirect failed for ' . $url;
} catch (Exception $exception) {
} catch (\Exception $exception) {
return $exception->getMessage();
}
}
Expand All @@ -158,7 +157,7 @@ private function checkRedirect(string $url): bool
try {
$client->request('GET', $url, ['max_redirects' => 0]);

throw new Exception('something went wrong while calling ' . $url);
throw new \Exception('something went wrong while calling ' . $url);
} catch (RedirectionException) {
return true;
} catch (ClientException) {
Expand Down
6 changes: 2 additions & 4 deletions src/Command/SatisBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

namespace App\Command;

use DateTimeImmutable;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
Expand All @@ -32,7 +31,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
use RuntimeException;

/**
* @codeCoverageIgnore
Expand Down Expand Up @@ -99,12 +97,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var bool $autoBuildAll */
$autoBuildAll = $input->getOption('auto');

if ($autoBuildAll && (new DateTimeImmutable())->format('G') === '3') {
if ($autoBuildAll && (new \DateTimeImmutable())->format('G') === '3') {
$buildAll = \true;
}

if (!($application = $this->getApplication()) instanceof Application) {
throw new RuntimeException('Application is not initialized.', 1_660_125_012);
throw new \RuntimeException('Application is not initialized.', 1_660_125_012);
}

// Run extensions:ter:json:create
Expand Down
5 changes: 2 additions & 3 deletions src/Command/SatisJsonCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use RuntimeException;

/**
* @codeCoverageIgnore
Expand Down Expand Up @@ -75,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if (!is_writable($configFile)) {
throw new RuntimeException(sprintf('File "%s" is not writable', $configFile), 1_438_441_994);
throw new \RuntimeException(sprintf('File "%s" is not writable', $configFile), 1_438_441_994);
}

$repositories = [
Expand All @@ -96,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$satis->useProviders();

if (file_put_contents($configFile, (string)$satis) === false) {
throw new RuntimeException(sprintf('File "%s" could not be written, reason unknown', $configFile), 1_438_442_238);
throw new \RuntimeException(sprintf('File "%s" could not be written, reason unknown', $configFile), 1_438_442_238);
}

$output->writeln(sprintf('Successfully created "%s" with repository dir "%s"', $configFile, $repositoryDir));
Expand Down
3 changes: 1 addition & 2 deletions src/Controller/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Iterator;

#[IsGranted('ROLE_ADMIN')]
class DashboardController extends AbstractDashboardController
Expand All @@ -50,7 +49,7 @@ public function configureDashboard(): Dashboard
}

/**
* @return Iterator<\EasyCorp\Bundle\EasyAdminBundle\Config\Menu\CrudMenuItem|\EasyCorp\Bundle\EasyAdminBundle\Config\Menu\DashboardMenuItem>
* @return \Iterator<\EasyCorp\Bundle\EasyAdminBundle\Config\Menu\CrudMenuItem|\EasyCorp\Bundle\EasyAdminBundle\Config\Menu\DashboardMenuItem>
*/
public function configureMenuItems(): iterable
{
Expand Down
6 changes: 2 additions & 4 deletions src/Controller/Admin/MajorVersionCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;

use function in_array;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;

class MajorVersionCrudController extends AbstractCrudController
{
Expand Down Expand Up @@ -64,7 +62,7 @@ public function configureFields(string $pageName): iterable
yield TextField::new('title', 'Title');
yield TextField::new('subtitle', 'Subtitle');

if (in_array($pageName, [Crud::PAGE_DETAIL, Crud::PAGE_EDIT, Crud::PAGE_NEW], true)) {
if (\in_array($pageName, [Crud::PAGE_DETAIL, Crud::PAGE_EDIT, Crud::PAGE_NEW], true)) {
yield TextareaField::new('description', 'Description');
}

Expand Down
Loading

0 comments on commit 87a6b90

Please sign in to comment.