EscolaLMS/Webinar

View on GitHub
src/Policies/WebinarPolicy.php

Summary

Maintainability
A
0 mins
Test Coverage

Call to method where from undeclared class \Illuminate\Database\Eloquent\Relations\BelongsToMany
Open

                && $webinar->trainers()->where('trainer_id', $user->getKey())->exists()
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Call to method getKey from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

                && $webinar->trainers()->where('trainer_id', $user->getKey())->exists()
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Call to method can from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

        return $user->can(WebinarPermissionsEnum::WEBINAR_UPDATE)
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Call to method can from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

        return $user->can(WebinarPermissionsEnum::WEBINAR_READ)
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Parameter $user has undeclared type \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

    public function delete(User $user, Webinar $webinar): bool
Severity: Minor
Found in src/Policies/WebinarPolicy.php by phan

Class uses undeclared trait \Illuminate\Auth\Access\HandlesAuthorization
Open

class WebinarPolicy
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Call to method getKey from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

                && $webinar->trainers()->where('trainer_id', $user->getKey())->exists()
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Call to method getKey from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

                && $webinar->trainers()->where('trainer_id', $user->getKey())->exists()
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Call to method can from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

        return $user->can(WebinarPermissionsEnum::WEBINAR_CREATE);
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Parameter $user has undeclared type \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

    public function update(User $user, Webinar $webinar): bool
Severity: Minor
Found in src/Policies/WebinarPolicy.php by phan

Parameter $user has undeclared type \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

    public function create(User $user): bool
Severity: Minor
Found in src/Policies/WebinarPolicy.php by phan

Call to method can from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

                $user->can(WebinarPermissionsEnum::WEBINAR_UPDATE_OWN)
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Parameter $user has undeclared type \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

    public function list(User $user): bool
Severity: Minor
Found in src/Policies/WebinarPolicy.php by phan

Call to method where from undeclared class \Illuminate\Database\Eloquent\Relations\BelongsToMany
Open

                && $webinar->trainers()->where('trainer_id', $user->getKey())->exists()
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Call to method can from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

        return $user->can(WebinarPermissionsEnum::WEBINAR_DELETE)
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Call to method canAny from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

        return $user->canAny([WebinarPermissionsEnum::WEBINAR_LIST, WebinarPermissionsEnum::WEBINAR_LIST_OWN]);
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Parameter $user has undeclared type \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

    public function read(User $user, Webinar $webinar): bool
Severity: Minor
Found in src/Policies/WebinarPolicy.php by phan

Call to method can from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

                $user->can(WebinarPermissionsEnum::WEBINAR_DELETE_OWN)
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Call to method where from undeclared class \Illuminate\Database\Eloquent\Relations\BelongsToMany
Open

                && $webinar->trainers()->where('trainer_id', $user->getKey())->exists()
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

Call to method can from undeclared class \EscolaLms\Auth\Models\User (Did you mean class \EscolaLms\Webinar\Models\User)
Open

                $user->can(WebinarPermissionsEnum::WEBINAR_READ_OWN)
Severity: Critical
Found in src/Policies/WebinarPolicy.php by phan

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

                && $webinar->trainers()->where('trainer_id', $user->getKey())->exists()
Severity: Critical
Found in src/Policies/WebinarPolicy.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.

There are no issues that match your filters.

Category
Status