Showing 89 of 122 total issues

Line exceeds 160 characters; contains 207 characters
Open

    const TAG_SERVICE_IDENTIFIER_WRONG_FORMAT = 'The given identifier for the property `%s` is not valid, given value is `%s`, a suggestion would be `%s`. The format must respect the following rules: "%s".';

Line exceeds 160 characters; contains 201 characters
Open

    const BACKUP_CACHE_WARNING_MESSAGE = 'The cache instance for NotiZ core could not be loaded. If this message is written often in your logs, your TYPO3 instance may suffer from performance issues.';

Line exceeds 160 characters; contains 262 characters
Open

    const PROPERTY_ENTRY_VALUE_NOT_ACCESSIBLE = 'The value for the property `%s` (type: `%s`) cannot be modified, because the entry has been frozen. Modifying the value can only occur while the event is being dispatched, see method `%s::fillPropertyEntries()`.';

Line exceeds 160 characters; contains 171 characters
Open

        $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'][] = EventDefinitionRegisterer::class . '->processData';

This branch's code block is the same as the block for the branch on line 33.
Open

        } elseif (class_exists($instanceName)
            && in_array($instanceName, class_parents($className))
        ) {
            return true;
        }
Severity: Major
Found in Classes/Service/ObjectService.php by sonar-php

Having two cases in a switch statement or two branches in an if chain with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then in an if chain they should be combined, or for a switch, one should fall through to the other.

Noncompliant Code Example

switch ($i) {
  case 1:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  case 3:  // Noncompliant; duplicates case 1's implementation
    doSomething();
    break;
  default:
    doTheRest();
}

if ($a >= 0 && $a < 10) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else if ($a >= 20 && $a < 50) {
  doTheThing();  // Noncompliant; duplicates first condition
}
else {
  doTheRest();
}

if ($b == 0) {
  doOneMoreThing();
}
else {
  doOneMoreThing(); // Noncompliant; duplicates then-branch
}

var b = a ? 12 > 4 : 4;  // Noncompliant; always results in the same value

Compliant Solution

switch ($i) {
  case 1:
  case 3:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  default:
    doTheRest();
}

if (($a >= 0 && $a < 10) || ($a >= 20 && $a < 50)) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else {
  doTheRest();
}

doOneMoreThing();

b = 4;

or

switch ($i) {
  case 1:
    doSomething();
    break;
  case 2:
    doSomethingDifferent();
    break;
  case 3:
    doThirdThing();
    break;
  default:
    doTheRest();
}

if ($a >= 0 && $a < 10) {
  doTheThing();
else if ($a >= 10 && $a < 20) {
  doTheOtherThing();
}
else if ($a >= 20 && $a < 50) {
  doTheThirdThing();
}
else {
  doTheRest();
}

if ($b == 0) {
  doOneMoreThing();
}
else {
  doTheRest();
}

int b = a ? 12 > 4 : 8;

Exceptions

Blocks in an if chain that contain a single line of code are ignored, as are blocks in a switch statement that contain a single line of code with or without a following break.

This function "buildTcaArray" has 176 lines, which is greater than the 150 lines authorized. Split it into smaller functions.
Open

    protected function buildTcaArray(): array

A function that grows too large tends to aggregate too many responsibilities.

Such functions inevitably become harder to understand and therefore harder to maintain.

Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.

Those smaller functions will not only be easier to understand, but also probably easier to test.

Define and throw a dedicated exception instead of using a generic one.
Open

    throw new \Exception('Access denied.');
Severity: Major
Found in ext_tables.php by sonar-php

If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

Noncompliant Code Example

throw new Exception();  // Noncompliant

Compliant Solution

throw new InvalidArgumentException();
// or
throw new UnexpectedValueException();

See

Define and throw a dedicated exception instead of using a generic one.
Open

    throw new \Exception('Access denied.');
Severity: Major
Found in ext_localconf.php by sonar-php

If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

Noncompliant Code Example

throw new Exception();  // Noncompliant

Compliant Solution

throw new InvalidArgumentException();
// or
throw new UnexpectedValueException();

See

This function "buildTcaArray" has 208 lines, which is greater than the 150 lines authorized. Split it into smaller functions.
Open

    protected function buildTcaArray(): array

A function that grows too large tends to aggregate too many responsibilities.

Such functions inevitably become harder to understand and therefore harder to maintain.

Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.

Those smaller functions will not only be easier to understand, but also probably easier to test.

Severity
Category
Status
Source
Language