Skip to content

Commit

Permalink
[BUGFIX] Add missing negate operator
Browse files Browse the repository at this point in the history
Resolves: #4256
  • Loading branch information
helsner committed May 25, 2024
1 parent 7dc2ce7 commit a39ddd6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 54 deletions.
18 changes: 16 additions & 2 deletions rules/TYPO311/v0/SubstituteConstantsModeAndRequestTypeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
Expand Down Expand Up @@ -90,11 +91,24 @@ public function refactor(Node $node): ?Node
return null;
}

$operator = $node->getOperatorSigil();

if ($typeValue === 'BE') {
return $this->createIsBackendCall();
$beCall = $this->createIsBackendCall();

if ($operator !== '') {
return new BooleanNot($beCall);
}

return $beCall;
}

$feCall = $this->createIsFrontendCall();
if ($operator !== '') {
return new BooleanNot($feCall);
}

return $this->createIsFrontendCall();
return $feCall;
}

public function getRuleDefinition(): RuleDefinition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,13 @@

namespace Ssch\TYPO3Rector\Tests\Rector\v11\v0\SubstituteConstantsModeAndRequestTypeRector\Fixture;

defined('TYPO3_MODE') or die();
// defined('TYPO3_MODE') or die();

class MyController
{
public function fooAction()
{
if (TYPO3_REQUESTTYPE_BE) {
// Do something
}

if (TYPO3_REQUESTTYPE_FE) {
// Do something
}

if (TYPO3_MODE === 'BE') {
// Do something
}

if (TYPO3_MODE === 'FE') {
// Do something
}

if ('BE' === TYPO3_MODE) {
// Do something
}

if ('FOO' === TYPO3_MODE) {
// Do something
}

if ('FE' === TYPO3_MODE) {
if (TYPO3_MODE !== 'FE') {
// Do something
}
}
Expand All @@ -45,37 +21,13 @@ class MyController
namespace Ssch\TYPO3Rector\Tests\Rector\v11\v0\SubstituteConstantsModeAndRequestTypeRector\Fixture;

use TYPO3\CMS\Core\Http\ApplicationType;
defined('TYPO3') or die();
// defined('TYPO3') or die();

class MyController
{
public function fooAction()
{
if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
// Do something
}

if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
// Do something
}

if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
// Do something
}

if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
// Do something
}

if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
// Do something
}

if ('FOO' === TYPO3_MODE) {
// Do something
}

if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
if (!ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
// Do something
}
}
Expand Down

0 comments on commit a39ddd6

Please sign in to comment.