Skip to content

Commit

Permalink
[Core] fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Aug 12, 2022
1 parent eaca1e2 commit f7de804
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 125 deletions.
12 changes: 6 additions & 6 deletions composer.json
Expand Up @@ -61,31 +61,30 @@
"symfony/web-link": "^5.4 || ^6.0",
"symfony/webpack-encore-bundle": "^1.8",
"symfony/yaml": "^5.4 || ^6.0",
"thecodingmachine/safe": "^1.3 || ^2.1",
"thecodingmachine/safe": "^1.3 || ^2.2",
"twig/intl-extra": "^3.2",
"vich/uploader-bundle": "^1.16",
"villfa/invert-color": "^0.5",
"wyrihaximus/html-compress": "^4.1"
"wyrihaximus/html-compress": "^4.2"
},
"require-dev": {
"composer/composer": "^2.0",
"friendsofphp/php-cs-fixer": "^3.2",
"friendsoftwig/twigcs": "^5.0",
"friendsoftwig/twigcs": "^6.0",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-doctrine": "^1.0",
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-symfony": "^3.1",
"rector/rector": "^0.12",
"rector/rector": "^0.13",
"squizlabs/php_codesniffer": "^3.5",
"symfony/debug": "^4.4",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/maker-bundle": "^1.35",
"symfony/panther": "^1 || ^2.0",
"symfony/phpunit-bridge": "^5.0 || ^6.0",
"symfony/profiler-pack": "^1.0",
"symfony/test-pack": "^1.0",
"symplify/monorepo-builder": "^10.0",
"symplify/monorepo-builder": "^11.1",
"vimeo/psalm": "^4",
"weirdan/doctrine-psalm-plugin": "^2.0"
},
Expand Down Expand Up @@ -140,6 +139,7 @@
"assets": "./.scripts/generate-assets",
"publish-js-helper": "cd packages/js-helper && npm version patch && cd ../../ && git add packages/js-helper/. && git commit -m 'update pushword/js-helper version' && git push && cd packages/js-helper && npm publish",
"docs": "./.scripts/generate-docs",
"rector": "vendor/bin/rector process --dry-run",
"reset-skeleton": "./.scripts/reset-skeleton"
},
"config": {
Expand Down
6 changes: 6 additions & 0 deletions packages/admin/src/AdminTrait.php
Expand Up @@ -153,6 +153,8 @@ public function getTwig(): Twig
}

/**
* @noRector
*
* @param class-string<PageInterface> $pageClass
*/
public function setPageClass($pageClass): void
Expand All @@ -172,6 +174,8 @@ public function getApps(): AppPool
}

/**
* @noRector
*
* @param class-string<MediaInterface> $mediaClass
*/
public function setMediaClass($mediaClass): void
Expand All @@ -180,6 +184,8 @@ public function setMediaClass($mediaClass): void
}

/**
* @noRector
*
* @param class-string<UserInterface> $userClass
*/
public function setUserClass($userClass): void
Expand Down
Expand Up @@ -31,6 +31,8 @@ public function __construct(private TranslatorInterface $translator, private App
}

/**
* @noRector
*
* @return class-string<ConversationFormInterface>
*/
private function getFormManagerClass(string $type)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/composer.json
Expand Up @@ -52,7 +52,7 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.17",
"friendsoftwig/twigcs": "^4.0",
"friendsoftwig/twigcs": "^6.0",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.5",
"symfony/phpunit-bridge": "^5.0",
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/Component/App/AppConfig.php
Expand Up @@ -118,10 +118,7 @@ public function get(string $key)
return $this->getCustomProperty($key);
}

/**
* @param mixed $value
*/
public function setCustomProperty(string $key, $value): self
public function setCustomProperty(string $key, mixed $value): self
{
$camelCaseKey = static::normalizePropertyName($key);
if (property_exists($this, $camelCaseKey)) {
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/Component/EntityFilter/Filter/Extended.php
Expand Up @@ -23,12 +23,7 @@ public function apply($propertyValue)
return $this->loadExtendedValue($propertyValue);
}

/**
* @param mixed $propertyValue
*
* @return mixed
*/
private function loadExtendedValue($propertyValue)
private function loadExtendedValue(mixed $propertyValue): mixed
{
if ('' !== $propertyValue || ! $this->entity instanceof PageInterface || ! $this->entity->getExtendedPage() instanceof PageInterface) {
return $propertyValue;
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/Component/EntityFilter/Manager.php
Expand Up @@ -73,12 +73,8 @@ public function __call(string $method, array $arguments = [])
/**
* main_content => apply filters on mainContent (*_filters => camelCase(*))
* string => apply filters on each string property.
*
* @param mixed $propertyValue
*
* @return mixed
*/
private function filter(string $property, $propertyValue)
private function filter(string $property, mixed $propertyValue): mixed
{
$filters = $this->getFilters($this->camelCaseToSnakeCase($property));

Expand Down Expand Up @@ -168,12 +164,11 @@ private function getFilterClass(string $filter): FilterInterface
}

/**
* @param mixed $propertyValue
* @param string[] $filters
*
* @return mixed
*/
private function applyFilters(string $property, $propertyValue, array $filters)
private function applyFilters(string $property, mixed $propertyValue, array $filters)
{
foreach ($filters as $filter) {
if ($this->entity instanceof CustomPropertiesInterface
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Controller/PageController.php
Expand Up @@ -122,6 +122,7 @@ public function showMainFeed(Request $request, string $host = ''): Response
if (null === $page) {
throw $this->createNotFoundException('The page `'.$slug.'` was not found');
}

$request->setLocale($page->getLocale());

$params = [
Expand Down
Expand Up @@ -20,10 +20,7 @@ public function setStandAloneCustomProperties(?string $standStandAloneCustomProp

public function isStandAloneCustomProperty(string $name): bool;

/**
* @param mixed $value
*/
public function setCustomProperty(string $name, $value): self;
public function setCustomProperty(string $name, mixed $value): self;

/**
* @return mixed
Expand Down
Expand Up @@ -135,10 +135,7 @@ public function isStandAloneCustomProperty(string $name): bool
return ! method_exists($this, 'set'.ucfirst($name)) && ! method_exists($this, 'set'.$name);
}

/**
* @param mixed $value
*/
public function setCustomProperty(string $name, $value): self
public function setCustomProperty(string $name, mixed $value): self
{
$this->customProperties[$name] = $value;

Expand Down
Expand Up @@ -16,7 +16,7 @@
{# sm:grid-cols-2 sm:grid-cols-3 sm:grid-cols-4 #}
{% for name, image in images %}

{{ gallery_li_opener|default('<li>') }}
{{ gallery_li_opener|default('<li>')|raw }}
{{ _self.gallery_part(
media_from_string(image, name),
gallery_id, page ?? null,
Expand Down
1 change: 1 addition & 0 deletions packages/docs/content/roadmap.md
Expand Up @@ -7,6 +7,7 @@ parent: contribute

## BugFix && To finish

- Rectorize with all List
- Scan : ajouter un check des liens vides `"></a`
- AdminBlockEditor : new list item, évitez d'ajouter le lien d'avant sans ancre...
- Implement ESlint
Expand Down
154 changes: 62 additions & 92 deletions rector.php
Expand Up @@ -12,6 +12,7 @@
use Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Core\Bootstrap\RectorConfigsResolver;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DeadCode\Rector\Assign\RemoveAssignOfVoidReturnFunctionRector;
Expand Down Expand Up @@ -50,104 +51,73 @@
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\PHPStanTwigRules\Rules\NoTwigMissingVariableRule;
use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->parallel();

$parameters->set(
Option::PATHS,
array_map(
$rectorConfig->paths(array_map(
function ($path) { return __DIR__.'/'.$path; },
array_values(json_decode(file_get_contents('composer.json'), true)['autoload']['psr-4'])
)
);
));

$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80);

//$containerConfigurator->import(SetList::DEAD_CODE);
//$containerConfigurator->import(SymfonySetList::SYMFONY_CODE_QUALITY);

$tmp = [
//SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION, => Ok
//SetList::CODE_QUALITY,
//SetList::CODING_STYLE,
//SetList::FRAMEWORK_EXTRA_BUNDLE_50, => OK
//SetList::NAMING,
//SetList::PHP_74, => OK
//SetList::PSR_4, => not applied for config files
//SetList::SAFE_07, => ok, cool
//SetList::TYPE_DECLARATION,
//SetList::TYPE_DECLARATION_STRICT,
//SymfonySetList::SYMFONY_52, => OK
//SymfonySetList::SYMFONY_CODE_QUALITY, => OK
//SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION, => OK
//DoctrineSetList::DOCTRINE_ORM_29, => Ok
//DoctrineSetList::DOCTRINE_DBAL_30,
//DoctrineSetList::DOCTRINE_CODE_QUALITY, => OK
//DoctrineSetList::DOCTRINE_25, => failed
//PHPUnitSetList::PHPUNIT_91,
//PHPUnitSetList::PHPUNIT_CODE_QUALITY,
];

//$containerConfigurator->import(SetList::TYPE_DECLARATION);
$containerConfigurator->import(SetList::PHP_80);

$services = $containerConfigurator->services();
//$services->set(VarConstantCommentRector::class);
$services->set(CombinedAssignRector::class);
$services->set(SimplifyConditionsRector::class);
$services->set(SimplifyDeMorganBinaryRector::class);
$services->set(SimplifyForeachToCoalescingRector::class);
$services->set(SimplifyIfReturnBoolRector::class);
$services->set(StrContainsRector::class);
$services->set(StrEndsWithRector::class);
$services->set(StrStartsWithRector::class);
$services->set(CatchExceptionNameMatchingTypeRector::class);
$services->set(MakeInheritedMethodVisibilitySameAsParentRector::class);
$services->set(NewlineAfterStatementRector::class);
$services->set(CatchExceptionNameMatchingTypeRector::class);
$services->set(ReturnTypeFromStrictTypedCallRector::class);
$services->set(AddMethodCallBasedStrictParamTypeRector::class);
$services->set(AddVoidReturnTypeWhereNoReturnRector::class);
$services->set(ReturnTypeFromStrictTypedPropertyRector::class);
$services->set(TypedPropertyFromStrictConstructorRector::class);
$services->set(AddClosureReturnTypeRector::class);
$services->set(ReturnTypeFromReturnNewRector::class);
//$services->set(AddArrayReturnDocTypeRector::class); //=> false|... replaced by bool|...
$services->set(ReturnTypeDeclarationRector::class);
$services->set(PropertyTypeDeclarationRector::class);
$services->set(AddArrayParamDocTypeRector::class);
$services->set(ParamTypeByParentCallTypeRector::class);
$services->set(ParamTypeByMethodCallTypeRector::class);
$services->set(ParamTypeDeclarationRector::class);
$services->set(SimplifyBoolIdenticalTrueRector::class);
$services->set(RecastingRemovalRector::class);
$services->set(RemoveAlwaysTrueIfConditionRector::class);
$services->set(RemoveAndTrueRector::class);
$services->set(RemoveDeadIfForeachForRector::class);
$services->set(AddArrayParamDocTypeRector::class);
$services->set(AddClosureReturnTypeRector::class);
$services->set(AddMethodCallBasedStrictParamTypeRector::class);
//$services->set(RemoveNullPropertyInitializationRector::class);
$services->set(RemoveUselessParamTagRector::class);
$services->set(BooleanInIfConditionRuleFixerRector::class)
->call('configure', [[
BooleanInIfConditionRuleFixerRector::TREAT_AS_NON_EMPTY => false,
]]);
$services->set(BooleanInTernaryOperatorRuleFixerRector::class)
->call('configure', [[
//$parameters->rule(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80);
//$containerConfigurator->import(SetList::PHP_80);
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
// SetList::CODE_QUALITY,
// SetList::DEAD_CODE,
// SetList::CODING_STYLE,
// SetList::TYPE_DECLARATION,
// SetList::TYPE_DECLARATION_STRICT,
// SetList::NAMING,
// SetList::PRIVATIZATION,
// SetList::EARLY_RETURN,
// PHPUnitSetList::PHPUNIT_CODE_QUALITY,
]);
$rectorConfig->rule(CombinedAssignRector::class);
$rectorConfig->rule(SimplifyConditionsRector::class);
$rectorConfig->rule(SimplifyDeMorganBinaryRector::class);
$rectorConfig->rule(SimplifyForeachToCoalescingRector::class);
$rectorConfig->rule(SimplifyIfReturnBoolRector::class);
$rectorConfig->rule(StrContainsRector::class);
$rectorConfig->rule(StrEndsWithRector::class);
$rectorConfig->rule(StrStartsWithRector::class);
$rectorConfig->rule(CatchExceptionNameMatchingTypeRector::class);
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
$rectorConfig->rule(NewlineAfterStatementRector::class);
$rectorConfig->rule(CatchExceptionNameMatchingTypeRector::class);
$rectorConfig->rule(AddMethodCallBasedStrictParamTypeRector::class);
$rectorConfig->rule(AddVoidReturnTypeWhereNoReturnRector::class);
$rectorConfig->rule(ReturnTypeFromStrictTypedPropertyRector::class);
$rectorConfig->rule(TypedPropertyFromStrictConstructorRector::class);
$rectorConfig->rule(AddClosureReturnTypeRector::class);
$rectorConfig->rule(ReturnTypeFromReturnNewRector::class);
$rectorConfig->rule(ReturnTypeDeclarationRector::class);
$rectorConfig->rule(PropertyTypeDeclarationRector::class);
$rectorConfig->rule(AddArrayParamDocTypeRector::class);
$rectorConfig->rule(ParamTypeByParentCallTypeRector::class);
$rectorConfig->rule(ParamTypeByMethodCallTypeRector::class);
$rectorConfig->rule(ParamTypeDeclarationRector::class);
//$rectorConfig->rule(SimplifyBoolIdenticalTrueRector::class);
$rectorConfig->rule(RecastingRemovalRector::class);
$rectorConfig->rule(RemoveAlwaysTrueIfConditionRector::class);
$rectorConfig->rule(RemoveAndTrueRector::class);
$rectorConfig->rule(RemoveDeadIfForeachForRector::class);
$rectorConfig->rule(AddArrayParamDocTypeRector::class);
$rectorConfig->rule(AddClosureReturnTypeRector::class);
$rectorConfig->rule(AddMethodCallBasedStrictParamTypeRector::class);
//$rectorConfig->rule(RemoveNullPropertyInitializationRector::class);
$rectorConfig->rule(RemoveUselessParamTagRector::class);
$rectorConfig->ruleWithConfiguration(BooleanInTernaryOperatorRuleFixerRector::class, [
BooleanInTernaryOperatorRuleFixerRector::TREAT_AS_NON_EMPTY => false,
]]);
$services->set(DisallowedEmptyRuleFixerRector::class)
->call('configure', [[
]);
$rectorConfig->ruleWithConfiguration(DisallowedEmptyRuleFixerRector::class, [
DisallowedEmptyRuleFixerRector::TREAT_AS_NON_EMPTY => false,
]]);
$services->set(DisallowedShortTernaryRuleFixerRector::class)
->call('configure', [[
]);
$rectorConfig->ruleWithConfiguration(DisallowedShortTernaryRuleFixerRector::class, [
DisallowedShortTernaryRuleFixerRector::TREAT_AS_NON_EMPTY => false,
]]);
//$services->set(NoTwigMissingVariableRule::class)
//$services->set(ChangeLocalPropertyToVariableRector::class);
//$services->set(RemoveUselessReturnTagRector::class); // remove array<mixed> OK is useless, need to configure PHPstan before
]);
};

0 comments on commit f7de804

Please sign in to comment.