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

Add first rule for sulu rector #1

Merged
merged 3 commits into from
May 12, 2022
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
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ jobs:
dependency-versions: ${{ matrix.dependency-versions }}

- name: Execute test cases
run: time composer test

run: composer test

php-lint:
name: "PHP Lint"
Expand Down
13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.6",
"jackalope/jackalope-doctrine-dbal": "^1.7",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.6",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpunit/phpunit": "^9.5",
"rector/rector-src": "dev-main",
"rector/rector": "dev-main",
"sulu/sulu": "^2.5@dev",
"thecodingmachine/phpstan-strict-rules": "^1.0"
},
"autoload": {
Expand All @@ -41,8 +43,15 @@
"scripts": {
"lint": [
"@php-cs",
"@lint-composer"
"@lint-composer",
"@lint-rector"
],
"fix": [
"@php-cs-fix",
"@rector"
],
"lint-rector": "@php vendor/bin/rector process --dry-run",
"rector": "@php vendor/bin/rector process",
"lint-composer": "@composer validate --strict",
"phpstan": "@php vendor/bin/phpstan analyze",
"php-cs": "@php vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
Expand Down
2 changes: 1 addition & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
->autowire()
->autoconfigure();

$services->load('Sulu\\Rector', __DIR__ . '/../src')
$services->load('Sulu\\Rector\\', __DIR__ . '/../src')
->exclude([__DIR__ . '/../src/{Rector,ValueObject}']);

$rectorConfig->rule(RenameClassNonPhpRector::class);
Expand Down
22 changes: 21 additions & 1 deletion config/sets/sulu/sulu-24.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;

return static function (RectorConfig $rectorConfig): void {
// TODO configure upgrades
$rectorConfig
->ruleWithConfiguration(RenameMethodRector::class, [
// @see https://github.com/sulu/sulu/pull/6071
new MethodCallRename(
'Sulu\Component\Localization\Localization',
'setXDefault',
'setDefault',
),
new MethodCallRename(
'Sulu\Component\Localization\Localization',
'getXDefault',
'getDefault',
),
new MethodCallRename(
'Sulu\Component\Localization\Localization',
'isXDefault',
'isDefault',
),
]);
};
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ parameters:
- config
- src
- tests

level: max

scanDirectories:
- stubs

bootstrapFiles:
- vendor/rector/rector/vendor/scoper-autoload.php


ignoreErrors:
# allowed on null-safe calls
-
message: '#Do not use chained method calls\. Put each on separated lines#'
path: config/config.php
22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
failOnRisky="true"
failOnIncomplete="true"
>
<testsuites>
<testsuite name="Project Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
<directory suffix=".php">config</directory>
</include>
</coverage>
</phpunit>
25 changes: 25 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

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

$rectorConfig->parallel();

// for testing
$rectorConfig->import(__DIR__ . '/config/config.php');

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::NAMING,
]);
};
25 changes: 25 additions & 0 deletions tests/Set/Sulu24/Fixture/localization.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

class SomeClass {
public function someMethod(\Sulu\Component\Localization\Localization $localization)
{
$localization->setXDefault('en');
$localization->getXDefault();
$localization->isXDefault();
}
}

?>
---
<?php

class SomeClass {
public function someMethod(\Sulu\Component\Localization\Localization $localization)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this class exist in "require-dev" dependencies of composer.json or local /stubs directory?

Without existing class, PHPStan cannot find it nor analyse it.

{
$localization->setDefault('en');
$localization->getDefault();
$localization->isDefault();
}
}

?>
33 changes: 33 additions & 0 deletions tests/Set/Sulu24/Sulu24Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Rector\Symfony\Tests\Set\Symfony43;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class Sulu24Test extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}

/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/sulu-24.php';
}
}
11 changes: 11 additions & 0 deletions tests/Set/Sulu24/config/sulu-24.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Sulu\Rector\Set\SuluSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../config/config.php');
$rectorConfig->sets([SuluSetList::SULU_24]);
};