Skip to content

Commit

Permalink
[TASK] Simplify code generation command
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschaufi committed Oct 10, 2023
1 parent 7aeff68 commit e7388ff
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 117 deletions.
34 changes: 16 additions & 18 deletions utils/generator/src/Command/Typo3GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
use Ssch\TYPO3Rector\Generator\FileSystem\ConfigFilesystem;
use Ssch\TYPO3Rector\Generator\Finder\TemplateFinder;
use Ssch\TYPO3Rector\Generator\Generator\FileGenerator;
use Ssch\TYPO3Rector\Generator\ValueObject\Description;
use Ssch\TYPO3Rector\Generator\ValueObject\Name;
use Ssch\TYPO3Rector\Generator\ValueObject\Typo3RectorRecipe;
use Ssch\TYPO3Rector\Generator\ValueObject\Typo3Version;
use Ssch\TYPO3Rector\Generator\ValueObject\Url;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -148,15 +145,16 @@ private function askForChangelogUrl(): Question
$whatIsTheUrlToChangelog = new Question(
'Url to changelog (i.e. https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/...): '
);
$whatIsTheUrlToChangelog->setNormalizer(static fn ($url) => Url::createFromString((string) $url));
$whatIsTheUrlToChangelog->setMaxAttempts(3);
$whatIsTheUrlToChangelog->setValidator(
static function (Url $url) {
if (! filter_var($url->getUrl(), FILTER_VALIDATE_URL)) {
static function (?string $url) {
Assert::notNull($url);

if (! filter_var($url, FILTER_VALIDATE_URL)) {
throw new RuntimeException('Please enter a valid Url');
}

Assert::startsWith($url->getUrl(), 'https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/');
Assert::startsWith((string) $url, 'https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/');

return $url;
}
Expand All @@ -168,16 +166,15 @@ static function (Url $url) {
private function askForName(): Question
{
$giveMeYourName = new Question('Name (i.e MigrateRequiredFlag): ');
$giveMeYourName->setNormalizer(static fn ($name) => Name::createFromString((string) $name));
$giveMeYourName->setNormalizer(static fn ($name) => preg_replace('/Rector$/', '', ucfirst((string) $name)));
$giveMeYourName->setMaxAttempts(3);
$giveMeYourName->setValidator(static function (Name $name) {
Assert::notEndsWith($name->getName(), 'Rector');
Assert::minLength($name->getName(), 5);
Assert::maxLength($name->getName(), 60);
Assert::notContains($name->getName(), ' ', 'The name must not contain spaces');
$giveMeYourName->setValidator(static function (string $name) {
Assert::minLength($name, 5);
Assert::maxLength($name, 60);
Assert::notContains($name, ' ', 'The name must not contain spaces');
// Pattern from: https://www.php.net/manual/en/language.oop5.basic.php
Assert::regex(
$name->getName(),
$name,
'/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/',
'The name must be a valid PHP class name. A valid class name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.'
);
Expand All @@ -191,11 +188,11 @@ private function askForName(): Question
private function askForDescription(): Question
{
$description = new Question('Description (i.e. Migrate required flag): ');
$description->setNormalizer(static fn ($name) => Description::createFromString((string) $name));
$description->setMaxAttempts(3);
$description->setValidator(static function (Description $description) {
Assert::minLength($description->getDescription(), 5);
Assert::maxLength($description->getDescription(), 120);
$description->setValidator(static function (?string $description) {
Assert::notNull($description, 'Please enter a description');
Assert::minLength($description, 5);
Assert::maxLength($description, 120);

return $description;
});
Expand All @@ -211,6 +208,7 @@ private function askForType(): Question
'flexform',
'typoscript',
], 0);
$question->setMaxAttempts(3);
$question->setErrorMessage('Type %s is invalid.');

return $question;
Expand Down
28 changes: 0 additions & 28 deletions utils/generator/src/ValueObject/Description.php

This file was deleted.

33 changes: 0 additions & 33 deletions utils/generator/src/ValueObject/Name.php

This file was deleted.

20 changes: 10 additions & 10 deletions utils/generator/src/ValueObject/Typo3RectorRecipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ final class Typo3RectorRecipe
/**
* @readonly
*/
private Url $url;
private string $url;

/**
* @readonly
*/
private Name $name;
private string $name;

/**
* @readonly
*/
private Description $description;
private string $description;

/**
* @readonly
Expand All @@ -33,9 +33,9 @@ final class Typo3RectorRecipe

public function __construct(
Typo3Version $typo3Version,
Url $url,
Name $name,
Description $description,
string $url,
string $name,
string $description,
string $type
) {
$this->typo3Version = $typo3Version;
Expand All @@ -47,7 +47,7 @@ public function __construct(

public function getChangelogUrl(): string
{
return $this->url->getUrl();
return $this->url;
}

public function getMajorVersion(): string
Expand All @@ -62,17 +62,17 @@ public function getMinorVersion(): string

public function getDescription(): string
{
return $this->description->getDescription();
return $this->description;
}

public function getRectorName(): string
{
return $this->name->getRectorName();
return $this->name . 'Rector';
}

public function getTestDirectory(): string
{
return $this->name->getName() . 'Rector';
return $this->name . 'Rector';
}

public function getSet(): string
Expand Down
28 changes: 0 additions & 28 deletions utils/generator/src/ValueObject/Url.php

This file was deleted.

0 comments on commit e7388ff

Please sign in to comment.