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

[TASK] Simplify code generation command #3462

Merged
merged 1 commit into from
Oct 12, 2023
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
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($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.