YetiForceCompany/YetiForcePDF

View on GitHub

Showing 15,735 of 15,735 total issues

Define a constant instead of duplicating this literal "data-code" 3 times.
Open

        if ($childDomElement->hasAttribute('data-code') && $childDomElement->getAttribute('data-code')) {
Severity: Critical
Found in lib/Layout/LineBox.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Add a "case default" clause to this "switch" statement.
Open

        switch (\count($numberValues)) {
Severity: Critical
Found in lib/Style/Normalizer/Normalizer.php by sonar-php

The requirement for a final case default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. Even when the switch covers all current values of an enum, a default case should still be used because there is no guarantee that the enum won't be extended.

Noncompliant Code Example

switch ($param) {  //missing default clause
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
}

switch ($param) {
  default: // default clause should be the last one
    error();
    break;
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
}

Compliant Solution

switch ($param) {
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
  default:
    error();
    break;
}

See

  • MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
  • MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
  • MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
  • MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
  • MISRA C:2012, 16.1 - All switch statements shall be well-formed
  • MISRA C:2012, 16.4 - Every switch statement shall have a default label
  • MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
  • MITRE, CWE-478 - Missing Default Case in Switch Statement
  • CERT, MSC01-C. - Strive for logical completeness
  • CERT, MSC01-CPP. - Strive for logical completeness

Define a constant instead of duplicating this literal "padding-left" 12 times.
Open

        'padding-left' => '0',
Severity: Critical
Found in lib/Style/Style.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "line-through" 3 times.
Open

            'text-decoration' => 'line-through',
Severity: Critical
Found in lib/Style/Style.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "collapse" 4 times.
Open

                if ('collapse' !== $tableWrapperStyle->getRules('border-collapse')) {
Severity: Critical
Found in lib/Style/Style.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "UTF-16" 6 times.
Open

            $this->addValue('Title', $this->document->filterText($this->title, 'UTF-16', true, true));
Severity: Critical
Found in lib/Objects/Meta.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Rename "$parentBox" which has the same name as the field declared at line 28.
Open

            if ($parentBox = $this->box->getParent()) {
Severity: Major
Found in lib/Html/Element.php by sonar-php

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

Define a constant instead of duplicating this literal "inline" 3 times.
Open

            if ('inline' === $box->getStyle()->getRules('display')) {

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Rename "$currentLineBox" which has the same name as the field declared at line 31.
Open

            $currentLineBox = $this->getCurrentLineBox();
Severity: Major
Found in lib/Layout/BlockBox.php by sonar-php

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

Rename "$currentLineBox" which has the same name as the field declared at line 31.
Open

            $currentLineBox = $this->getCurrentLineBox();
Severity: Major
Found in lib/Layout/BlockBox.php by sonar-php

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

Rename "$minWidth" which has the same name as the field declared at line 40.
Open

        $minWidth = $this->minWidths[$maxPercentRatioIndex];
Severity: Major
Found in lib/Layout/TableBox.php by sonar-php

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

Rename "$rows" which has the same name as the field declared at line 80.
Open

            $rows = $rowGroup->getChildren();
Severity: Major
Found in lib/Layout/TableBox.php by sonar-php

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

Define a constant instead of duplicating this literal "data-size" 3 times.
Open

        if ($childDomElement->hasAttribute('data-size') && $childDomElement->getAttribute('data-size')) {
Severity: Critical
Found in lib/Layout/LineBox.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Add a "case default" clause to this "switch" statement.
Open

        switch ($whiteSpace) {
Severity: Critical
Found in lib/Layout/InlineBox.php by sonar-php

The requirement for a final case default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. Even when the switch covers all current values of an enum, a default case should still be used because there is no guarantee that the enum won't be extended.

Noncompliant Code Example

switch ($param) {  //missing default clause
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
}

switch ($param) {
  default: // default clause should be the last one
    error();
    break;
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
}

Compliant Solution

switch ($param) {
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
  default:
    error();
    break;
}

See

  • MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
  • MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
  • MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
  • MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
  • MISRA C:2012, 16.1 - All switch statements shall be well-formed
  • MISRA C:2012, 16.4 - Every switch statement shall have a default label
  • MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
  • MITRE, CWE-478 - Missing Default Case in Switch Statement
  • CERT, MSC01-C. - Strive for logical completeness
  • CERT, MSC01-CPP. - Strive for logical completeness

Define a constant instead of duplicating this literal "white-space" 3 times.
Open

        'white-space',
Severity: Critical
Found in lib/Style/Style.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "middle" 3 times.
Open

            'vertical-align' => 'middle',
Severity: Critical
Found in lib/Style/Style.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "inherit" 9 times.
Open

            'border-color' => 'inherit',
Severity: Critical
Found in lib/Style/Style.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Rename "$element" which has the same name as the field declared at line 45.
Open

        $element = $this->getElement();
Severity: Major
Found in lib/Style/Style.php by sonar-php

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

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

                throw new \ErrorException('Invalid fonts json structure.');
Severity: Major
Found in lib/Objects/Font.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 a constant instead of duplicating this literal "Invalid fonts json structure." 3 times.
Open

            throw new \ErrorException('Invalid fonts json structure.');
Severity: Critical
Found in lib/Objects/Font.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Severity
Category
Status
Source
Language