mateusjunges/laravel-acl

View on GitHub

Showing 22 of 25 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Severity: Major
Found in database/migrations/create_model_has_groups_table.php and 1 other location - About 1 day to fix
database/migrations/create_model_has_permissions_table.php on lines 1..47

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 324.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Severity: Major
Found in database/migrations/create_model_has_permissions_table.php and 1 other location - About 1 day to fix
database/migrations/create_model_has_groups_table.php on lines 1..47

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 324.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        $groups = collect(is_array($groups) || $groups instanceof Collection ? $groups : func_get_args())
            ->flatten()
            ->reduce(function ($array, $group) {
                if (empty($group)) {
                    return $array;
Severity: Major
Found in src/Concerns/HasGroups.php and 1 other location - About 4 hrs to fix
src/Concerns/HasPermissions.php on lines 379..398

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 171.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        $permissions = collect(is_array($permissions) || $permissions instanceof Collection ? $permissions : func_get_args())
            ->flatten()
            ->reduce(function ($array, $permission) {
                if (empty($permission)) {
                    return $array;
Severity: Major
Found in src/Concerns/HasPermissions.php and 1 other location - About 4 hrs to fix
src/Concerns/HasGroups.php on lines 112..131

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 171.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

File HasPermissions.php has 281 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Junges\ACL\Concerns;

use Illuminate\Database\Eloquent\Builder;
Severity: Minor
Found in src/Concerns/HasPermissions.php - About 2 hrs to fix

    Method up has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function up()
        {
            $teams = config('acl.teams');
            $tableNames = config('acl.tables');
            $columnNames = config('acl.column_names');
    Severity: Major
    Found in database/migrations/add_teams_fields.php - About 2 hrs to fix

      AclRegistrar has 21 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class AclRegistrar
      {
          protected Repository $cache;
          protected CacheManager $cacheManager;
          protected string $permissionClass;
      Severity: Minor
      Found in src/AclRegistrar.php - About 2 hrs to fix

        Function up has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public function up()
            {
                $teams = config('acl.teams');
                $tableNames = config('acl.tables');
                $columnNames = config('acl.column_names');
        Severity: Minor
        Found in database/migrations/add_teams_fields.php - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method assignGroup has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function assignGroup($groups): self
            {
                $groups = collect(is_array($groups) || $groups instanceof Collection ? $groups : func_get_args())
                    ->flatten()
                    ->reduce(function ($array, $group) {
        Severity: Minor
        Found in src/Concerns/HasGroups.php - About 1 hr to fix

          Method assignPermission has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function assignPermission($permissions): self
              {
                  $permissions = collect(is_array($permissions) || $permissions instanceof Collection ? $permissions : func_get_args())
                      ->flatten()
                      ->reduce(function ($array, $permission) {
          Severity: Minor
          Found in src/Concerns/HasPermissions.php - About 1 hr to fix

            Function hasGroup has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                public function hasGroup($groups, string $guard = null): bool
                {
                    if (is_string($groups) && strpos($groups, '|') !== false) {
                        $groups = $this->convertPipeToArray($groups);
                    }
            Severity: Minor
            Found in src/Concerns/HasGroups.php - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method hasGroup has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function hasGroup($groups, string $guard = null): bool
                {
                    if (is_string($groups) && strpos($groups, '|') !== false) {
                        $groups = $this->convertPipeToArray($groups);
                    }
            Severity: Minor
            Found in src/Concerns/HasGroups.php - About 1 hr to fix

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  public static function forPermissions(array $permissions = []): self
                  {
                      $message = 'User does not have the right permissions.';
              
                      if (config('permission.display_permission_in_exception')) {
              Severity: Minor
              Found in src/Exceptions/UnauthorizedException.php and 1 other location - About 1 hr to fix
              src/Exceptions/UnauthorizedException.php on lines 13..26

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 100.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  public static function forGroups(array $groups = []): self
                  {
                      $message = 'User does not have the right groups.';
              
                      if (config('acl.display_permission_in_exception')) {
              Severity: Minor
              Found in src/Exceptions/UnauthorizedException.php and 1 other location - About 1 hr to fix
              src/Exceptions/UnauthorizedException.php on lines 28..41

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 100.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Avoid too many return statements within this method.
              Open

                              return '<?php } ?>';
              Severity: Major
              Found in src/Providers/ACLViewServiceProvider.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return $permissions;
                Severity: Major
                Found in src/Concerns/HasPermissions.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return $this;
                  Severity: Major
                  Found in src/Concerns/HasPermissions.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return "<?php }else if(auth({$guard})->check() && auth({$guard})->user()->hasPermission({$permission})){?>";
                    Severity: Major
                    Found in src/Providers/ACLViewServiceProvider.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return $this;
                      Severity: Major
                      Found in src/Concerns/HasGroups.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return false;
                        Severity: Major
                        Found in src/Concerns/HasGroups.php - About 30 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language