Avoid using static access to class '\Illuminate\Support\Facades\Schema' in method 'down'. Open
Schema::dropIfExists('webinar_authors');
- Read upRead up
- Exclude checks
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('webinars', function (Blueprint $table) {
$table->dropForeign('webinars_author_id_foreign');
$table->dropColumn('author_id');
});
- Read upRead up
- Exclude checks
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::create('webinar_authors', function (Blueprint $table) {
$table->id();
$table->bigInteger('author_id')->unsigned();
$table->bigInteger('webinar_id')->unsigned();
$table->timestamps();
- Read upRead up
- Exclude checks
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('webinars', function (Blueprint $table) {
$table->bigInteger('author_id')->unsigned()->nullable();
$table->foreign('author_id')->references('id')->on('users')->onDelete('SET NULL');
});
- Read upRead up
- Exclude checks
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 "webinars" 3 times. Open
$table->foreign('webinar_id')->references('id')->on('webinars')->cascadeOnDelete();
- Read upRead up
- Exclude checks
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 "author_id" 5 times. Open
$table->bigInteger('author_id')->unsigned();
- Read upRead up
- Exclude checks
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.
Parameter $table
has undeclared type \Illuminate\Database\Schema\Blueprint
Open
Schema::table('webinars', function (Blueprint $table) {
- Exclude checks
Parameter $table
has undeclared type \Illuminate\Database\Schema\Blueprint
Open
Schema::create('webinar_authors', function (Blueprint $table) {
- Exclude checks
Call to method id
from undeclared class \Illuminate\Database\Schema\Blueprint
Open
$table->id();
- Exclude checks
Call to method bigInteger
from undeclared class \Illuminate\Database\Schema\Blueprint
Open
$table->bigInteger('author_id')->unsigned()->nullable();
- Exclude checks
Call to method foreign
from undeclared class \Illuminate\Database\Schema\Blueprint
Open
$table->foreign('author_id')->references('id')->on('users')->cascadeOnDelete();
- Exclude checks
Call to method foreign
from undeclared class \Illuminate\Database\Schema\Blueprint
Open
$table->foreign('webinar_id')->references('id')->on('webinars')->cascadeOnDelete();
- Exclude checks
Call to method table
from undeclared class \Illuminate\Support\Facades\Schema
Open
Schema::table('webinars', function (Blueprint $table) {
- Exclude checks
Call to method timestamps
from undeclared class \Illuminate\Database\Schema\Blueprint
Open
$table->timestamps();
- Exclude checks
Parameter $table
has undeclared type \Illuminate\Database\Schema\Blueprint
Open
Schema::table('webinars', function (Blueprint $table) {
- Exclude checks
Call to method dropIfExists
from undeclared class \Illuminate\Support\Facades\Schema
Open
Schema::dropIfExists('webinar_authors');
- Exclude checks
Call to method bigInteger
from undeclared class \Illuminate\Database\Schema\Blueprint
Open
$table->bigInteger('author_id')->unsigned();
- Exclude checks
Call to method bigInteger
from undeclared class \Illuminate\Database\Schema\Blueprint
Open
$table->bigInteger('webinar_id')->unsigned();
- Exclude checks
Call to method table
from undeclared class \Illuminate\Support\Facades\Schema
Open
Schema::table('webinars', function (Blueprint $table) {
- Exclude checks
Class extends undeclared class \Illuminate\Database\Migrations\Migration
Open
class CreateWebinarAuthorsTable extends Migration
- Exclude checks
Call to method dropColumn
from undeclared class \Illuminate\Database\Schema\Blueprint
Open
$table->dropColumn('author_id');
- Exclude checks
Call to method dropForeign
from undeclared class \Illuminate\Database\Schema\Blueprint
Open
$table->dropForeign('webinars_author_id_foreign');
- Exclude checks
Call to method foreign
from undeclared class \Illuminate\Database\Schema\Blueprint
Open
$table->foreign('author_id')->references('id')->on('users')->onDelete('SET NULL');
- Exclude checks
Call to method create
from undeclared class \Illuminate\Support\Facades\Schema
Open
Schema::create('webinar_authors', function (Blueprint $table) {
- Exclude checks
Avoid using short method names like CreateWebinarAuthorsTable::up(). The configured minimum method name length is 3. Open
public function up(): void
{
Schema::create('webinar_authors', function (Blueprint $table) {
$table->id();
$table->bigInteger('author_id')->unsigned();
- Read upRead up
- Exclude checks
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 CreateWebinarAuthorsTable extends Migration
- Exclude checks