deep-web-solutions/wordpress-framework-core

View on GitHub

Showing 12 of 13 total issues

Function collect_granting_rules has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

    final public function collect_granting_rules(): array {
        $rules_key = "permissions_rules_{$this->get_id()}";
        $rules     = $this->get_cache_value( $rules_key );

        if ( $rules instanceof NotFoundException ) {

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

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

<?php
/**
 * A message displayed when an installation update is available.
 *
 * @since   1.0.0
Severity: Major
Found in src/templates/installation/required-update.php and 1 other location - About 2 hrs to fix
src/templates/installation/required-original.php on lines 1..33

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

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
/**
 * A message displayed before the very first installation.
 *
 * @since   1.0.0
Severity: Major
Found in src/templates/installation/required-original.php and 1 other location - About 2 hrs to fix
src/templates/installation/required-update.php on lines 1..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 123.

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 install_or_update has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function install_or_update(): ?InstallFailureException {
        if ( ! Users::has_capabilities( 'activate_plugins' ) ) {
            return new InstallFailureException( 'User does not have enough permissions to run the installation routine' );
        }

Severity: Minor
Found in src/includes/Functionalities/InstallationFunctionality.php - About 1 hr to fix

    Method output_installation_js has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function output_installation_js() {
            if ( false === $this->has_notice_output ) {
                return; // The installation/upgrade notice has not been outputted.
            }
    
    
    Severity: Minor
    Found in src/includes/Functionalities/InstallationFunctionality.php - About 1 hr to fix

      Function get_installable_versions has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function get_installable_versions(): array {
              $installable_versions = array();
      
              foreach ( \get_declared_classes() as $declared_class ) {
                  if ( ! \is_a( $declared_class, InstallableInterface::class, true ) ) {
      Severity: Minor
      Found in src/includes/Functionalities/InstallationFunctionality.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 collect_granting_rules has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          final public function collect_granting_rules(): array {
              $rules_key = "permissions_rules_{$this->get_id()}";
              $rules     = $this->get_cache_value( $rules_key );
      
              if ( $rules instanceof NotFoundException ) {

        Method register_admin_notices has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function register_admin_notices( AdminNoticesService $notices_service ): void {
                if ( \doing_action( 'activate_' . $this->get_plugin()->get_plugin_file_path() ) ) {
                    return;
                }
        
        
        Severity: Minor
        Found in src/includes/Functionalities/InstallationFunctionality.php - About 1 hr to fix

          Function update has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public function update( string $current_version ): ?UpdateFailureException {
                  $current_version = \json_decode( $current_version, true );
                  if ( \is_null( $current_version ) ) {
                      return new UpdateFailureException( \__( 'Failed to update permissions', 'dws-wp-framework-core' ) );
                  }
          Severity: Minor
          Found in src/includes/Functionalities/AbstractPermissionsFunctionality.php - About 55 mins 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 uninstall has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function uninstall(): ?UninstallFailureException {
                  if ( ! Users::has_capabilities( (array) 'delete_plugins' ) ) {
                      return new UninstallFailureException( 'User does not have enough permissions to run the uninstallation routine' );
                  }
          
          
          Severity: Minor
          Found in src/includes/Functionalities/InstallationFunctionality.php - About 45 mins 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 collect_permissions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              final public function collect_permissions(): array {
                  $permissions_key = "permissions_{$this->get_id()}";
                  $permissions     = $this->get_cache_value( $permissions_key );
          
                  if ( $permissions instanceof NotFoundException ) {
          Severity: Minor
          Found in src/includes/Functionalities/AbstractPermissionsChildFunctionality.php - About 25 mins 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 install has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public function install(): ?InstallFailureException {
                  $granting_rules = $this->collect_granting_rules();
                  $existing_roles = $this->get_existing_roles();
          
                  foreach ( $existing_roles as $wp_role ) {
          Severity: Minor
          Found in src/includes/Functionalities/AbstractPermissionsFunctionality.php - About 25 mins 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

          Severity
          Category
          Status
          Source
          Language