artesaos/defender

View on GitHub

Showing 21 of 21 total issues

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

<?php

namespace Artesaos\Defender\Middlewares;

use Closure;
Severity: Major
Found in src/Defender/Middlewares/NeedsPermissionMiddleware.php and 1 other location - About 1 day to fix
src/Defender/Middlewares/NeedsRoleMiddleware.php on lines 1..71

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 319.

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

namespace Artesaos\Defender\Middlewares;

use Closure;
Severity: Major
Found in src/Defender/Middlewares/NeedsRoleMiddleware.php and 1 other location - About 1 day to fix
src/Defender/Middlewares/NeedsPermissionMiddleware.php on lines 1..71

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 319.

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 function down()
    {
        Schema::table(config('defender.role_user_table', 'role_user'), function (Blueprint $table) {
            $table->dropForeign(config('defender.role_user_table', 'role_user').'_user_id_foreign');
            $table->dropForeign(config('defender.role_user_table', 'role_user').'_'.config('defender.role_key', 'role_id').'_foreign');
src/resources/migrations/2015_02_23_161104_create_defender_permission_user_table.php on lines 30..38

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 122.

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 function down()
    {
        Schema::table(config('defender.permission_user_table', 'permission_user'), function (Blueprint $table) {
            $table->dropForeign(config('defender.permission_user_table', 'permission_user').'_user_id_foreign');
            $table->dropForeign(config('defender.permission_user_table', 'permission_user').'_'.config('defender.permission_key', 'permission_id').'_foreign');
src/resources/migrations/2015_02_23_161103_create_defender_role_user_table.php on lines 27..35

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 122.

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

Function handle has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function handle($request, Closure $next, $roles = null, $any = false)
    {
        if (is_null($roles)) {
            $roles = $this->getRoles($request);
            $anyRole = $this->getAny($request);
Severity: Minor
Found in src/Defender/Middlewares/NeedsRoleMiddleware.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

Function handle has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function handle($request, Closure $next, $permissions = null, $any = false)
    {
        if (is_null($permissions)) {
            $permissions = $this->getPermissions($request);
            $anyPermission = $this->getAny($request);
Severity: Minor
Found in src/Defender/Middlewares/NeedsPermissionMiddleware.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

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

    public function newPivot(Model $parent, array $attributes, $table, $exists, $using = null)
    {
        $permissionModel = app()['config']->get('defender.permission_model');

        if ($parent instanceof $permissionModel) {
Severity: Major
Found in src/Defender/Traits/Permissions/RoleHasPermissions.php and 1 other location - About 1 hr to fix
src/Defender/Traits/Users/HasPermissions.php on lines 40..49

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 103.

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

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

    public function newPivot(Model $parent, array $attributes, $table, $exists, $using = null)
    {
        $permissionModel = app()['config']->get('defender.permission_model');

        if ($parent instanceof $permissionModel) {
Severity: Major
Found in src/Defender/Traits/Users/HasPermissions.php and 1 other location - About 1 hr to fix
src/Defender/Traits/Permissions/RoleHasPermissions.php on lines 39..48

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 103.

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

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

    public function handle($request, Closure $next, $permissions = null, $any = false)
    {
        if (is_null($permissions)) {
            $permissions = $this->getPermissions($request);
            $anyPermission = $this->getAny($request);
Severity: Minor
Found in src/Defender/Middlewares/NeedsPermissionMiddleware.php - About 1 hr to fix

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

        public function handle($request, Closure $next, $roles = null, $any = false)
        {
            if (is_null($roles)) {
                $roles = $this->getRoles($request);
                $anyRole = $this->getAny($request);
    Severity: Minor
    Found in src/Defender/Middlewares/NeedsRoleMiddleware.php - About 1 hr to fix

      Method newPivot has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          public function newPivot(Model $parent, array $attributes, $table, $exists, $using = null)
      Severity: Minor
      Found in src/Defender/Traits/Users/HasPermissions.php - About 35 mins to fix

        Method newPivot has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            public function newPivot(Model $parent, array $attributes, $table, $exists, $using = null)
        Severity: Minor
        Found in src/Defender/Traits/Models/Permission.php - About 35 mins to fix

          Method newPivot has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public function newPivot(Model $parent, array $attributes, $table, $exists, $using = null)
          Severity: Minor
          Found in src/Defender/Traits/Permissions/RoleHasPermissions.php - About 35 mins to fix

            Method newPivot has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                public function newPivot(Model $parent, array $attributes, $table, $exists, $using = null);
            Severity: Minor
            Found in src/Defender/Contracts/Permission.php - About 35 mins to fix

              Avoid too many return statements within this method.
              Open

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

                Avoid too many return statements within this method.
                Open

                            return new EloquentPermissionRepository($app, $app->make(\Artesaos\Defender\Contracts\Permission::class));
                Severity: Major
                Found in src/Defender/Providers/DefenderServiceProvider.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return $next($request);
                  Severity: Major
                  Found in src/Defender/Middlewares/NeedsPermissionMiddleware.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return new EloquentUserRepository($app, $app->make($userModel));
                    Severity: Major
                    Found in src/Defender/Providers/DefenderServiceProvider.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return $next($request);
                      Severity: Major
                      Found in src/Defender/Middlewares/NeedsRoleMiddleware.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return $app['defender.permission'];
                        Severity: Major
                        Found in src/Defender/Providers/DefenderServiceProvider.php - About 30 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language