protected/modules/blog/models/Post.php

Summary

Maintainability
D
2 days
Test Coverage

File Post.php has 538 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Post
 *
 * Модель для работы с постами
Severity: Major
Found in protected/modules/blog/models/Post.php - About 1 day to fix

    Post has 39 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Post extends yupe\models\YModel implements ICommentable
    {
        /**
         *
         */
    Severity: Minor
    Found in protected/modules/blog/models/Post.php - About 5 hrs to fix

      Method rules has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function rules()
          {
              return [
                  ['blog_id, slug,  title, content, status, publish_time', 'required', 'except' => 'search'],
                  [
      Severity: Minor
      Found in protected/modules/blog/models/Post.php - About 1 hr to fix

        Method search has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function search($limit = null)
            {
                $criteria = new CDbCriteria();
        
                $criteria->compare('t.id', $this->id, true);
        Severity: Minor
        Found in protected/modules/blog/models/Post.php - About 1 hr to fix

          Method behaviors has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function behaviors()
              {
                  $module = Yii::app()->getModule('blog');
          
                  return [
          Severity: Minor
          Found in protected/modules/blog/models/Post.php - About 1 hr to fix

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

                public function relations()
                {
                    return [
                        'createUser' => [self::BELONGS_TO, 'User', 'create_user_id'],
                        'updateUser' => [self::BELONGS_TO, 'User', 'update_user_id'],
            Severity: Minor
            Found in protected/modules/blog/models/Post.php - About 1 hr to fix

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

                  public function getArchive($blogId = null, $cache = 3600)
                  {
                      $data = Yii::app()->getCache()->get("Blog::Post::archive::{$blogId}");
              
                      if (false === $data) {
              Severity: Minor
              Found in protected/modules/blog/models/Post.php - About 1 hr to fix

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

                    public function getArchive($blogId = null, $cache = 3600)
                    {
                        $data = Yii::app()->getCache()->get("Blog::Post::archive::{$blogId}");
                
                        if (false === $data) {
                Severity: Minor
                Found in protected/modules/blog/models/Post.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

                Avoid too many return statements within this method.
                Open

                        return $this->save();
                Severity: Major
                Found in protected/modules/blog/models/Post.php - About 30 mins to fix

                  Function createPublicPost has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function createPublicPost(array $post)
                      {
                          if (empty($post['blog_id']) || empty($post['user_id'])) {
                              $this->addError('blog_id', Yii::t('BlogModule.blog', "Blog is empty!"));
                  
                  
                  Severity: Minor
                  Found in protected/modules/blog/models/Post.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

                  There are no issues that match your filters.

                  Category
                  Status