EscolaLMS/Consultations

View on GitHub
src/Models/Consultation.php

Summary

Maintainability
A
0 mins
Test Coverage
B
89%

Avoid using static access to class '\Illuminate\Support\Facades\Storage' in method 'getLogotypeUrlAttribute'.
Open

                $logotype = Storage::url(trim($this->attributes['logotype_path'], '/'));
Severity: Minor
Found in src/Models/Consultation.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 '\EscolaLms\Consultations\Database\Factories\ConsultationFactory' in method 'newFactory'.
Open

        return ConsultationFactory::new();
Severity: Minor
Found in src/Models/Consultation.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 '\Illuminate\Support\Facades\Storage' in method 'getImageUrlAttribute'.
Open

                $imagePath = Storage::url($path);
Severity: Minor
Found in src/Models/Consultation.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

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

        'image_path',
Severity: Critical
Found in src/Models/Consultation.php by sonar-php

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 "logotype_path" 4 times.
Open

        'logotype_path',
Severity: Critical
Found in src/Models/Consultation.php by sonar-php

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 unused local variables such as '$oa'.
Open

                return preg_match('/^(http|https):.*$/', $logotype, $oa) ?
Severity: Minor
Found in src/Models/Consultation.php by phpmd

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) ?
Severity: Minor
Found in src/Models/Consultation.php by phpmd

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

Return type of author() is undeclared type \Illuminate\Database\Eloquent\Relations\BelongsTo
Open

    public function author(): BelongsTo
Severity: Minor
Found in src/Models/Consultation.php by phan

Return type of terms() is undeclared type \Illuminate\Database\Eloquent\Relations\HasMany
Open

    public function terms(): HasMany
Severity: Minor
Found in src/Models/Consultation.php by phan

Reference to undeclared property \EscolaLms\Consultations\Models\Consultation->attributes
Open

        if ($this->attributes['logotype_path'] ?? null) {
Severity: Minor
Found in src/Models/Consultation.php by phan

Call to undeclared method \EscolaLms\Consultations\Models\Consultation::belongsToMany
Open

        return $this->belongsToMany(Category::class);
Severity: Critical
Found in src/Models/Consultation.php by phan

Call to method url from undeclared class \Illuminate\Support\Facades\Storage
Open

                $imagePath = Storage::url($path);
Severity: Critical
Found in src/Models/Consultation.php by phan

Return type of proposedTerms() is undeclared type \Illuminate\Database\Eloquent\Relations\HasMany
Open

    public function proposedTerms(): HasMany
Severity: Minor
Found in src/Models/Consultation.php by phan

Reference to undeclared property \EscolaLms\Consultations\Models\Consultation->attributes
Open

            $path = trim(trim($this->attributes['logotype_path'], '/'));
Severity: Minor
Found in src/Models/Consultation.php by phan

Call to method url from undeclared class \Illuminate\Support\Facades\Storage
Open

                $logotype = Storage::url(trim($this->attributes['logotype_path'], '/'));
Severity: Critical
Found in src/Models/Consultation.php by phan

Call to undeclared function \app()
Open

        $consultationServiceContract = app(ConsultationServiceContract::class);
Severity: Critical
Found in src/Models/Consultation.php by phan

Call to undeclared method \EscolaLms\Consultations\Models\Consultation::belongsToMany
Open

        return $this->belongsToMany(User::class, 'consultation_teachers', 'consultation_id', 'teacher_id');
Severity: Critical
Found in src/Models/Consultation.php by phan

Reference to constant class from undeclared class \EscolaLms\Categories\Models\Category
Open

        return $this->belongsToMany(Category::class);
Severity: Critical
Found in src/Models/Consultation.php by phan

Call to undeclared function \url()
Open

                    url($logotype);
Severity: Critical
Found in src/Models/Consultation.php by phan

Reference to undeclared property \EscolaLms\Consultations\Models\Consultation->attributes
Open

        if ($this->attributes['image_path'] ?? null) {
Severity: Minor
Found in src/Models/Consultation.php by phan

Class uses undeclared trait \EscolaLms\ModelFields\Traits\ModelFields
Open

class Consultation extends Model
Severity: Critical
Found in src/Models/Consultation.php by phan

Return type of categories() is undeclared type \Illuminate\Database\Eloquent\Relations\BelongsToMany
Open

    public function categories(): BelongsToMany
Severity: Minor
Found in src/Models/Consultation.php by phan

Call to undeclared method \EscolaLms\Consultations\Models\Consultation::hasMany
Open

        return $this->hasMany(ConsultationUserPivot::class);
Severity: Critical
Found in src/Models/Consultation.php by phan

Call to undeclared function \url()
Open

                    url($imagePath);
Severity: Critical
Found in src/Models/Consultation.php by phan

Static call to undeclared method \EscolaLms\Consultations\Database\Factories\ConsultationFactory::new
Open

        return ConsultationFactory::new();
Severity: Critical
Found in src/Models/Consultation.php by phan

Return type of teachers() is undeclared type \Illuminate\Database\Eloquent\Relations\BelongsToMany
Open

    public function teachers(): BelongsToMany
Severity: Minor
Found in src/Models/Consultation.php by phan

Possibly zero references to use statement for classlike/namespace CoreUser (\EscolaLms\Core\Models\User)
Open

use EscolaLms\Core\Models\User as CoreUser;
Severity: Minor
Found in src/Models/Consultation.php by phan

Class extends undeclared class \Illuminate\Database\Eloquent\Model
Open

class Consultation extends Model
Severity: Critical
Found in src/Models/Consultation.php by phan

Class uses undeclared trait \Illuminate\Database\Eloquent\Factories\HasFactory
Open

class Consultation extends Model
Severity: Critical
Found in src/Models/Consultation.php by phan

Reference to undeclared property \EscolaLms\Consultations\Models\Consultation->attributes
Open

            $path = trim(trim($this->attributes['image_path'], '/'));
Severity: Minor
Found in src/Models/Consultation.php by phan

Call to undeclared method \EscolaLms\Consultations\Models\Consultation::belongsTo
Open

        return $this->belongsTo(User::class, 'author_id');
Severity: Critical
Found in src/Models/Consultation.php by phan

Return type of users() is undeclared type \Illuminate\Database\Eloquent\Relations\BelongsToMany
Open

    public function users(): BelongsToMany
Severity: Minor
Found in src/Models/Consultation.php by phan

Call to undeclared method \EscolaLms\Consultations\Models\Consultation::belongsToMany
Open

        return $this->belongsToMany(User::class, 'consultation_user');
Severity: Critical
Found in src/Models/Consultation.php by phan

Call to undeclared method \EscolaLms\Consultations\Models\Consultation::hasMany
Open

        return $this->hasMany(ConsultationProposedTerm::class, 'consultation_id');
Severity: Critical
Found in src/Models/Consultation.php by phan

Reference to undeclared property \EscolaLms\Consultations\Models\Consultation->attributes
Open

                $logotype = Storage::url(trim($this->attributes['logotype_path'], '/'));
Severity: Minor
Found in src/Models/Consultation.php by phan

Reference to undeclared property \EscolaLms\Consultations\Models\Consultation->duration
Open

        return $this->duration ?? '0';
Severity: Minor
Found in src/Models/Consultation.php by phan

Avoid excessively long variable names like $consultationServiceContract. Keep variable name length under 20.
Open

        $consultationServiceContract = app(ConsultationServiceContract::class);
Severity: Minor
Found in src/Models/Consultation.php by phpmd

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):.*$/', $logotype, $oa) ?
Severity: Minor
Found in src/Models/Consultation.php by phpmd

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):.*$/', $imagePath, $oa) ?
Severity: Minor
Found in src/Models/Consultation.php by phpmd

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

There must be one blank line after the last USE statement; 2 found;
Open

use EscolaLms\Core\Models\User as CoreUser;
Severity: Minor
Found in src/Models/Consultation.php by phpcodesniffer

There are no issues that match your filters.

Category
Status