From c8ea130b5959cf4e641bed4e2b4153d19d23cfdf Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 8 Nov 2022 21:15:39 +0100 Subject: [PATCH] TASK: Add some sensitive defaults for the config (#3207) --- config/config.php | 7 +++++++ config/config_test.php | 3 --- templates/rector.php.dist | 13 ------------- .../v8/v3/IconsRector/config/configured_rule.php | 1 - .../rename_and_initialize_arguments.php.inc | 2 +- .../Fixture/functional_test_fixture.php.inc | 4 ++-- .../Fixture/not_working_unit_test_fixture.php.inc | 12 ++++++------ .../Fixture/viewhelper_test_fixture.php.inc | 4 ++-- ...tom_exception_handler_with_constructor.php.inc | 3 +-- ..._exception_handler_without_constructor.php.inc | 3 +-- .../Fixture/validate_method.php.inc | 3 +-- .../Fixture/properties.php.inc | 15 +++++++-------- 12 files changed, 28 insertions(+), 42 deletions(-) diff --git a/config/config.php b/config/config.php index 893bda013..8361b5ad3 100644 --- a/config/config.php +++ b/config/config.php @@ -11,12 +11,19 @@ use Helmich\TypoScriptParser\Tokenizer\Tokenizer; use Helmich\TypoScriptParser\Tokenizer\TokenizerInterface; use Rector\Config\RectorConfig; +use Ssch\TYPO3Rector\Configuration\Typo3Option; use Ssch\TYPO3Rector\FileProcessor\TypoScript\TypoScriptFileProcessor; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; return static function (RectorConfig $rectorConfig): void { + $rectorConfig->disableParallel(); + $rectorConfig->importNames(); + $rectorConfig->phpstanConfig(Typo3Option::PHPSTAN_FOR_RECTOR_PATH); + // this will not import root namespace classes, like \DateTime or \Exception + $rectorConfig->importShortClasses(false); + $services = $rectorConfig->services(); $services->defaults() ->public() diff --git a/config/config_test.php b/config/config_test.php index 6be7d4172..b961b69ed 100644 --- a/config/config_test.php +++ b/config/config_test.php @@ -3,10 +3,7 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Ssch\TYPO3Rector\Configuration\Typo3Option; return static function (RectorConfig $rectorConfig): void { $rectorConfig->import(__DIR__ . '/config.php'); - $rectorConfig->importNames(); - $rectorConfig->phpstanConfig(Typo3Option::PHPSTAN_FOR_RECTOR_PATH); }; diff --git a/templates/rector.php.dist b/templates/rector.php.dist index 75aa5201f..d9a29b7d8 100644 --- a/templates/rector.php.dist +++ b/templates/rector.php.dist @@ -12,24 +12,11 @@ use Ssch\TYPO3Rector\Rector\General\ExtEmConfRector; use Ssch\TYPO3Rector\Set\Typo3LevelSetList; return static function (RectorConfig $rectorConfig): void { - $parameters = $rectorConfig->parameters(); $rectorConfig->sets([ Typo3LevelSetList::UP_TO_TYPO3_11, ]); - // In order to have a better analysis from phpstan we teach it here some more things - $rectorConfig->phpstanConfig(Typo3Option::PHPSTAN_FOR_RECTOR_PATH); - - // FQN classes are not imported by default. If you don't do it manually after every Rector run, enable it by: - $rectorConfig->importNames(); - - // Disable parallel otherwise non php file processing is not working i.e. typoscript - $rectorConfig->disableParallel(); - - // this will not import root namespace classes, like \DateTime or \Exception - $rectorConfig->importShortClasses(false); - // Define your target version which you want to support $rectorConfig->phpVersion(PhpVersion::PHP_74); diff --git a/tests/FileProcessor/Resources/Icons/Rector/v8/v3/IconsRector/config/configured_rule.php b/tests/FileProcessor/Resources/Icons/Rector/v8/v3/IconsRector/config/configured_rule.php index 159edadda..4050cfa71 100644 --- a/tests/FileProcessor/Resources/Icons/Rector/v8/v3/IconsRector/config/configured_rule.php +++ b/tests/FileProcessor/Resources/Icons/Rector/v8/v3/IconsRector/config/configured_rule.php @@ -7,6 +7,5 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->import(__DIR__ . '/../../../../../../../../../config/config_test.php'); - $rectorConfig->disableParallel(); $rectorConfig->rule(IconsRector::class); }; diff --git a/tests/Rector/Migrations/Fixture/rename_and_initialize_arguments.php.inc b/tests/Rector/Migrations/Fixture/rename_and_initialize_arguments.php.inc index 34aacf5f1..14afffb85 100644 --- a/tests/Rector/Migrations/Fixture/rename_and_initialize_arguments.php.inc +++ b/tests/Rector/Migrations/Fixture/rename_and_initialize_arguments.php.inc @@ -61,7 +61,7 @@ class MySpecialViewHelperWithFullQualifiedNamespaceLinkViewHelper extends Abstra return 'foo'; } - public function injectPluginSettingsService(MySpecialViewHelperWithFullQualifiedNamespaceLinkViewHelper $pluginSettingsService): void + public function injectPluginSettingsService(\MySpecialViewHelperWithFullQualifiedNamespaceLinkViewHelper $pluginSettingsService): void { $this->pluginSettingsService = $pluginSettingsService; } diff --git a/tests/Rector/Nimut/TestingFramework/Fixture/functional_test_fixture.php.inc b/tests/Rector/Nimut/TestingFramework/Fixture/functional_test_fixture.php.inc index a1b0fadab..fa5634165 100644 --- a/tests/Rector/Nimut/TestingFramework/Fixture/functional_test_fixture.php.inc +++ b/tests/Rector/Nimut/TestingFramework/Fixture/functional_test_fixture.php.inc @@ -15,9 +15,9 @@ class MyFunctionalTest extends FunctionalTestCase namespace Ssch\TYPO3Rector\Tests\Rector\Nimut\TestingFramework\Fixture; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class MyFunctionalTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase +class MyFunctionalTest extends FunctionalTestCase { } diff --git a/tests/Rector/Nimut/TestingFramework/Fixture/not_working_unit_test_fixture.php.inc b/tests/Rector/Nimut/TestingFramework/Fixture/not_working_unit_test_fixture.php.inc index 7f276ca81..cad9be0da 100644 --- a/tests/Rector/Nimut/TestingFramework/Fixture/not_working_unit_test_fixture.php.inc +++ b/tests/Rector/Nimut/TestingFramework/Fixture/not_working_unit_test_fixture.php.inc @@ -29,14 +29,14 @@ class MyUnitTest extends UnitTestCase namespace Ssch\TYPO3Rector\Tests\Rector\Nimut\TestingFramework\Fixture; -use Nimut\TestingFramework\Exception\Exception; -use Nimut\TestingFramework\MockObject\AccessibleMockObjectInterface; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; +use TYPO3\TestingFramework\Core\AccessibleObjectInterface; +use TYPO3\TestingFramework\Core\Exception; -class MyUnitTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase +class MyUnitTest extends UnitTestCase { /** - * @var \TYPO3\TestingFramework\Core\AccessibleObjectInterface + * @var AccessibleObjectInterface */ protected $fooBarBaz; @@ -44,7 +44,7 @@ class MyUnitTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase { try { - } catch (\TYPO3\TestingFramework\Core\Exception $e) { + } catch (Exception $e) { } } diff --git a/tests/Rector/Nimut/TestingFramework/Fixture/viewhelper_test_fixture.php.inc b/tests/Rector/Nimut/TestingFramework/Fixture/viewhelper_test_fixture.php.inc index d5fc3d214..556c9ae6d 100644 --- a/tests/Rector/Nimut/TestingFramework/Fixture/viewhelper_test_fixture.php.inc +++ b/tests/Rector/Nimut/TestingFramework/Fixture/viewhelper_test_fixture.php.inc @@ -15,9 +15,9 @@ class MyViewHelperTest extends ViewHelperBaseTestcase namespace Ssch\TYPO3Rector\Tests\Rector\Nimut\TestingFramework\Fixture; -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase; -class MyViewHelperTest extends \TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase +class MyViewHelperTest extends ViewHelperBaseTestcase { } diff --git a/tests/Rector/v11/v4/AddSetConfigurationMethodToExceptionHandlerRector/Fixture/custom_exception_handler_with_constructor.php.inc b/tests/Rector/v11/v4/AddSetConfigurationMethodToExceptionHandlerRector/Fixture/custom_exception_handler_with_constructor.php.inc index 6cd5417aa..9edd4e5b6 100644 --- a/tests/Rector/v11/v4/AddSetConfigurationMethodToExceptionHandlerRector/Fixture/custom_exception_handler_with_constructor.php.inc +++ b/tests/Rector/v11/v4/AddSetConfigurationMethodToExceptionHandlerRector/Fixture/custom_exception_handler_with_constructor.php.inc @@ -49,7 +49,6 @@ class MyCustomExceptionHandler implements ExceptionHandlerInterface namespace Ssch\TYPO3Rector\Tests\Rector\v11\v4\AddSetConfigurationMethodToExceptionHandlerRector\Fixture; -use Exception; use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject; use TYPO3\CMS\Frontend\ContentObject\Exception\ExceptionHandlerInterface; @@ -66,7 +65,7 @@ class MyCustomExceptionHandler implements ExceptionHandlerInterface { } - public function handle(Exception $exception, AbstractContentObject $contentObject = null, $contentObjectConfiguration = []) + public function handle(\Exception $exception, AbstractContentObject $contentObject = null, $contentObjectConfiguration = []) { $bar = $this->foo; $foo = $this->typoscriptConfiguration['foo']; diff --git a/tests/Rector/v11/v4/AddSetConfigurationMethodToExceptionHandlerRector/Fixture/custom_exception_handler_without_constructor.php.inc b/tests/Rector/v11/v4/AddSetConfigurationMethodToExceptionHandlerRector/Fixture/custom_exception_handler_without_constructor.php.inc index d593ea9c6..88612c0ad 100644 --- a/tests/Rector/v11/v4/AddSetConfigurationMethodToExceptionHandlerRector/Fixture/custom_exception_handler_without_constructor.php.inc +++ b/tests/Rector/v11/v4/AddSetConfigurationMethodToExceptionHandlerRector/Fixture/custom_exception_handler_without_constructor.php.inc @@ -18,13 +18,12 @@ class MyCustomExceptionHandler implements ExceptionHandlerInterface namespace Ssch\TYPO3Rector\Tests\Rector\v11\v4\AddSetConfigurationMethodToExceptionHandlerRector\Fixture; -use Exception; use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject; use TYPO3\CMS\Frontend\ContentObject\Exception\ExceptionHandlerInterface; class MyCustomExceptionHandler implements ExceptionHandlerInterface { - public function handle(Exception $exception, AbstractContentObject $contentObject = null, $contentObjectConfiguration = []) + public function handle(\Exception $exception, AbstractContentObject $contentObject = null, $contentObjectConfiguration = []) { } diff --git a/tests/Rector/v9/v3/ValidateAnnotationRector/Fixture/validate_method.php.inc b/tests/Rector/v9/v3/ValidateAnnotationRector/Fixture/validate_method.php.inc index 528672bd8..879dd2227 100644 --- a/tests/Rector/v9/v3/ValidateAnnotationRector/Fixture/validate_method.php.inc +++ b/tests/Rector/v9/v3/ValidateAnnotationRector/Fixture/validate_method.php.inc @@ -19,13 +19,12 @@ final class SomeControllerWithValidation namespace Ssch\TYPO3Rector\Tests\Rector\v9\v3\ValidateAnnotationRector\Fixture; use TYPO3\CMS\Extbase\Annotation as Extbase; -use stdClass; final class SomeControllerWithValidation { /** * @Extbase\Validate("\Foo\Bar\Domain\Validator\ChangePasswordValidator", param="changePassword") */ - public function updateAction(stdClass $changePassword) + public function updateAction(\stdClass $changePassword) { } } diff --git a/tests/Rector/v9/v4/UseClassSchemaInsteadReflectionServiceMethodsRector/Fixture/properties.php.inc b/tests/Rector/v9/v4/UseClassSchemaInsteadReflectionServiceMethodsRector/Fixture/properties.php.inc index e0f31801a..97602af6d 100644 --- a/tests/Rector/v9/v4/UseClassSchemaInsteadReflectionServiceMethodsRector/Fixture/properties.php.inc +++ b/tests/Rector/v9/v4/UseClassSchemaInsteadReflectionServiceMethodsRector/Fixture/properties.php.inc @@ -49,7 +49,6 @@ class MyService namespace Ssch\TYPO3Rector\Tests\Rector\v9\v4\UseClassSchemaInsteadReflectionServiceMethodsRector\Fixture; -use stdClass; use TYPO3\CMS\Extbase\Reflection\ReflectionService; class MyService @@ -63,17 +62,17 @@ class MyService public function init(): void { - $properties = array_keys($this->reflectionService->getClassSchema(stdClass::class)->getProperties()); + $properties = array_keys($this->reflectionService->getClassSchema(\stdClass::class)->getProperties()); foreach ($properties as $property) { - $propertyTagsValues = $this->reflectionService->getClassSchema(stdClass::class)->getProperty($property)['tags'] ?? []; + $propertyTagsValues = $this->reflectionService->getClassSchema(\stdClass::class)->getProperty($property)['tags'] ?? []; $tags = $propertyTagsValues; - $tag = $this->reflectionService->getClassSchema(stdClass::class)->getProperty($property)['tags']['tag'] ?? []; + $tag = $this->reflectionService->getClassSchema(\stdClass::class)->getProperty($property)['tags']['tag'] ?? []; } } public function fooBarBaz() { - $propertyTagsValues = $this->reflectionService->getClassSchema(stdClass::class)->getProperty('property')['tags'] ?? []; + $propertyTagsValues = $this->reflectionService->getClassSchema(\stdClass::class)->getProperty('property')['tags'] ?? []; if ( ! empty($propertyTagsValues)) { // Do something here } @@ -81,17 +80,17 @@ class MyService public function getProperty($property) { - $propertyTagsValues = $this->reflectionService->getClassSchema(stdClass::class)->getProperty($property)['tags'] ?? []; + $propertyTagsValues = $this->reflectionService->getClassSchema(\stdClass::class)->getProperty($property)['tags'] ?? []; return $propertyTagsValues; } public function isPropertyTaggedWith($property) { - $propertyReflectionService = $this->reflectionService->getClassSchema(stdClass::class)->getProperty($property); + $propertyReflectionService = $this->reflectionService->getClassSchema(\stdClass::class)->getProperty($property); if (empty($propertyReflectionService) ? false : isset($propertyReflectionService['tags']['tag'])) { // Do something here } - $propertyReflectionService = $this->reflectionService->getClassSchema(stdClass::class)->getProperty($property); + $propertyReflectionService = $this->reflectionService->getClassSchema(\stdClass::class)->getProperty($property); return empty($propertyReflectionService) ? false : isset($propertyReflectionService['tags']['tag']); } }