poisa/Settings

View on GitHub

Showing 88 of 88 total issues

Avoid using short method names like CreateSettingsTable::up(). The configured minimum method name length is 3.
Open

    public function up()
    {
        Schema::create(config('settings.table_name'), function (Blueprint $table) {
            $table->string('key')->primary();
            $table->longtext('value')->nullable();

ShortMethodName

Since: 0.2

Detects when very short method names are used.

Example

class ShortMethod {
    public function a( $index ) { // Violation
    }
}

Source https://phpmd.org/rules/naming.html#shortmethodname

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class CreateSettingsTable extends Migration

Function createFromTypeAlias has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public static function createFromTypeAlias(string $typeAlias): Serializer
    {
        foreach (config('settings.serializers') as $serializable) {
            if (!class_exists($serializable)) {
                throw new ClassDoesNotExist($serializable);
Severity: Minor
Found in src/Serializers/SerializerFactory.php - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function getSerializableClass has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public static function getSerializableClass(string $dataType): string
    {
        foreach (config('settings.serializers') as $serializable) {
            if (!class_exists($serializable)) {
                throw new ClassDoesNotExist($serializable);
Severity: Minor
Found in src/Serializers/SerializerFactory.php - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function getKey has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getKey(string $key, $connection = null)
    {
        if (is_null($connection)) {
            $connection = $this->getDefaultConnection();
        }
Severity: Minor
Found in src/Settings.php - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid using static access to class '\Settings' in method 'handle'.
Open

        $value = Settings::getKey($this->argument('key'), $database);
Severity: Minor
Found in src/Commands/GetCommand.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 '\Poisa\Settings\Serializers\SerializerFactory' in method 'createKey'.
Open

        $serializable = SerializerFactory::createFromValue($value);
Severity: Minor
Found in src/Settings.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

The method createKey uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $model->value = $serializable->serialize($value);
        }
Severity: Minor
Found in src/Settings.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

The method updateKey uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $data->value = $serializable->serialize($value);
        }
Severity: Minor
Found in src/Settings.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

Avoid using static access to class '\Poisa\Settings\Serializers\SerializerFactory' in method 'getKey'.
Open

        $serializable = SerializerFactory::createFromTypeAlias($data->type_alias);
Severity: Minor
Found in src/Settings.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 '\Settings' in method 'handle'.
Open

        Settings::setKey($this->argument('key'), $this->argument('value'), $database);
Severity: Minor
Found in src/Commands/SetCommand.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 '\Poisa\Settings\Serializers\SerializerFactory' in method 'updateKey'.
Open

        $serializable = SerializerFactory::createFromValue($value);
Severity: Minor
Found in src/Settings.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

The method getKey uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $value = $serializable->unserialize($data->value);
        }
Severity: Minor
Found in src/Settings.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

Avoid using static access to class '\Illuminate\Support\Facades\Schema' in method 'up'.
Open

        Schema::create(config('settings.table_name'), function (Blueprint $table) {
            $table->string('key')->primary();
            $table->longtext('value')->nullable();
            $table->string('type_alias');
            $table->timestamps();

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

The method handle uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $database = $this->option('database');
        }
Severity: Minor
Found in src/Commands/GetCommand.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

Avoid using static access to class '\Illuminate\Support\Str' in method 'getTypeAlias'.
Open

        $scalarType = Str::after($className, 'Scalar');
Severity: Minor
Found in src/Serializers/BaseScalarType.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 unused parameters such as '$app'.
Open

        $this->app->singleton(Settings::class, function ($app) {
Severity: Minor
Found in src/SettingsServiceProvider.php by phpmd

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

The method handle uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $database = $this->option('database');
        }
Severity: Minor
Found in src/Commands/SetCommand.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

Avoid using static access to class '\Illuminate\Support\Facades\Schema' in method 'down'.
Open

        Schema::dropIfExists(config('settings.table_name'));

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

Opening brace should be on a new line
Open

    public function getTypeAlias(): string {
Severity
Category
Status
Source
Language