BlogCell   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 67
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A sidebar() 0 58 2
1
<?php
2
namespace App\View\Cell;
3
4
use Cake\View\Cell;
5
6
class BlogCell extends Cell
7
{
8
9
    /**
10
     * Display the sidebar on the blog pages.
11
     *
12
     * @return void
13
     */
14
    public function sidebar()
15
    {
16
        $this->loadModel('BlogCategories');
17
        $this->loadModel('BlogArticles');
18
19
        $articleSearch = $this->BlogArticles->newEntity($this->request->data);
0 ignored issues
show
Bug introduced by
The property BlogArticles does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Deprecated Code introduced by
The property Cake\Http\ServerRequest::$data has been deprecated with message: 3.4.0 This public property will be removed in 4.0.0. Use getData() instead.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
20
21
        //Select all Categories.
22
        $categories = $this->BlogCategories
0 ignored issues
show
Bug introduced by
The property BlogCategories does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
            ->find()
24
            ->select([
25
                'id',
26
                'title',
27
                'article_count'
28
            ])
29
            ->all();
30
31
        //Select featured article.
32
        $featured = $this->BlogArticles
33
            ->find()
34
            ->select([
35
                'id',
36
                'title',
37
                'created',
38
                'comment_count'
39
            ])
40
            ->contain([
41
                'Users' => function ($q) {
42
                    return $q->find('short');
43
                }
44
            ])
45
            ->where([
46
                'BlogArticles.id !=' => ($this->request->id) ? $this->request->id : 0,
47
                'BlogArticles.is_display' => 1
48
            ])
49
            ->order([
50
                'BlogArticles.created' => 'desc'
51
            ])
52
            ->first();
53
54
        //Select all articles and group them by monthly.
55
        $archives = $this->BlogArticles
56
            ->find('all')
57
            ->select([
58
                'date' => 'DATE(created)',
59
                'count' => 'COUNT(*)'
60
            ])
61
            ->group('SUBSTR(DATE(created), 1, 7)')
62
            ->order([
63
                'date' => 'desc'
64
            ])
65
            ->where([
66
                'is_display' => 1
67
            ])
68
            ->toArray();
69
70
        $this->set(compact('categories', 'featured', 'archives', 'articleSearch'));
71
    }
72
}
73