[Silverstripe] deprecate, handled by community

This commit is contained in:
TomasVotruba 2020-05-13 17:35:28 +02:00
parent c9c2287d70
commit a3bfaed373
11 changed files with 5 additions and 258 deletions

View File

@ -123,7 +123,6 @@
"Rector\\NodeNestingScope\\": "packages/node-nesting-scope/src",
"Rector\\Sensio\\": "rules/sensio/src",
"Rector\\Shopware\\": "rules/shopware/src",
"Rector\\Silverstripe\\": "rules/silverstripe/src",
"Rector\\StaticTypeMapper\\": "packages/static-type-mapper/src",
"Rector\\StrictCodeQuality\\": "rules/strict-code-quality/src",
"Rector\\Sylius\\": "rules/sylius/src",
@ -194,7 +193,6 @@
"Rector\\SOLID\\Tests\\": "rules/solid/tests",
"Rector\\Sensio\\Tests\\": "rules/sensio/tests",
"Rector\\Shopware\\Tests\\": "rules/shopware/tests",
"Rector\\Silverstripe\\Tests\\": "rules/silverstripe/tests",
"Rector\\StrictCodeQuality\\Tests\\": "rules/strict-code-quality/tests",
"Rector\\Sylius\\Tests\\": "rules/sylius/tests",
"Rector\\SymfonyCodeQuality\\Tests\\": "rules/symfony-code-quality/tests",

View File

@ -1,5 +0,0 @@
# various versions
services:
# https://github.com/silverstripe/silverstripe-upgrader/issues/76
Rector\Silverstripe\Rector\ConstantToStaticCallRector: null
Rector\Silverstripe\Rector\DefineConstantToStaticCallRector: null

View File

@ -87,6 +87,7 @@ services:
### Similar Projects
- [ClangMR](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/41342.pdf) for C++ by Google (closed source) - almost idential workflow, developed independently though
- [hhast](https://github.com/hhvm/hhast) - HHVM AST + format preserving + mirations
- [facebook/jscodeshift](https://github.com/facebook/jscodeshift) for Javascript
- [silverstripe/silverstripe-upgrader](https://github.com/silverstripe/silverstripe-upgrader) for PHP CMS, Silverstripe
- [dereuromark/upgrade](https://github.com/dereuromark/upgrade) for PHP Framework, CakePHP

View File

@ -1,4 +1,4 @@
# All 490 Rectors Overview
# All 488 Rectors Overview
- [Projects](#projects)
- [General](#general)
@ -59,7 +59,6 @@
- [SOLID](#solid) (11)
- [Sensio](#sensio) (1)
- [Shopware](#shopware) (3)
- [Silverstripe](#silverstripe) (2)
- [StrictCodeQuality](#strictcodequality) (1)
- [Sylius](#sylius) (1)
- [Symfony](#symfony) (29)
@ -4147,7 +4146,7 @@ Change singleton class to normal class that can be registered as a service
### `FunctionToStaticMethodRector`
- class: [`Rector\Legacy\Rector\Node\FunctionToStaticMethodRector`](/../master/rules/legacy/src/Rector/Node/FunctionToStaticMethodRector.php)
- class: [`Rector\Legacy\Rector\FileSystem\FunctionToStaticMethodRector`](/../master/rules/legacy/src/Rector/FileSystem/FunctionToStaticMethodRector.php)
Change functions to static calls, so composer can autoload them
@ -9282,36 +9281,6 @@ Use version from di parameter
<br>
## Silverstripe
### `ConstantToStaticCallRector`
- class: [`Rector\Silverstripe\Rector\ConstantToStaticCallRector`](/../master/rules/silverstripe/src/Rector/ConstantToStaticCallRector.php)
- [test fixtures](/../master/rules/silverstripe/tests/Rector/ConstantToStaticCallRector/Fixture)
Turns defined constant to static method call.
```diff
-SS_DATABASE_NAME;
+Environment::getEnv("SS_DATABASE_NAME");
```
<br>
### `DefineConstantToStaticCallRector`
- class: [`Rector\Silverstripe\Rector\DefineConstantToStaticCallRector`](/../master/rules/silverstripe/src/Rector/DefineConstantToStaticCallRector.php)
- [test fixtures](/../master/rules/silverstripe/tests/Rector/DefineConstantToStaticCallRector/Fixture)
Turns defined function call to static method call.
```diff
-defined("SS_DATABASE_NAME");
+Environment::getEnv("SS_DATABASE_NAME");
```
<br>
## StrictCodeQuality
### `VarInlineAnnotationToAssertRector`

View File

@ -1,51 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Silverstripe\Rector;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
/**
* @see \Rector\Silverstripe\Tests\Rector\ConstantToStaticCallRector\ConstantToStaticCallRectorTest
*/
final class ConstantToStaticCallRector extends AbstractRector
{
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns defined constant to static method call.', [
new CodeSample('SS_DATABASE_NAME;', 'Environment::getEnv("SS_DATABASE_NAME");'),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [ConstFetch::class];
}
/**
* @param ConstFetch $node
*/
public function refactor(Node $node): ?Node
{
$constantName = $this->getName($node);
if ($constantName === null) {
return null;
}
if (! Strings::startsWith($constantName, 'SS_')) {
return null;
}
return $this->createStaticCall('Environment', 'getEnv', [new String_($constantName)]);
}
}

View File

@ -1,59 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Silverstripe\Rector;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
/**
* @see \Rector\Silverstripe\Tests\Rector\DefineConstantToStaticCallRector\DefineConstantToStaticCallRectorTest
*/
final class DefineConstantToStaticCallRector extends AbstractRector
{
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns defined function call to static method call.', [
new CodeSample('defined("SS_DATABASE_NAME");', 'Environment::getEnv("SS_DATABASE_NAME");'),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(Node $node): ?Node
{
if (count($node->args) !== 1) {
return null;
}
if (! $this->isName($node, 'defined')) {
return null;
}
$argumentValue = $node->args[0]->value;
if (! $argumentValue instanceof String_) {
return null;
}
if (! Strings::startsWith($argumentValue->value, 'SS_')) {
return null;
}
return $this->createStaticCall('Environment', 'getEnv', $node->args);
}
}

View File

@ -1,30 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Silverstripe\Tests\Rector\ConstantToStaticCallRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Silverstripe\Rector\ConstantToStaticCallRector;
final class ConstantToStaticCallRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $file): void
{
$this->doTestFile($file);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return ConstantToStaticCallRector::class;
}
}

View File

@ -1,21 +0,0 @@
<?php
function constantToStaticCall()
{
if (defined('SS_DATABASE_NAME')) {
echo SS_DATABASENAME;
}
}
?>
-----
<?php
function constantToStaticCall()
{
if (defined('SS_DATABASE_NAME')) {
echo \Environment::getEnv('SS_DATABASENAME');
}
}
?>

View File

@ -1,30 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Silverstripe\Tests\Rector\DefineConstantToStaticCallRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Silverstripe\Rector\DefineConstantToStaticCallRector;
final class DefineConstantToStaticCallRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $file): void
{
$this->doTestFile($file);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return DefineConstantToStaticCallRector::class;
}
}

View File

@ -1,25 +0,0 @@
<?php
namespace Rector\Silverstripe\Tests\Rector\DefineConstantToStaticCallRector\Fixture;
function defineConstantToStaticCall()
{
if (defined('SS_DATABASE_NAME')) {
echo SS_DATABASENAME;
}
}
?>
-----
<?php
namespace Rector\Silverstripe\Tests\Rector\DefineConstantToStaticCallRector\Fixture;
function defineConstantToStaticCall()
{
if (\Environment::getEnv('SS_DATABASE_NAME')) {
echo SS_DATABASENAME;
}
}
?>

View File

@ -4,9 +4,9 @@ sonar.projectKey=rectorphp_rector
# relative paths to source
# wildcards don't work :(
sonar.sources=compiler/src,src,rules/autodiscovery/src,rules/architecture/src,packages/attribute-aware-php-doc/src,packages/better-php-doc-parser/src,rules/cakephp/src,rules/celebrity/src,rules/code-quality/src,rules/coding-style/src,packages/console-differ/src,rules/dead-code/src,rules/doctrine/src,rules/doctrine-code-quality/src,rules/framework-migration/src,packages/file-system-rector/src,rules/elastic-search-dsl/src,rules/guzzle/src,rules/laravel/src,rules/legacy/src,rules/mysql-to-mysqli/src,rules/nette-tester-to-phpunit/src,rules/nette-to-symfony/src,rules/nette/src,packages/node-collector/src,packages/node-type-resolver/src,packages/node-name-resolver/src,rules/phpstan/src,packages/phpstan-static-type-mapper/src,rules/phpunit-symfony/src,rules/phpunit/src,rules/psr4/src,rules/php-spec-to-phpunit/src,rules/php52/src,rules/php53/src,rules/php54/src,rules/php55/src,rules/php56/src,rules/php70/src,rules/php71/src,rules/php72/src,rules/php73/src,rules/php74/src,rules/php80/src,rules/removing-static/src,rules/renaming/src,rules/restoration/src,packages/refactoring/src,rules/solid/src,rules/sensio/src,rules/shopware/src,rules/silverstripe/src,packages/static-type-mapper/src,rules/sylius/src,rules/symfony-code-quality/src,rules/symfony-phpunit/src,rules/symfony/src,rules/twig/src,rules/type-declaration/src,packages/vendor-locker/src,packages/rector-generator/src,rules/strict-code-quality/src,packages/dynamic-type-analysis/src,rules/php-deglobalize/src,rules/phalcon/src,rules/doctrine-gedmo-to-knplabs/src,packages/polyfill/src
sonar.sources=compiler/src,src,rules/autodiscovery/src,rules/architecture/src,packages/attribute-aware-php-doc/src,packages/better-php-doc-parser/src,rules/cakephp/src,rules/celebrity/src,rules/code-quality/src,rules/coding-style/src,packages/console-differ/src,rules/dead-code/src,rules/doctrine/src,rules/doctrine-code-quality/src,rules/framework-migration/src,packages/file-system-rector/src,rules/elastic-search-dsl/src,rules/guzzle/src,rules/laravel/src,rules/legacy/src,rules/mysql-to-mysqli/src,rules/nette-tester-to-phpunit/src,rules/nette-to-symfony/src,rules/nette/src,packages/node-collector/src,packages/node-type-resolver/src,packages/node-name-resolver/src,rules/phpstan/src,packages/phpstan-static-type-mapper/src,rules/phpunit-symfony/src,rules/phpunit/src,rules/psr4/src,rules/php-spec-to-phpunit/src,rules/php52/src,rules/php53/src,rules/php54/src,rules/php55/src,rules/php56/src,rules/php70/src,rules/php71/src,rules/php72/src,rules/php73/src,rules/php74/src,rules/php80/src,rules/removing-static/src,rules/renaming/src,rules/restoration/src,packages/refactoring/src,rules/solid/src,rules/sensio/src,rules/shopware/src,packages/static-type-mapper/src,rules/sylius/src,rules/symfony-code-quality/src,rules/symfony-phpunit/src,rules/symfony/src,rules/twig/src,rules/type-declaration/src,packages/vendor-locker/src,packages/rector-generator/src,rules/strict-code-quality/src,packages/dynamic-type-analysis/src,rules/php-deglobalize/src,rules/phalcon/src,rules/doctrine-gedmo-to-knplabs/src,packages/polyfill/src
sonar.tests=tests,rules/autodiscovery/tests,rules/architecture/tests,packages/better-php-doc-parser/tests,rules/cakephp/tests,rules/celebrity/tests,rules/code-quality/tests,rules/coding-style/tests,rules/dead-code/tests,rules/doctrine/tests,rules/doctrine-code-quality/tests,rules/elastic-search-dsl/tests,rules/guzzle/tests,rules/laravel/tests,rules/legacy/tests,rules/mysql-to-mysqli/tests,rules/nette-tester-to-phpunit/tests,rules/nette-to-symfony/tests,rules/nette/tests,packages/node-type-resolver/tests,utils/phpstan-extensions/src,rules/phpstan/tests,rules/phpunit-symfony/tests,rules/phpunit/tests,rules/psr4/tests,rules/php-spec-to-phpunit/tests,rules/php52/tests,rules/php53/tests,rules/php54/tests,rules/php55/tests,rules/php56/tests,rules/php70/tests,rules/php71/tests,rules/php72/tests,rules/php73/tests,rules/php74/tests,rules/php80/tests,rules/removing-static/tests,rules/renaming/tests,rules/restoration/tests,rules/solid/tests,rules/sensio/tests,rules/shopware/tests,rules/silverstripe/tests,rules/sylius/tests,rules/symfony-code-quality/tests,rules/symfony-phpunit/tests,rules/symfony/tests,rules/twig/tests,rules/type-declaration/tests,rules/strict-code-quality/tests,packages/dynamic-type-analysis/tests,rules/php-deglobalize/tests,rules/phalcon/tests,utils/documentation-generator/src,utils/phpstan-attribute-type-syncer/src,utils/phpstan-static-type-mapper-checker/src,rules/doctrine-gedmo-to-knplabs/tests,packages/polyfill/tests
sonar.tests=tests,rules/autodiscovery/tests,rules/architecture/tests,packages/better-php-doc-parser/tests,rules/cakephp/tests,rules/celebrity/tests,rules/code-quality/tests,rules/coding-style/tests,rules/dead-code/tests,rules/doctrine/tests,rules/doctrine-code-quality/tests,rules/elastic-search-dsl/tests,rules/guzzle/tests,rules/laravel/tests,rules/legacy/tests,rules/mysql-to-mysqli/tests,rules/nette-tester-to-phpunit/tests,rules/nette-to-symfony/tests,rules/nette/tests,packages/node-type-resolver/tests,utils/phpstan-extensions/src,rules/phpstan/tests,rules/phpunit-symfony/tests,rules/phpunit/tests,rules/psr4/tests,rules/php-spec-to-phpunit/tests,rules/php52/tests,rules/php53/tests,rules/php54/tests,rules/php55/tests,rules/php56/tests,rules/php70/tests,rules/php71/tests,rules/php72/tests,rules/php73/tests,rules/php74/tests,rules/php80/tests,rules/removing-static/tests,rules/renaming/tests,rules/restoration/tests,rules/solid/tests,rules/sensio/tests,rules/shopware/tests,rules/sylius/tests,rules/symfony-code-quality/tests,rules/symfony-phpunit/tests,rules/symfony/tests,rules/twig/tests,rules/type-declaration/tests,rules/strict-code-quality/tests,packages/dynamic-type-analysis/tests,rules/php-deglobalize/tests,rules/phalcon/tests,utils/documentation-generator/src,utils/phpstan-attribute-type-syncer/src,utils/phpstan-static-type-mapper-checker/src,rules/doctrine-gedmo-to-knplabs/tests,packages/polyfill/tests
# see https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/#NarrowingtheFocus-patterns
sonar.exclusions=src/**/*.php.inc,rules/**/*.php.inc,packages/**/*.php.inc,packages/**/Fixture/**/*,rules/**/Fixture/**/*,tests/**/Source/**/*