Skip to content

⬆️ Update symplify easy coding standard #3568

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ compose.override.yaml
/.phpunit.result.cache
###< phpunit/phpunit ###


###> squizlabs/php_codesniffer ###
/.phpcs-cache
/phpcs.xml
###< squizlabs/php_codesniffer ###
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"symfony/monolog-bundle": "^3.7",
"symfony/password-hasher": "^5.4",
"symfony/polyfill-php72": "^1.23",
"symfony/polyfill-php84": "^1.31",
"symfony/security-bundle": "^5.4",
"symfony/security-csrf": "^5.4",
"symfony/serializer": "^5.4",
Expand Down Expand Up @@ -111,9 +112,10 @@
"phpstan/phpstan-symfony": "^1.0.1",
"phpunit/phpunit": "^8.5",
"se/selenium-server-standalone": "^3.141",
"slevomat/coding-standard": "^8.16",
"symfony/browser-kit": "^5.4",
"symfony/css-selector": "^5.4",
"symplify/easy-coding-standard": "^10.0"
"symplify/easy-coding-standard": "^12.5"
},
"config": {
"preferred-install": {
Expand All @@ -124,7 +126,8 @@
"composer/package-versions-deprecated": true,
"drupol/composer-packages": true,
"symfony/flex": true,
"php-http/discovery": true
"php-http/discovery": true,
"dealerdirect/phpcodesniffer-composer-installer": false
}
},
"extra": {
Expand Down
151 changes: 64 additions & 87 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
use PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer;
use PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer;
use PhpCsFixer\Fixer\Basic\BracesFixer;
use PhpCsFixer\Fixer\Basic\Psr0Fixer;
use PhpCsFixer\Fixer\Basic\Psr4Fixer;
use PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer;
use PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer;
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\ClassNotation\FinalInternalClassFixer;
use PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
Expand Down Expand Up @@ -43,7 +42,7 @@
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer;
use Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousDocBlockWhitespaceFixer;
use Symplify\CodingStandard\Fixer\Commenting\RemoveUselessDefaultCommentFixer;
use Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

Expand All @@ -52,19 +51,14 @@
// See: https://github.com/bolt/core/issues/2519
error_reporting(error_reporting() & ~E_NOTICE);

return static function (ECSConfig $ecsConfig): void {
$parameters = $ecsConfig->parameters();

$parameters->set('sets', ['clean-code', 'common', 'php70', 'php71', 'psr12', 'symfony', 'symfony-risky']);

$parameters->set('paths', [
return ECSConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/ecs.php',
]);

$parameters->set('cache_directory', 'var/cache/ecs');

$parameters->set('skip', [
])
->withCache('var/cache/ecs')
->withPreparedSets(psr12: true, common: true, cleanCode: true)
->withSkip([
OrderedClassElementsFixer::class => null,
YodaStyleFixer::class => null,
IncrementStyleFixer::class => null,
Expand All @@ -76,82 +70,65 @@
UnaryOperatorSpacesFixer::class => null,
ArrayOpenerAndCloserNewlineFixer::class => null,
ArrayListItemNewlineFixer::class => null,
]);

$services = $ecsConfig->services();

$services->set(StandaloneLineInMultilineArrayFixer::class);

$services->set(BlankLineAfterStrictTypesFixer::class);

$services->set(ConcatSpaceFixer::class)
->call('configure', [['spacing' => 'one']]);

$services->set(RemoveSuperfluousDocBlockWhitespaceFixer::class);

$services->set(PhpUnitMethodCasingFixer::class);

$services->set(FinalInternalClassFixer::class);

$services->set(MbStrFunctionsFixer::class);

$services->set(Psr0Fixer::class);

$services->set(Psr4Fixer::class);

$services->set(LowercaseCastFixer::class);

$services->set(ShortScalarCastFixer::class);

$services->set(BlankLineAfterOpeningTagFixer::class);

$services->set(NoLeadingImportSlashFixer::class);

$services->set(OrderedImportsFixer::class)
->call('configure', [[
])
->withRules([
StandaloneLineInMultilineArrayFixer::class,
BlankLineAfterStrictTypesFixer::class,
RemoveUselessDefaultCommentFixer::class,
PhpUnitMethodCasingFixer::class,
FinalInternalClassFixer::class,
MbStrFunctionsFixer::class,
LowercaseCastFixer::class,
ShortScalarCastFixer::class,
BlankLineAfterOpeningTagFixer::class,
NoLeadingImportSlashFixer::class,
NewWithBracesFixer::class,
NoBlankLinesAfterClassOpeningFixer::class,
TernaryOperatorSpacesFixer::class,
ReturnTypeDeclarationFixer::class,
NoTrailingWhitespaceFixer::class,
NoSinglelineWhitespaceBeforeSemicolonsFixer::class,
NoWhitespaceBeforeCommaInArrayFixer::class,
WhitespaceAfterCommaInArrayFixer::class,
FullyQualifiedStrictTypesFixer::class,
DisallowYodaComparisonSniff::class,
])
->withConfiguredRule(PhpdocToReturnTypeFixer::class, ['union_types' => false])
->withConfiguredRule(NoSuperfluousPhpdocTagsFixer::class, ['remove_inheritdoc' => false])
->withConfiguredRule(
ConcatSpaceFixer::class,
['spacing' => 'one']
)
->withConfiguredRule(
OrderedImportsFixer::class,
[
'imports_order' => ['class', 'const', 'function'],
]]);

$services->set(DeclareEqualNormalizeFixer::class)
->call('configure', [['space' => 'none']]);

$services->set(NewWithBracesFixer::class);

$services->set(BracesFixer::class)
->call('configure', [[
]
)
->withConfiguredRule(
DeclareEqualNormalizeFixer::class,
['space' => 'none']
)
->withConfiguredRule(
BracesFixer::class,
[
'allow_single_line_closure' => false,
'position_after_functions_and_oop_constructs' => 'next',
'position_after_control_structures' => 'same',
'position_after_anonymous_constructs' => 'same',
]]);

$services->set(NoBlankLinesAfterClassOpeningFixer::class);

$services->set(VisibilityRequiredFixer::class)
->call('configure', [[
]
)
->withConfiguredRule(
VisibilityRequiredFixer::class,
[
'elements' => ['const', 'method', 'property'],
]]);

$services->set(TernaryOperatorSpacesFixer::class);

$services->set(ReturnTypeDeclarationFixer::class);

$services->set(NoTrailingWhitespaceFixer::class);

$services->set(NoSinglelineWhitespaceBeforeSemicolonsFixer::class);

$services->set(NoWhitespaceBeforeCommaInArrayFixer::class);

$services->set(WhitespaceAfterCommaInArrayFixer::class);

$services->set(PhpdocToReturnTypeFixer::class);

$services->set(FullyQualifiedStrictTypesFixer::class);

$services->set(NoSuperfluousPhpdocTagsFixer::class);

$services->set(PhpdocLineSpanFixer::class)
->call('configure', [['property' => 'single']]);

$services->set(DisallowYodaComparisonSniff::class);
};
]
)
->withConfiguredRule(
PhpdocLineSpanFixer::class,
['property' => 'single']
)
->withConfiguredRule(
ClassAttributesSeparationFixer::class,
['elements' => ['property' => 'one', 'method' => 'one', 'const' => 'none']]
);
1 change: 0 additions & 1 deletion src/Api/Extensions/ContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Bolt\Entity\Content;
use Bolt\Entity\Field;
use Bolt\Enum\Statuses;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Tightenco\Collect\Support\Collection;

Expand Down
2 changes: 1 addition & 1 deletion src/Cache/CachingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private function getTags(string $contentTypeSlug): array
{
$tags = explode(',', $contentTypeSlug);

$tags = array_map(function($t) {
$tags = array_map(function ($t) {
return preg_replace('/[^\pL\d,]+/u', '', $t);
}, $tags);

Expand Down
2 changes: 1 addition & 1 deletion src/Cache/ContentToArrayCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ protected function contentToArray(Content $content, string $locale = ''): array

return $this->execute([parent::class, __FUNCTION__], [$content, $locale]);
}
}
}
2 changes: 1 addition & 1 deletion src/Canonical.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function getScheme(): string
*/
public function setScheme(string $scheme): void
{
$this->scheme = trim($scheme, ':/');
$this->scheme = mb_trim($scheme, ':/');
}

public function getPort(): ?int
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/DeepCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function isKeyEmpty($key): bool
return $this->has($key) && (
($this->get($key) instanceof Collection && $this->get($key)->isEmpty())
|| empty($this->get($key))
);
);
}

public function isKeyNotEmpty($key): bool
Expand Down
6 changes: 4 additions & 2 deletions src/Command/ExtensionsConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,13 @@ private function getExtensionServicesPath(string $path = '*'): string

private function getExtensionConfigPath(string $namespace, string $name): string
{
return sprintf('%s/config/extensions/%s%s%s.yaml',
return sprintf(
'%s/config/extensions/%s%s%s.yaml',
$this->projectDir,
$namespace,
(! empty($name) ? '-' : ''),
$name);
$name
);
}

private function getPackagePath(BaseExtension $package): string
Expand Down
11 changes: 7 additions & 4 deletions src/Command/ResetPasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ class ResetPasswordCommand extends Command
/** @var UserRepository */
private $userRepository;

public function __construct(EntityManagerInterface $em, UserPasswordHasherInterface $passwordHasher,
UserRepository $userRepository, ValidatorInterface $validator)
{
public function __construct(
EntityManagerInterface $em,
UserPasswordHasherInterface $passwordHasher,
UserRepository $userRepository,
ValidatorInterface $validator
) {
parent::__construct();

$this->entityManager = $em;
Expand All @@ -62,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);
$username = $input->getArgument('username');

/** @var User|null */
/** @var User|null $user */
$user = $this->userRepository->findOneBy(['username' => $username]);

if ($user === null) {
Expand Down
1 change: 0 additions & 1 deletion src/Command/UpdateListFormatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Bolt\Utils\ListFormatHelper;
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 Symfony\Component\Console\Style\SymfonyStyle;
Expand Down
10 changes: 4 additions & 6 deletions src/Configuration/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
use Bolt\Controller\Backend\ClearCacheController;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Yaml\Yaml;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Tightenco\Collect\Support\Collection;
use Webimpress\SafeWriter\FileWriter;

class Config
{
Expand Down Expand Up @@ -229,7 +226,7 @@ public function getMediaTypes(): Collection

public function getContentType(string $name): ?Collection
{
$name = trim($name);
$name = mb_trim($name);

if ($this->has('contenttypes/' . $name)) {
return $this->get('contenttypes/' . $name);
Expand All @@ -249,7 +246,7 @@ public function getContentType(string $name): ?Collection

public function getTaxonomy(string $name): ?Collection
{
$name = trim($name);
$name = mb_trim($name);

if ($this->has('taxonomies/' . $name)) {
return $this->get('taxonomies/' . $name);
Expand Down Expand Up @@ -283,7 +280,8 @@ public function getMaxUpload(): int

public function getMaxUploadDescription(): string
{
return sprintf('This value is the minimum of these constraints:<br> <strong>Bolt\'s <code>config.yaml</code></strong>:<br>
return sprintf(
'This value is the minimum of these constraints:<br> <strong>Bolt\'s <code>config.yaml</code></strong>:<br>
<code>accept_upload_size</code>: <code>%s</code><br><br>
<strong>PHP\'s <code>php.ini</code></strong>:<br>
<code>post_max_size</code>: <code>%s</code><br> <code>upload_max_filesize</code>: <code>%s</code>',
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Parser/ContentTypesParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ private function determineOrder(array $contentType): string

$order = str_replace(array_keys($replacements), array_values($replacements), $order);

$orderName = trim($order, '-');
$orderName = mb_trim($order, '-');

if (! in_array($orderName, array_keys($contentType['fields']), true) &&
! in_array($orderName, ['createdAt', 'modifiedAt', 'publishedAt', 'id'], true)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Backend/Async/SelectOptionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(Config $config, FieldExtension $fieldExtension)
*/
public function handleSelectOptions(Request $request): JsonResponse
{
[ $contentTypeSlug, $format ] = explode('/', $request->get('values'));
[$contentTypeSlug, $format] = explode('/', $request->get('values'));

if (empty($maxAmount = $request->get('limit'))) {
$maxAmount = $this->config->get('general/maximum_listing_select', 200);
Expand Down
Loading