intraxia/wp-gistpen

View on GitHub
app/Database/Repository/WordPressPost.php

Summary

Maintainability
F
3 days
Test Coverage

Function persist has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

    public function persist( Model $model ) {
        $result = $model->get_primary_id() ?
            wp_update_post( $model->get_underlying_wp_object(), true ) :
            wp_insert_post( (array) $model->get_underlying_wp_object(), true );

Severity: Minor
Found in app/Database/Repository/WordPressPost.php - About 5 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

Method persist has 91 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function persist( Model $model ) {
        $result = $model->get_primary_id() ?
            wp_update_post( $model->get_underlying_wp_object(), true ) :
            wp_insert_post( (array) $model->get_underlying_wp_object(), true );

Severity: Major
Found in app/Database/Repository/WordPressPost.php - About 3 hrs to fix

    Function create has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        public function create( $class, array $data = array(), array $options = array() ) {
            $model = new $class();
    
            /**
             * Set aside the `blobs` key for use.
    Severity: Minor
    Found in app/Database/Repository/WordPressPost.php - About 3 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

    File WordPressPost.php has 302 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    namespace Intraxia\Gistpen\Database\Repository;
    
    use Exception;
    Severity: Minor
    Found in app/Database/Repository/WordPressPost.php - About 3 hrs to fix

      Method create has 64 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function create( $class, array $data = array(), array $options = array() ) {
              $model = new $class();
      
              /**
               * Set aside the `blobs` key for use.
      Severity: Major
      Found in app/Database/Repository/WordPressPost.php - About 2 hrs to fix

        Method find_by has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function find_by( $class, array $params = array() ) {
                $post_type     = $class::get_post_type();
                $parent_search = 'post_parent__in';
        
                if ( Blob::class === $class ) {
        Severity: Major
        Found in app/Database/Repository/WordPressPost.php - About 2 hrs to fix

          Function find has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              public function find( $class, $id, array $params = array() ) {
                  $post_type = $class::get_post_type();
                  $post      = get_post( $id );
          
                  if ( ! $post || $post->post_type !== $post_type ) {
          Severity: Minor
          Found in app/Database/Repository/WordPressPost.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 find_by has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              public function find_by( $class, array $params = array() ) {
                  $post_type     = $class::get_post_type();
                  $parent_search = 'post_parent__in';
          
                  if ( Blob::class === $class ) {
          Severity: Minor
          Found in app/Database/Repository/WordPressPost.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

          Method find has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function find( $class, $id, array $params = array() ) {
                  $post_type = $class::get_post_type();
                  $post      = get_post( $id );
          
                  if ( ! $post || $post->post_type !== $post_type ) {
          Severity: Minor
          Found in app/Database/Repository/WordPressPost.php - About 1 hr to fix

            Avoid too many return statements within this method.
            Open

                            return $state->ID;
            Severity: Major
            Found in app/Database/Repository/WordPressPost.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $this->find( get_class( $model ), $model->get_primary_id() );
              Severity: Major
              Found in app/Database/Repository/WordPressPost.php - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status