EscolaLMS/Consultations

View on GitHub
database/migrations/2022_03_23_140827_change_columns_in_consultationuser_table.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

        Schema::dropIfExists('consultation_terms');

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 'down'.
Open

            if (Schema::hasTable('orders')) {

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->dateTime('executed_at')->nullable();
            $table->string('executed_status')->nullable();
        });

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 'down'.
Open

        Schema::create('consultation_terms', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('user_id')->unsigned();
            $table->bigInteger('order_item_id')->unsigned();
            $table->dateTime('executed_at')->nullable();

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 'down'.
Open

        Schema::table('consultation_user', function (Blueprint $table) {
            $table->dropColumn(['executed_at', 'executed_status']);
        });

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

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

            $table->string('executed_status')->nullable();

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 "executed_at" 3 times.
Open

            $table->dateTime('executed_at')->nullable();

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.

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

            $table->bigInteger('user_id')->unsigned();

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

        Schema::create('consultation_terms', function (Blueprint $table) {

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

                $table->foreign('order_item_id')->on('order_items')->references('id')->cascadeOnDelete();

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

            $table->timestamps();

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 dateTime from undeclared class \Illuminate\Database\Schema\Blueprint
Open

            $table->dateTime('executed_at')->nullable();

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

        Schema::create('consultation_terms', function (Blueprint $table) {

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

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

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

        Schema::dropIfExists('consultation_terms');

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

            $table->string('executed_status')->nullable();

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

            if (Schema::hasTable('orders')) {

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

            $table->foreign('user_id')->on('users')->references('id');

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

            $table->bigInteger('order_item_id')->unsigned();

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

            $table->string('executed_status')->nullable();

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

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

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

            $table->id();

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

            $table->dateTime('executed_at')->nullable();

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

class ChangeColumnsInConsultationuserTable extends Migration

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

            $table->dropColumn(['executed_at', 'executed_status']);

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        Schema::create('consultation_terms', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('user_id')->unsigned();
            $table->bigInteger('order_item_id')->unsigned();
            $table->dateTime('executed_at')->nullable();
database/migrations/2022_02_10_075849_add_pivot_table_for_order_items_and_user.php on lines 20..31

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 141.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

    public function up()
    {
        Schema::table('consultation_user', function (Blueprint $table) {
            $table->dateTime('executed_at')->nullable();
            $table->string('executed_status')->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 ChangeColumnsInConsultationuserTable extends Migration

There are no issues that match your filters.

Category
Status