Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Apply new CS rules and minor cleanups #99

Merged
merged 1 commit into from
Jun 3, 2023
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
71 changes: 59 additions & 12 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,69 @@
<?php

$header = <<<EOM
This file is part of the TYPO3 project.

(c) 2019-2022 Benni Mack
Simon Gilli
$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config
->setHeader(
<<<EOM
This file is part of the TYPO3 project.

For the full copyright and license information, please view
the LICENSE file that was distributed with this source code.
(c) 2019-2022 Benni Mack
Simon Gilli

The TYPO3 project - inspiring people to share!
EOM;
For the full copyright and license information, please view
the LICENSE file that was distributed with this source code.

$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config
->setHeader($header, true)
The TYPO3 project - inspiring people to share!
EOM,
true
)
->addRules([
'@PER:risky' => true,
'@PHP80Migration:risky' => true,
'@PHP81Migration' => true,
'declare_strict_types' => true,
'fully_qualified_strict_types' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => false,
'import_functions' => false,
],
'no_unneeded_import_alias' => true,
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
'sort_algorithm' => 'alpha',
],
'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',
],
],
'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,
])
->getFinder()
->exclude('templates')
->exclude('tests/Unit/Fixtures')
->in(__DIR__)
;

Expand Down
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82,
LevelSetList::UP_TO_PHP_81,
DowngradeLevelSetList::DOWN_TO_PHP_81,
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class Application extends BaseApplication
public const VERSION = '0.8.0-DEV';

/**
* getcwd() equivalent which always returns a string
* getcwd() equivalent which always returns a string.
*
* @throws RuntimeException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/AbstractSetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
abstract class AbstractSetupCommand extends Command
{
/**
* @var Setup $setup
* @var Setup
*/
protected $setup;

Expand Down
10 changes: 7 additions & 3 deletions src/Console/Command/TypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace TYPO3\CodingStandards\Console\Command;

use RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -39,6 +40,9 @@ protected function configureBefore(): void
));
}

/**
* @throws RuntimeException
*/
private function getType(InputInterface $input): string
{
if ($this->type === '') {
Expand All @@ -49,17 +53,17 @@ private function getType(InputInterface $input): string

$composerManifest = $this->getProjectDir() . '/composer.json';
if (!file_exists($composerManifest)) {
throw new \RuntimeException(sprintf($composerManifestError, 'found'));
throw new RuntimeException(sprintf($composerManifestError, 'found'));
}

$composerManifest = \file_get_contents($composerManifest);
if ($composerManifest === false) {
throw new \RuntimeException(sprintf($composerManifestError, 'read')); // @codeCoverageIgnore
throw new RuntimeException(sprintf($composerManifestError, 'read')); // @codeCoverageIgnore
}

$composerManifest = \json_decode($composerManifest, true, 512, 0);
if ($composerManifest === false || !is_array($composerManifest)) {
throw new \RuntimeException(sprintf($composerManifestError, 'decoded'));
throw new RuntimeException(sprintf($composerManifestError, 'decoded'));
}

if (
Expand Down
16 changes: 8 additions & 8 deletions src/CsFixerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class CsFixerConfig extends Config implements CsFixerConfigInterface
* @var string
*/
protected static $defaultHeader = <<<EOF
{header}
{header}

It is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License, either version 2
of the License, or any later version.
It is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License, either version 2
of the License, or any later version.

For the full copyright and license information, please read the
LICENSE.txt file that was distributed with this source code.
For the full copyright and license information, please read the
LICENSE.txt file that was distributed with this source code.

The TYPO3 project - inspiring people to share!
EOF;
The TYPO3 project - inspiring people to share!
EOF;

/**
* @var array<string, array<string, mixed>|bool>
Expand Down
11 changes: 9 additions & 2 deletions src/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace TYPO3\CodingStandards;

use RuntimeException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Style\StyleInterface;
Expand Down Expand Up @@ -59,14 +60,17 @@ final class Setup

private readonly StyleInterface $style;

/**
* @throws RuntimeException
*/
public function __construct(string $targetDir, StyleInterface $style = null)
{
if ($targetDir === '') {
$targetDir = '.'; // @codeCoverageIgnore
}

if (!\is_dir($targetDir)) {
throw new \RuntimeException(sprintf("Target directory '%s' does not exist.", $targetDir));
throw new RuntimeException(sprintf("Target directory '%s' does not exist.", $targetDir));
}

// Normalize separators on Windows
Expand Down Expand Up @@ -109,10 +113,13 @@ public function forExtension(bool $force): int
return $result ? 0 : 1;
}

/**
* @throws RuntimeException
*/
public function copyPhpCsFixerConfig(bool $force, string $type): bool
{
if (!in_array($type, self::VALID_TYPES, true)) {
throw new \RuntimeException(sprintf('Invalid type (%s) specified.', $type));
throw new RuntimeException(sprintf('Invalid type (%s) specified.', $type));
}

$targetFile = '.php-cs-fixer.dist.php';
Expand Down
Loading