Skip to content

Commit

Permalink
TASK: Add some sensitive defaults for the config (#3207)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon authored Nov 8, 2022
1 parent eb63cff commit c8ea130
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 42 deletions.
7 changes: 7 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions config/config_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
13 changes: 0 additions & 13 deletions templates/rector.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../../../../../config/config_test.php');
$rectorConfig->disableParallel();
$rectorConfig->rule(IconsRector::class);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ 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;

public function testFooBar()
{
try {

} catch (\TYPO3\TestingFramework\Core\Exception $e) {
} catch (Exception $e) {

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -63,35 +62,35 @@ 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
}
}

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']);
}
}
Expand Down

0 comments on commit c8ea130

Please sign in to comment.