aaronbullard/php-schema

View on GitHub

Showing 35 of 43 total issues

Expected 1 newline at end of file; 0 found
Open

}
Severity: Minor
Found in demo/Entity/Address.php by phpcodesniffer

Expected 1 space after IF keyword; 0 found
Open

        if($this->isAssociative()){
Severity: Minor
Found in src/Models/Model.php by phpcodesniffer

Expected 1 space after closing parenthesis; found 0
Open

} catch (ValidationException $e){
Severity: Minor
Found in demo/demo.php by phpcodesniffer

Expected 1 newline at end of file; 0 found
Open

 */
Severity: Minor
Found in demo/demo.php by phpcodesniffer

Expected 1 newline at end of file; 0 found
Open

}
Severity: Minor
Found in demo/Entity/Invoice.php by phpcodesniffer

Expected 1 newline at end of file; 0 found
Open

}
Severity: Minor
Found in demo/Entity/LineItem.php by phpcodesniffer

Whitespace found at end of line
Open

     * Array of attributes that must be observed for changes.  These 
Severity: Minor
Found in src/Models/Model.php by phpcodesniffer

Remove the unused function parameter "$schema".
Open

    public static function createDTO($schema, array $args = []): object
Severity: Major
Found in src/Models/Factory.php by sonar-php

Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

Noncompliant Code Example

function doSomething($a, $b) { // "$a" is unused
  return compute($b);
}

Compliant Solution

function doSomething($b) {
  return compute($b);
}

Exceptions

Functions in classes that override a class or implement interfaces are ignored.

class C extends B {

  function doSomething($a, $b) {     // no issue reported on $b
    compute($a);
  }

}

See

  • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
  • MISRA C:2012, 2.7 - There should be no unused parameters in functions
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CERT, MSC12-CPP. - Detect and remove code that has no effect

Remove this commented out code.
Open

// use PhpSchema\Models\SchemaModel;
Severity: Major
Found in src/Models/Factory.php by sonar-php

Programmers should not comment out code as it bloats programs and reduces readability.

Unused code should be deleted and can be retrieved from source control history if required.

See

  • MISRA C:2004, 2.4 - Sections of code should not be "commented out".
  • MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
  • MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
  • MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"

Move arguments "$street_2" after arguments without default value
Open

    public function __construct(string $street_1, string $street_2 = null, string $city, string $state, string $zipcode)
Severity: Major
Found in demo/Entity/Address.php by sonar-php

The ability to define default values for method arguments can make a method easier to use. Default argument values allow callers to specify as many or as few arguments as they want while getting the same functionality and minimizing boilerplate, wrapper code.

But all method arguments with default values should be declared after the method arguments without default values. Otherwise, it makes it impossible for callers to take advantage of defaults; they must re-specify the defaulted values in order to "get to" the non-default arguments.

Noncompliant Code Example

function makeyogurt($type = "acidophilus", $flavor){...}  // Noncompliant

makeyogurt("raspberry")}}  // Runtime error: Missing argument 2 in call to makeyogurt()

Compliant Solution

function makeyogurt($flavor, $type = "acidophilus", ){...}

makeyogurt("raspberry")}} // Works as expected

Remove the unused function parameter "$args".
Open

    public static function createDTO($schema, array $args = []): object
Severity: Major
Found in src/Models/Factory.php by sonar-php

Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

Noncompliant Code Example

function doSomething($a, $b) { // "$a" is unused
  return compute($b);
}

Compliant Solution

function doSomething($b) {
  return compute($b);
}

Exceptions

Functions in classes that override a class or implement interfaces are ignored.

class C extends B {

  function doSomething($a, $b) {     // no issue reported on $b
    compute($a);
  }

}

See

  • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
  • MISRA C:2012, 2.7 - There should be no unused parameters in functions
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CERT, MSC12-CPP. - Detect and remove code that has no effect

Remove the unused function parameter "$method".
Open

    protected function isGetterMethod(string $method): bool
Severity: Major
Found in src/Traits/MethodAccess.php by sonar-php

Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

Noncompliant Code Example

function doSomething($a, $b) { // "$a" is unused
  return compute($b);
}

Compliant Solution

function doSomething($b) {
  return compute($b);
}

Exceptions

Functions in classes that override a class or implement interfaces are ignored.

class C extends B {

  function doSomething($a, $b) {     // no issue reported on $b
    compute($a);
  }

}

See

  • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
  • MISRA C:2012, 2.7 - There should be no unused parameters in functions
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CERT, MSC12-CPP. - Detect and remove code that has no effect

Add curly braces around the nested statement(s).
Open

        if (array() === $this->container) return false;
Severity: Critical
Found in src/Models/Model.php by sonar-php

While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

Noncompliant Code Example

if (condition)  // Noncompliant
  executeSomething();

Compliant Solution

if (condition) {
  executeSomething();
}

See

  • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
  • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
  • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
  • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
  • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
  • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
  • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

Remove the unused function parameter "$method".
Open

    protected function isSetterMethod(string $method): bool
Severity: Major
Found in src/Traits/MethodAccess.php by sonar-php

Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

Noncompliant Code Example

function doSomething($a, $b) { // "$a" is unused
  return compute($b);
}

Compliant Solution

function doSomething($b) {
  return compute($b);
}

Exceptions

Functions in classes that override a class or implement interfaces are ignored.

class C extends B {

  function doSomething($a, $b) {     // no issue reported on $b
    compute($a);
  }

}

See

  • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
  • MISRA C:2012, 2.7 - There should be no unused parameters in functions
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CERT, MSC12-CPP. - Detect and remove code that has no effect

Move arguments "$input" after arguments without default value
Open

    public function __construct($input = [], Observable $subscriber)
Severity: Major
Found in src/Observers/Observer.php by sonar-php

The ability to define default values for method arguments can make a method easier to use. Default argument values allow callers to specify as many or as few arguments as they want while getting the same functionality and minimizing boilerplate, wrapper code.

But all method arguments with default values should be declared after the method arguments without default values. Otherwise, it makes it impossible for callers to take advantage of defaults; they must re-specify the defaulted values in order to "get to" the non-default arguments.

Noncompliant Code Example

function makeyogurt($type = "acidophilus", $flavor){...}  // Noncompliant

makeyogurt("raspberry")}}  // Runtime error: Missing argument 2 in call to makeyogurt()

Compliant Solution

function makeyogurt($flavor, $type = "acidophilus", ){...}

makeyogurt("raspberry")}} // Works as expected
Severity
Category
Status
Source
Language