EscolaLMS/Consultations

View on GitHub
database/migrations/2022_03_25_123812_remove_unique_index_in_consultaion_user_table.php

Summary

Maintainability
A
0 mins
Test Coverage

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

        Schema::table('consultation_user', function (Blueprint $table) {
            $table->unique(['user_id', 'consultation_id'], 'consultation_user_unique');
        });

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 'DB' in method 'up'.
Open

            DB::statement('ALTER TABLE `consultation_user` DROP INDEX `consultation_user_unique`, ADD INDEX (user_id, consultation_id)');

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 '\Illuminate\Support\Facades\Schema' in method 'up'.
Open

            Schema::table('consultation_user', function (Blueprint $table) {
                $table->dropUnique('consultation_user_unique');
            });

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 'DB' in method 'up'.
Open

        if (DB::connection() instanceof MySqlConnection) {

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 up uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            Schema::table('consultation_user', function (Blueprint $table) {
                $table->dropUnique('consultation_user_unique');
            });
        }

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

Parameter $table has undeclared type \Illuminate\Database\Schema\Blueprint
Open

            Schema::table('consultation_user', function (Blueprint $table) {

Checking instanceof against undeclared class \Illuminate\Database\MySqlConnection
Open

        if (DB::connection() instanceof MySqlConnection) {

Class extends undeclared class \Illuminate\Database\Migrations\Migration
Open

class RemoveUniqueIndexInConsultaionUserTable extends Migration

Call to method statement from undeclared class \DB
Open

            DB::statement('ALTER TABLE `consultation_user` DROP INDEX `consultation_user_unique`, ADD INDEX (user_id, consultation_id)');

Call to method table from undeclared class \Illuminate\Support\Facades\Schema
Open

        Schema::table('consultation_user', function (Blueprint $table) {

Call to method table from undeclared class \Illuminate\Support\Facades\Schema
Open

            Schema::table('consultation_user', function (Blueprint $table) {

Call to method connection from undeclared class \DB
Open

        if (DB::connection() instanceof MySqlConnection) {

Call to method dropUnique from undeclared class \Illuminate\Database\Schema\Blueprint
Open

                $table->dropUnique('consultation_user_unique');

Parameter $table has undeclared type \Illuminate\Database\Schema\Blueprint
Open

        Schema::table('consultation_user', function (Blueprint $table) {

Call to method unique from undeclared class \Illuminate\Database\Schema\Blueprint
Open

            $table->unique(['user_id', 'consultation_id'], 'consultation_user_unique');

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

    public function up()
    {
        if (DB::connection() instanceof MySqlConnection) {
            DB::statement('ALTER TABLE `consultation_user` DROP INDEX `consultation_user_unique`, ADD INDEX (user_id, consultation_id)');
        } else {

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 RemoveUniqueIndexInConsultaionUserTable extends Migration

Line exceeds 120 characters; contains 137 characters
Open

            DB::statement('ALTER TABLE `consultation_user` DROP INDEX `consultation_user_unique`, ADD INDEX (user_id, consultation_id)');

There are no issues that match your filters.

Category
Status