EscolaLMS/model-fields

View on GitHub
src/Policies/MetadataPolicy.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%

Avoid unused parameters such as '$template'.
Open

    public function delete(?User $user, Metadata $template = null): bool
Severity: Minor
Found in src/Policies/MetadataPolicy.php by phpmd

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Avoid unused parameters such as '$user'.
Open

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

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Parameter $user has undeclared type ?\EscolaLms\Core\Models\User
Open

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

Parameter $user has undeclared type ?\EscolaLms\Core\Models\User
Open

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

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

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

Parameter $user has undeclared type ?\EscolaLms\Core\Models\User
Open

    public function delete(?User $user, Metadata $template = null): bool
Severity: Minor
Found in src/Policies/MetadataPolicy.php by phan

Call to method can from undeclared class \EscolaLms\Core\Models\User
Open

        return !is_null($user) && $user->can(MetaFieldPermissionsEnum::METADATA_DELETE);
Severity: Critical
Found in src/Policies/MetadataPolicy.php by phan

Call to method can from undeclared class \EscolaLms\Core\Models\User
Open

        return !is_null($user) && $user->can(MetaFieldPermissionsEnum::METADATA_CREATE_UPDATE);
Severity: Critical
Found in src/Policies/MetadataPolicy.php by phan

Remove the unused function parameter "$template".
Open

    public function delete(?User $user, Metadata $template = null): bool
Severity: Major
Found in src/Policies/MetadataPolicy.php by sonar-php

Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

Noncompliant Code Example

function doSomething($a, $b) { // "$a" is unused
  return compute($b);
}

Compliant Solution

function doSomething($b) {
  return compute($b);
}

Exceptions

Functions in classes that override a class or implement interfaces are ignored.

class C extends B {

  function doSomething($a, $b) {     // no issue reported on $b
    compute($a);
  }

}

See

  • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
  • MISRA C:2012, 2.7 - There should be no unused parameters in functions
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CERT, MSC12-CPP. - Detect and remove code that has no effect

Remove the unused function parameter "$user".
Open

    public function list(?User $user): bool
Severity: Major
Found in src/Policies/MetadataPolicy.php by sonar-php

Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

Noncompliant Code Example

function doSomething($a, $b) { // "$a" is unused
  return compute($b);
}

Compliant Solution

function doSomething($b) {
  return compute($b);
}

Exceptions

Functions in classes that override a class or implement interfaces are ignored.

class C extends B {

  function doSomething($a, $b) {     // no issue reported on $b
    compute($a);
  }

}

See

  • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
  • MISRA C:2012, 2.7 - There should be no unused parameters in functions
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CERT, MSC12-CPP. - Detect and remove code that has no effect

There are no issues that match your filters.

Category
Status