Skip to content

Commit

Permalink
TASK: Fix condition matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Aug 21, 2023
1 parent 719fdee commit 4d11f32
Show file tree
Hide file tree
Showing 140 changed files with 373 additions and 399 deletions.
8 changes: 4 additions & 4 deletions src/FileProcessor/FlexForms/FlexFormsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function process(File $file, Configuration $configuration): array
}

$xml = $domDocument->saveXML($domDocument->documentElement, LIBXML_NOEMPTYTAG);
if ($xml === false) {
if (false === $xml) {
throw new UnexpectedValueException('Could not convert to xml');
}

Expand All @@ -89,7 +89,7 @@ public function process(File $file, Configuration $configuration): array
public function supports(File $file, Configuration $configuration): bool
{
// avoid empty run
if ($this->flexFormRectors === []) {
if ([] === $this->flexFormRectors) {
return false;
}

Expand All @@ -107,11 +107,11 @@ public function supports(File $file, Configuration $configuration): bool
return false;
}

if ($xml === false) {
if (false === $xml) {
return false;
}

return $xml->getName() === 'T3DataStructure';
return 'T3DataStructure' === $xml->getName();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function transform(DOMDocument $domDocument): bool
continue;
}

if ($type->textContent !== 'select') {
if ('select' !== $type->textContent) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/FileProcessor/Fluid/FluidFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(array $fluidRectors, FileDiffFactory $fileDiffFactor

public function supports(File $file, Configuration $configuration): bool
{
if ($this->fluidRectors === []) {
if ([] === $this->fluidRectors) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ private function shouldSkip(File $file): bool
return true;
}

if ($smartFileInfo->getBasename() === 'constants.txt') {
if ('constants.txt' === $smartFileInfo->getBasename()) {
return false;
}

return $smartFileInfo->getBasename() !== 'setup.txt';
return 'setup.txt' !== $smartFileInfo->getBasename();
}

private function shouldSkipInTestMode(SmartFileInfo $smartFileInfo): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ private function shouldSkip(File $file): bool
return true;
}

if ($smartFileInfo->getBasename() === 'ext_typoscript_setup.txt') {
if ('ext_typoscript_setup.txt' === $smartFileInfo->getBasename()) {
return false;
}

if ($smartFileInfo->getBasename() === 'ext_typoscript_constants.txt') {
if ('ext_typoscript_constants.txt' === $smartFileInfo->getBasename()) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/FileProcessor/Resources/Icons/IconsFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ private function shouldSkip(string $filenameWithoutExtension): bool
return false;
}

return $filenameWithoutExtension !== self::EXT_ICON_NAME;
return self::EXT_ICON_NAME !== $filenameWithoutExtension;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function change(string $condition): ?string

$value = (int) $matches['value'];

if ($value === 1) {
if (1 === $value) {
return 'backend.user.isAdmin';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public function shouldApply(string $condition): bool
return false;
}

return preg_match('#^' . self::TYPE . self::ZERO_ONE_OR_MORE_WHITESPACES . '=[^=]#', $condition) === 1;
return 1 === preg_match('#^' . self::TYPE . self::ZERO_ONE_OR_MORE_WHITESPACES . '=[^=]#', $condition);
}

private function isRegularExpression(string $regularExpression): bool
{
return @preg_match($regularExpression, '') !== false;
return false !== @preg_match($regularExpression, '');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public function change(string $condition): ?string
$matches
);

// Nothing we can do here, might be something like TYPO3_LOADED_EXT
if (! isset($matches['type'], $matches['property'], $matches['operator'], $matches['value'])) {
$newConditions[] = $condition;
continue;
}

$type = trim($matches['type']);
$property = trim($matches['property']);
$operator = trim($matches['operator']);
Expand Down Expand Up @@ -84,7 +90,7 @@ private function refactorGetPost(string $property, string $operator, string $val
$value = sprintf("'%s'", $value);
}

if (count($parameters) === 1) {
if (1 === count($parameters)) {
return sprintf(
'request.getQueryParams()[\'%1$s\'] %2$s %3$s',
$parameters[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function change(string $condition): ?string
foreach ($keys as $key) {
[, , $operator] = explode('.', $key);

if ($operator === '=' && is_countable($conditions[$key]) && count($conditions[$key]) > 1) {
if ('=' === $operator && is_countable($conditions[$key]) && count($conditions[$key]) > 1) {
$values = [];
$condition = '';
foreach ($conditions[$key] as $value) {
Expand Down Expand Up @@ -122,15 +122,15 @@ public function shouldApply(string $condition): bool

private function refactorGetPost(string $property, string $operator, string $value): string
{
if ($property === 'L') {
if ('L' === $property) {
return sprintf('siteLanguage("languageId") %s "%s"', self::OPERATOR_MAPPING[$operator], $value);
}

$normalizedValue = $this->normalizeValue($value);

$parameters = $this->explodeParameters($property);

if (count($parameters) === 1) {
if (1 === count($parameters)) {
return sprintf(
'request.getQueryParams()[\'%1$s\'] %2$s %3$s',
$parameters[0],
Expand All @@ -139,7 +139,7 @@ private function refactorGetPost(string $property, string $operator, string $val
);
}

if ($property === '_POST') {
if ('_POST' === $property) {
return sprintf(
'traverse(request.getParsedBody(), \'%1$s\') %2$s %3$s) %2$s %3$s',
implode('/', $parameters),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public function shouldApply(string $condition): bool
return false;
}

return preg_match('#^' . self::TYPE . self::ZERO_ONE_OR_MORE_WHITESPACES . '=[^=]#', $condition) === 1;
return 1 === preg_match('#^' . self::TYPE . self::ZERO_ONE_OR_MORE_WHITESPACES . '=[^=]#', $condition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function change(string $condition): ?string
return $condition;
}

if (! isset($matches[1]) || $matches[1] === '') {
if (! isset($matches[1]) || '' === $matches[1]) {
return 'loginUser("*") == false';
}

Expand All @@ -33,6 +33,6 @@ public function change(string $condition): ?string

public function shouldApply(string $condition): bool
{
return preg_match('#^' . self::TYPE . self::ZERO_ONE_OR_MORE_WHITESPACES . '=#', $condition) === 1;
return 1 === preg_match('#^' . self::TYPE . self::ZERO_ONE_OR_MORE_WHITESPACES . '=#', $condition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public function change(string $condition): ?string

public function shouldApply(string $condition): bool
{
return preg_match('#^' . self::TYPE . self::ZERO_ONE_OR_MORE_WHITESPACES . '\|#', $condition) === 1;
return 1 === preg_match('#^' . self::TYPE . self::ZERO_ONE_OR_MORE_WHITESPACES . '\|#', $condition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function change(string $condition): ?string
$operator = $operatorAndValueMatches['operator'] ?? '';
$value = $operatorAndValueMatches['value'] ?? '';

if ($operator === '') {
if ('' === $operator) {
$operator = '=';
}

Expand All @@ -79,6 +79,6 @@ public function change(string $condition): ?string

public function shouldApply(string $condition): bool
{
return Strings::match($condition, '#' . self::ALLOWED_TIME_CONSTANTS . '#Ui') !== null;
return null !== Strings::match($condition, '#' . self::ALLOWED_TIME_CONSTANTS . '#Ui');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function change(string $condition): ?string
return $condition;
}

if (! isset($matches[1]) || $matches[1] === '') {
if (! isset($matches[1]) || '' === $matches[1]) {
return "usergroup('*') == false";
}

Expand All @@ -33,6 +33,6 @@ public function change(string $condition): ?string

public function shouldApply(string $condition): bool
{
return preg_match('#^' . self::TYPE . self::ZERO_ONE_OR_MORE_WHITESPACES . '=[^=]#', $condition) === 1;
return 1 === preg_match('#^' . self::TYPE . self::ZERO_ONE_OR_MORE_WHITESPACES . '=[^=]#', $condition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function getRuleDefinition(): RuleDefinition

public function convert(): ?AddedFileWithContent
{
if (self::$persistenceArray === []) {
if ([] === self::$persistenceArray) {
return null;
}

Expand Down Expand Up @@ -188,7 +188,7 @@ public function configure(array $configuration): void
{
$filename = $configuration[self::FILENAME] ?? null;

if ($filename !== null) {
if (null !== $filename) {
$this->filename = $filename;
}
}
Expand Down Expand Up @@ -242,11 +242,11 @@ private function extractColumns(array $paths, Assignment $statement): void
return;
}

if (isset($paths[4]) && $paths[4] === 'config') {
if (isset($paths[4]) && 'config' === $paths[4]) {
return;
}

if (isset($paths[5]) && $paths[5] === 'type') {
if (isset($paths[5]) && 'type' === $paths[5]) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function enterNode(Statement $statement): void
return;
}

if ($statement->value->value !== 'TEMPLATE') {
if ('TEMPLATE' !== $statement->value->value) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function enterNode(Statement $statement): void
return;
}

if ($statement->object->absoluteName !== 'config.disableCharsetHeader') {
if ('config.disableCharsetHeader' !== $statement->object->absoluteName) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public function enterNode(Statement $statement): void
return;
}

if ($statement->object->relativeName === 'lib.fluidContent') {
if ('lib.fluidContent' === $statement->object->relativeName) {
$this->hasChanged = true;
$statement->object->relativeName = 'lib.contentElement';

return;
}

if ($statement->object->relativeName === 'fluidContent') {
if ('fluidContent' === $statement->object->relativeName) {
$this->hasChanged = true;
$statement->object->relativeName = 'contentElement';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function enterNode(Statement $statement): void
return;
}

if ($statement->condition !== null) {
if (null !== $statement->condition) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function enterNode(Statement $statement): void

$changedCondition = $conditionMatcher->change($condition);
$applied = true;
if ($changedCondition !== null) {
if (null !== $changedCondition) {
$newConditions[] = $changedCondition;
}
}
Expand All @@ -90,19 +90,19 @@ public function enterNode(Statement $statement): void
$file->addRectorClassWithLine(new RectorWithLineChange($this, $statement->sourceLine));
}

if ($newConditions === []) {
if ([] === $newConditions) {
$statement->condition = '';

return;
}

if (count($newConditions) === 1) {
if (1 === count($newConditions)) {
$statement->condition = sprintf('[%s]', $newConditions[0]);

return;
}

if ($operators === []) {
if ([] === $operators) {
$statement->condition = sprintf('[%s]', implode(' || ', $newConditions));

return;
Expand All @@ -119,7 +119,7 @@ public function enterNode(Statement $statement): void
$newCondition = '';
foreach ($newConditions as $key => $value) {
$operator = $operators[$key];
if ($operator === '') {
if ('' === $operator) {
$newCondition .= $value;
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/FileProcessor/TypoScript/TypoScriptFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function __construct(

public function supports(File $file, Configuration $configuration): bool
{
if ($this->typoScriptRectors === []) {
if ([] === $this->typoScriptRectors) {
return false;
}

Expand Down Expand Up @@ -205,7 +205,7 @@ private function processFile(File $file): void
static fn (AbstractTypoScriptRector $typoScriptRector) => $typoScriptRector->hasChanged()
);

if ($typoscriptRectorsWithChange === []) {
if ([] === $typoscriptRectorsWithChange) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/FileProcessor/Yaml/Form/FormYamlFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function process(File $file, Configuration $configuration): array
public function supports(File $file, Configuration $configuration): bool
{
// Prevent unnecessary processing
if ($this->transformer === []) {
if ([] === $this->transformer) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ private function refactorFinishers(array $finishers, &$yamlToModify): bool
continue;
}

if ($optionKey === 'replyToAddress') {
if ('replyToAddress' === $optionKey) {
$yamlToModify[self::FINISHERS][$finisherKey][self::OPTIONS]['replyToRecipients'][] = $optionValue;
} elseif ($optionKey === 'carbonCopyAddress') {
} elseif ('carbonCopyAddress' === $optionKey) {
$yamlToModify[self::FINISHERS][$finisherKey][self::OPTIONS]['carbonCopyRecipients'][] = $optionValue;
} elseif ($optionKey === 'blindCarbonCopyAddress') {
} elseif ('blindCarbonCopyAddress' === $optionKey) {
$yamlToModify[self::FINISHERS][$finisherKey][self::OPTIONS]['blindCarbonCopyRecipients'][] = $optionValue;
}

Expand Down
Loading

0 comments on commit 4d11f32

Please sign in to comment.