aaronbullard/php-schema

View on GitHub
src/Models/Model.php

Summary

Maintainability
A
0 mins
Test Coverage

The method __construct has a boolean flag argument $observe, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function __construct($input = [], $observe = TRUE)
Severity: Minor
Found in src/Models/Model.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

Avoid using static access to class '\PhpSchema\ValidationException' in method 'startObserving'.
Invalid

            throw ValidationException::ARRAYABLE();
Severity: Minor
Found in src/Models/Model.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\PhpSchema\Observers\ObserverFactory' in method 'startObserving'.
Invalid

        if (ObserverFactory::isObservable($value)) {
Severity: Minor
Found in src/Models/Model.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\PhpSchema\Observers\ObserverFactory' in method 'startObserving'.
Invalid

            $value = ObserverFactory::create($value, $this);
Severity: Minor
Found in src/Models/Model.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

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

TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
Open

    public function __construct($input = [], $observe = TRUE)
Severity: Minor
Found in src/Models/Model.php by phpcodesniffer

Inline control structures are not allowed
Open

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

Expected 1 space after closing parenthesis; found 0
Open

        if($isAssoc === false){
Severity: Minor
Found in src/Models/Model.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 IF keyword; 0 found
Open

        if($isAssoc === false){
Severity: Minor
Found in src/Models/Model.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

Expected 1 space after closing parenthesis; found 0
Open

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

There are no issues that match your filters.

Category
Status