Skip to content

Commit

Permalink
fix: code style
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Jul 20, 2023
1 parent 23cddc9 commit 5d1f28b
Show file tree
Hide file tree
Showing 20 changed files with 233 additions and 176 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
vendor

.phpunit.result.cache
.php-cs-fixer.cache

# Devenv
.devenv*
Expand Down
59 changes: 59 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/*
* This document has been generated with
* https://mlocati.github.io/php-cs-fixer-configurator/#version:3.14|configurator
* you can change this configuration by importing this file.
*/
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'@PSR12:risky' => true,
'@PHP80Migration:risky' => true,
'@PHP81Migration' => true,
'@PhpCsFixer' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
// Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
'blank_line_after_opening_tag' => false,
// Using `isset($var) &&` multiple times should be done in one call.
'combine_consecutive_issets' => false,
// Calling `unset` on multiple items should be done in one call.
'combine_consecutive_unsets' => false,
// Concatenation should be spaced according configuration.
'concat_space' => ['spacing'=>'one'],
// Pre- or post-increment and decrement operators should be used if possible.
'increment_style' => ['style'=>'post'],
// Ensure there is no code on the same line as the PHP open tag.
'linebreak_after_opening_tag' => false,
// Replace non multibyte-safe functions with corresponding mb function.
'mb_str_functions' => true,
// Add leading `\` before function invocation to speed up resolving.
'native_function_invocation' => false,
// Adds or removes `?` before type declarations for parameters with a default `null` value.
'nullable_type_declaration_for_default_null_value' => true,
// All items of the given phpdoc tags must be either left-aligned or (by default) aligned vertically.
'phpdoc_align' => ['align'=>'left'],
// PHPDoc summary should end in either a full stop, exclamation mark, or question mark.
'phpdoc_summary' => false,
// Throwing exception must be done in single line.
'single_line_throw' => false,
// Comparisons should be strict.
'strict_comparison' => true,
// Functions should be used with `$strict` param set to `true`.
'strict_param' => true,
// Anonymous functions with one-liner return statement must use arrow functions.
'use_arrow_functions' => false,
// Write conditions in Yoda style (`true`), non-Yoda style (`['equal' => false, 'identical' => false, 'less_and_greater' => false]`) or ignore those conditions (`null`) based on configuration.
'yoda_style' => false,
// Currently waiting for https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5572 to be implemented to ignore @var (needed for LSP)
'phpdoc_to_comment' => false,
// Multi-line arrays, arguments list, parameters list and `match` expressions must have a trailing comma.
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'arrays', 'match', 'parameters']],
])
->setFinder(PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('stubs')
->in(__DIR__)
)
;
2 changes: 1 addition & 1 deletion config/v6.5/flysystem-v3.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'League\\Flysystem\\FilesystemInterface' => 'League\\Flysystem\\FilesystemOperator',
'League\\Flysystem\\AdapterInterface' => 'League\\Flysystem\\FilesystemAdapter',
'League\\Flysystem\\Memory\\MemoryAdapter' => 'League\\Flysystem\\InMemory\\InMemoryFilesystemAdapter',
]
],
);

$methodRenaming = [];
Expand Down
6 changes: 3 additions & 3 deletions config/v6.5/renaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@
'Shopware\Core\Content\Flow\Dispatching\FlowState',
'sequenceId',
'getSequenceId',
null
)]
null,
)],
);

$rectorConfig->ruleWithConfiguration(
InterfaceReplacedWithAbstractClassRector::class,
[
new InterfaceReplacedWithAbstractClass('Shopware\Core\Checkout\Cart\CartPersisterInterface', 'Shopware\Core\Checkout\Cart\AbstractCartPersister'),
new InterfaceReplacedWithAbstractClass('Shopware\Core\Content\Sitemap\Provider\UrlProviderInterface', 'Shopware\Core\Content\Sitemap\Provider\AbstractUrlProvider'),
]
],
);

$rectorConfig->rule(FakerPropertyToMethodCallRector::class);
Expand Down
8 changes: 4 additions & 4 deletions config/v6.5/typehints.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
new AddParamTypeDeclaration('Shopware\Core\Content\ProductStream\DataAbstractionLayer\ProductStreamIndexer', 'iterate', 0, new ArrayType(new StringType(), new StringType())),
new AddParamTypeDeclaration('Shopware\Core\Content\Rule\DataAbstractionLayer\RuleIndexer', 'iterate', 0, new ArrayType(new StringType(), new StringType())),
new AddParamTypeDeclaration('Shopware\\Storefront\\Page\\Product\\Review\\ReviewLoaderResult', 'setMatrix', 0, new ObjectType('Shopware\Core\Content\Product\SalesChannel\Review\RatingMatrix')),
]
],
);

$rectorConfig->ruleWithConfiguration(
Expand All @@ -43,22 +43,22 @@
new AddReturnTypeDeclaration('Shopware\Core\Content\Cms\DataResolver\CriteriaCollection', 'getIterator', new ObjectType('Traversable')),
new AddReturnTypeDeclaration('Shopware\\Core\\Checkout\\Cart\\CartBehavior', 'hasPermission', new BooleanType()),
new AddReturnTypeDeclaration('Shopware\\Storefront\\Page\\Product\\Review\\ReviewLoaderResult', 'getMatrix', new ObjectType('Shopware\Core\Content\Product\SalesChannel\Review\RatingMatrix')),
]
],
);

$rectorConfig->ruleWithConfiguration(
AddArgumentToClassWithoutDefaultRector::class,
[
new AddArgumentToClassWithoutDefault('Shopware\Storefront\Framework\Captcha\AbstractCaptcha', 'supports', 1, 'captchaConfig', new ArrayType(new StringType(), new StringType())),
new AddArgumentToClassWithoutDefault('Shopware\Storefront\Framework\Cache\ReverseProxy\AbstractReverseProxyGateway', 'tag', 2, 'response', new ObjectType('Symfony\Component\HttpFoundation\Response')),
]
],
);

$rectorConfig->ruleWithConfiguration(
ArgumentAdderRector::class,
[
new ArgumentAdder('Shopware\Core\Content\Media\Thumbnail\ThumbnailService', 'updateThumbnails', 2, 'strict', false, new BooleanType()),
]
],
);

$rectorConfig->rule(AddBanAllToReverseProxyRector::class);
Expand Down
83 changes: 40 additions & 43 deletions new.php
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
<?php

use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
<?php declare(strict_types=1);

$place = $_SERVER['argv'][1];
$name = $_SERVER['argv'][2];

$rectorTpl = <<<'RECTOR'
<?php
<?php
namespace #NAMESPACE#;
namespace #NAMESPACE#;
use PhpParser\Node;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use PhpParser\Node;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
class #NAME# extends AbstractRector
{
public function getRuleDefinition(): RuleDefinition
class #NAME# extends AbstractRector
{
return new RuleDefinition('NAME', [
new CodeSample(
<<<'CODE_SAMPLE'
class Foo implements Test {
}
CODE_SAMPLE
,
<<<'PHP'
class Foo extends AbstractTest {
}
PHP
),
]);
}
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('NAME', [
new CodeSample(
<<<'CODE_SAMPLE'
class Foo implements Test {
public function getNodeTypes(): array
{
return [
Node\Stmt\Class_::class,
];
}
CODE_SAMPLE
,
<<<'PHP'
class Foo extends AbstractTest {
/**
* @param Node\Stmt\Class_ $node
*/
public function refactor(Node $node): ?Node
{
return null;
}
}
RECTOR;
PHP
),
]);
}
public function getNodeTypes(): array
{
return [
Node\Stmt\Class_::class,
];
}
/**
* @param Node\Stmt\Class_ $node
*/
public function refactor(Node $node): ?Node
{
return null;
}
}
RECTOR;

$vals = [
'#NAMESPACE#' => 'Frosh\Rector\Rule\\' . $place,
'#NAME#' => $name,
];
$rector = str_replace(array_keys($vals), $vals, $rectorTpl);

file_put_contents(sprintf('%s/src/Rule/%s/%s.php', __DIR__, $place, $name), $rector,LOCK_EX);
file_put_contents(sprintf('%s/src/Rule/%s/%s.php', __DIR__, $place, $name), $rector, \LOCK_EX);
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src'
__DIR__ . '/src',
]);

$rectorConfig->importNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ public function getRuleDefinition(): RuleDefinition
return new RuleDefinition('NAME', [
new ConfiguredCodeSample(
<<<'PHP'
class Foo {
public function __construct(array $foo = [])
{
}
}
PHP
class Foo {
public function __construct(array $foo = [])
{
}
}
PHP
,
<<<'PHP'
class Foo {
public function __construct(array $foo)
{
}
}
PHP,
[new MakeClassConstructorArgumentRequired('Foo', 0, new ArrayType(new StringType(), new StringType()))]
class Foo {
public function __construct(array $foo)
{
}
}
PHP,
[new MakeClassConstructorArgumentRequired('Foo', 0, new ArrayType(new StringType(), new StringType()))],
),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Frosh\Rector\Rule\ClassConstructor;

use function array_values;
use Frosh\Rector\Rule\ClassMethod\AddArgumentToClassWithoutDefault;
use PhpParser\Node;
use PhpParser\Node\Expr\New_;
Expand All @@ -29,18 +28,18 @@ public function getRuleDefinition(): RuleDefinition
[
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
$someObject = new SomeExampleClass($example);
CODE_SAMPLE
$someObject = new SomeExampleClass($example);
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
$someObject = new SomeExampleClass();
CODE_SAMPLE
$someObject = new SomeExampleClass();
CODE_SAMPLE
,
[
new RemoveArgumentFromClassConstruct('SomeExampleClass', 0),
]
],
),
]
],
);
}

Expand All @@ -66,7 +65,6 @@ public function refactor(Node $node)

/**
* @param AddArgumentToClassWithoutDefault[] $configuration
* @return void
*/
public function configure(array $configuration): void
{
Expand All @@ -91,7 +89,7 @@ private function rebuildNew(New_ $node): ?Node
}

if ($hasChanged) {
$node->args = array_values($node->args);
$node->args = \array_values($node->args);

return $node;
}
Expand Down Expand Up @@ -127,7 +125,7 @@ private function rebuildConstructor(ClassMethod $node): ?Node
}

if ($hasChanged) {
$node->params = array_values($node->params);
$node->params = \array_values($node->params);

return $node;
}
Expand Down
Loading

0 comments on commit 5d1f28b

Please sign in to comment.