deep-web-solutions/wordpress-framework-utilities

View on GitHub

Showing 32 of 57 total issues

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

    public static function get_missing_php_extensions_notice_message( string $registrant_name, array $php_extensions, bool $are_optional = false ): string {
        if ( $are_optional ) {
            return \sprintf(
                /* translators: 1. Plugin or identifiable name, 2. Comma-separated list of missing PHP extensions. */
                \_n(
src/includes/Dependencies/Helpers/DependenciesServiceHelpers.php on lines 226..252

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

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 get_missing_php_functions_notice_message( string $registrant_name, array $php_functions, bool $are_optional = false ): string {
        if ( $are_optional ) {
            return \sprintf(
                /* translators: 1. Plugin or identifiable name, 2. Comma-separated list of missing PHP functions. */
                \_n(
src/includes/Dependencies/Helpers/DependenciesServiceHelpers.php on lines 266..292

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

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 status_to_boolean has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    public static function status_to_boolean( $are_deps_fulfilled, bool $include_optional = true ): bool {
        if ( \is_array( \reset( $are_deps_fulfilled ) ) ) { // MultiCheckerHandler
            foreach ( $are_deps_fulfilled as $deps_status ) {
                if ( false === $include_optional ) {
                    $optional_keys = Arrays::search_keys( $deps_status, true, array( self::class, 'is_optional_checker' ) );
Severity: Minor
Found in src/includes/Dependencies/Helpers/DependenciesServiceHelpers.php - About 2 hrs 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 get_missing_dependencies has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function get_missing_dependencies(): array {
        $missing = array();

        if ( \function_exists( 'ini_get' ) ) {
            foreach ( $this->get_dependencies() as $dependency ) {

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 output_local has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    protected function output_local(): ?OutputFailureException {
        foreach ( $this->get_store()->get_all() as $admin_notices_store ) {
            if ( $admin_notices_store instanceof StoreInterface ) {
                foreach ( $this->get_notices( $admin_notices_store->get_id() ) as $notice ) {
                    $result = $this->output_notice( $notice, $admin_notices_store );
Severity: Minor
Found in src/includes/AdminNotices/AbstractAdminNoticesHandler.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 get_plugin_name has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    protected function get_plugin_name( string $plugin, array $plugin_config ): string {
        if ( $this->is_plugin_active( $plugin, $plugin_config ) ) {
            if ( isset( $plugin_config['name_getter'] ) && \is_callable( $plugin_config['name_getter'] ) ) {
                $plugin_name = Strings::maybe_cast( \call_user_func( $plugin_config['name_getter'] ), '' );
            } else {
Severity: Minor
Found in src/includes/Dependencies/Checkers/WPPluginsChecker.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 output_dismiss_js has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function output_dismiss_js(): void {
        if ( false === $this->has_output ) {
            return;
        }

Severity: Minor
Found in src/includes/AdminNotices/Handlers/DismissibleNoticesHandler.php - About 1 hr to fix

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

        public function add_filter( string $hook, ?object $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void {
            parent::add_filter( $hook, $component, $callback, $priority, $accepted_args );
    
            if ( empty( $component ) ) {
                \add_filter( $hook, $callback, $priority, $accepted_args );
    Severity: Major
    Found in src/includes/Hooks/Handlers/DirectHooksHandler.php and 1 other location - About 1 hr to fix
    src/includes/Hooks/Handlers/DirectHooksHandler.php on lines 43..51

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

    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 add_action( string $hook, ?object $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void {
            parent::add_action( $hook, $component, $callback, $priority, $accepted_args );
    
            if ( empty( $component ) ) {
                \add_action( $hook, $callback, $priority, $accepted_args );
    Severity: Major
    Found in src/includes/Hooks/Handlers/DirectHooksHandler.php and 1 other location - About 1 hr to fix
    src/includes/Hooks/Handlers/DirectHooksHandler.php on lines 87..95

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

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

        public function setup_active_state_dependencies_admin_notices(): ?SetupFailureException {
            $deps_handler = $this->get_dependencies_handler( DependencyContextsEnum::ACTIVE_STATE );
            if ( \is_null( $deps_handler ) ) {
                throw new NotImplementedException( 'Dependencies admin notices scenario not supported' );
            }

      Method get_admin_notice_handle has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function get_admin_notice_handle( string $name = '', $extra = array(), string $root = 'dws-framework-utilities' ): string {
              if ( $this instanceof PluginComponentInterface ) {
                  $root = ( 'dws-framework-utilities' === $root ) ? '' : $root;
                  $root = \join( '_', array( $this->get_plugin()->get_plugin_slug(), $root ?: $this->get_name() ) );
              } elseif ( 'dws-framework-utilities' === $root ) {
      Severity: Minor
      Found in src/includes/AdminNotices/Helpers/AdminNoticesHelpersTrait.php - About 1 hr to fix

        Method get_missing_dependencies has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function get_missing_dependencies(): array {
                $missing = array();
        
                if ( \function_exists( 'ini_get' ) ) {
                    foreach ( $this->get_dependencies() as $dependency ) {

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

              public function setup_active_state_dependencies_admin_notices(): ?SetupFailureException {
                  $deps_handler = $this->get_dependencies_handler( DependencyContextsEnum::ACTIVE_STATE );
                  if ( \is_null( $deps_handler ) ) {
                      throw new NotImplementedException( 'Dependencies admin notices scenario not supported' );
                  }

          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 initialize_dependencies_handlers has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function initialize_dependencies_handlers(): ?InitializationFailureException {
                  if ( $this instanceof DependenciesServiceAwareInterface ) {
                      $service = $this->get_dependencies_service();
                  } elseif ( $this instanceof ContainerAwareInterface ) {
                      $service = $this->get_container()->get( DependenciesService::class );

          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 add_filter has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public function add_filter( string $hook, ?object $component, string $callback, int $priority = 10, int $accepted_args = 1 );
          Severity: Minor
          Found in src/includes/Hooks/HooksAdapterInterface.php - About 35 mins to fix

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

                public function validate_allowed_value( $value, string $default_key, string $options_key, string $validation_type, string $handler_id = 'settings' ) {
            Severity: Minor
            Found in src/includes/Validation/ValidationService.php - About 35 mins to fix

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

                  public function add_filter( string $hook, ?object $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void {
              Severity: Minor
              Found in src/includes/Hooks/Handlers/DirectHooksHandler.php - About 35 mins to fix

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

                    public function add_action( string $hook, ?object $component, string $callback, int $priority = 10, int $accepted_args = 1 );
                Severity: Minor
                Found in src/includes/Hooks/HooksAdapterInterface.php - About 35 mins to fix

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

                      protected function validate_allowed_value( $value, string $default_key, string $options_key, string $validation_type, string $handler_id = 'settings' ) {
                  Severity: Minor
                  Found in src/includes/Validation/ValidationServiceAwareTrait.php - About 35 mins to fix

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

                        public function add_action( string $hook, ?object $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void {
                    Severity: Minor
                    Found in src/includes/Hooks/Handlers/DirectHooksHandler.php - About 35 mins to fix
                      Severity
                      Category
                      Status
                      Source
                      Language