Avoid unused local variables such as '$oa'. Open
return preg_match('/^(http|https):.*$/', $logotype, $oa) ?
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$oa'. Open
return preg_match('/^(http|https):.*$/', $imagePath, $oa) ?
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Class extends undeclared class \Illuminate\Database\Eloquent\Model
Open
class Webinar extends Model
- Exclude checks
Reference to undeclared property \EscolaLms\Webinar\Models\Webinar->attributes
Open
$path = trim(trim($this->attributes['logotype_path'], '/'));
- Exclude checks
Reference to undeclared property \EscolaLms\Webinar\Models\Webinar->attributes
Open
$logotype = Storage::url(trim($this->attributes['logotype_path'], '/'));
- Exclude checks
Call to undeclared method \EscolaLms\Webinar\Models\Webinar::belongsToMany
Open
return $this->belongsToMany(User::class, 'webinar_trainers','webinar_id', 'trainer_id') ;
- Exclude checks
Property \EscolaLms\Webinar\Models\Webinar->active_to
has undeclared type ?\Illuminate\Support\Carbon
Open
* @property ?Carbon $active_to
- Exclude checks
Reference to undeclared property \EscolaLms\Webinar\Models\Webinar->attributes
Open
$path = trim(trim($this->attributes['image_path'], '/'));
- Exclude checks
Call to undeclared function \url()
Open
url($imagePath);
- Exclude checks
Return type of trainers()
is undeclared type \Illuminate\Database\Eloquent\Relations\BelongsToMany
Open
public function trainers(): BelongsToMany
- Exclude checks
Return type of tags()
is undeclared type \Illuminate\Database\Eloquent\Relations\MorphMany
Open
public function tags(): MorphMany
- Exclude checks
Call to undeclared function \app()
Open
$webinarServiceContract = app(WebinarServiceContract::class);
- Exclude checks
Class uses undeclared trait \Illuminate\Database\Eloquent\Factories\HasFactory
Open
class Webinar extends Model
- Exclude checks
Reference to constant class
from undeclared class \EscolaLms\Tags\Models\Tag
Open
return $this->morphMany(Tag::class, 'morphable');
- Exclude checks
Call to undeclared method \EscolaLms\Webinar\Models\Webinar::morphMany
Open
return $this->morphMany(Tag::class, 'morphable');
- Exclude checks
Call to method url
from undeclared class \Illuminate\Support\Facades\Storage
Open
$imagePath = Storage::url($path);
- Exclude checks
Call to undeclared function \url()
Open
url($logotype);
- Exclude checks
Reference to undeclared property \EscolaLms\Webinar\Models\Webinar->attributes
Open
if ($this->attributes['image_path'] ?? null) {
- Exclude checks
Call to method url
from undeclared class \Illuminate\Support\Facades\Storage
Open
$logotype = Storage::url(trim($this->attributes['logotype_path'], '/'));
- Exclude checks
Reference to undeclared property \EscolaLms\Webinar\Models\Webinar->attributes
Open
if ($this->attributes['logotype_path'] ?? null) {
- Exclude checks
Static call to undeclared method \EscolaLms\Webinar\Database\Factories\WebinarFactory::new
Open
return WebinarFactory::new();
- Exclude checks
Call to undeclared method \EscolaLms\Webinar\Models\Webinar::belongsToMany
Open
return $this->belongsToMany(User::class, 'webinar_user');
- Exclude checks
Reference to undeclared property \EscolaLms\Webinar\Models\Webinar->duration
Open
return $this->duration ?? '';
- Exclude checks
Call to undeclared function \app()
Open
$webinarServiceContract = app(WebinarServiceContract::class);
- Exclude checks
Return type of users()
is undeclared type \Illuminate\Database\Eloquent\Relations\BelongsToMany
Open
public function users(): BelongsToMany
- Exclude checks
Avoid using static access to class '\EscolaLms\Webinar\Database\Factories\WebinarFactory' in method 'newFactory'. Open
return WebinarFactory::new();
- 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\Storage' in method 'getImageUrlAttribute'. Open
$imagePath = Storage::url($path);
- 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\Storage' in method 'getLogotypeUrlAttribute'. Open
$logotype = Storage::url(trim($this->attributes['logotype_path'], '/'));
- 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 "logotype_path" 3 times. Open
if ($this->attributes['logotype_path'] ?? null) {
- 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 "image_path" 3 times. Open
'image_path',
- 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.
Avoid excessively long variable names like $webinarServiceContract. Keep variable name length under 20. Open
$webinarServiceContract = app(WebinarServiceContract::class);
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $webinarServiceContract. Keep variable name length under 20. Open
$webinarServiceContract = app(WebinarServiceContract::class);
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid variables with short names like $oa. Configured minimum length is 3. Open
return preg_match('/^(http|https):.*$/', $imagePath, $oa) ?
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $oa. Configured minimum length is 3. Open
return preg_match('/^(http|https):.*$/', $logotype, $oa) ?
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
No space found after comma in function call Open
return $this->belongsToMany(User::class, 'webinar_trainers','webinar_id', 'trainer_id') ;
- Exclude checks