LatestPostsWidget   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 5
c 2
b 1
f 1
lcom 1
cbo 1
dl 0
loc 56
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A name() 0 4 1
A options() 0 7 1
A view() 0 4 1
A data() 0 6 1
1
<?php namespace Modules\Blog\Widgets;
2
3
use Modules\Blog\Repositories\PostRepository;
4
use Modules\Core\Contracts\Setting;
5
use Modules\Dashboard\Foundation\Widgets\BaseWidget;
6
7
class LatestPostsWidget extends BaseWidget
8
{
9
    /**
10
     * @var PostRepository
11
     */
12
    private $post;
13
14
    public function __construct(PostRepository $post, Setting $setting)
15
    {
16
        $this->post = $post;
17
        $this->setting = $setting;
18
    }
19
20
    /**
21
     * Get the widget name
22
     * @return string
23
     */
24
    protected function name()
25
    {
26
        return 'LatestPostsWidget';
27
    }
28
29
    /**
30
     * Get the widget options
31
     * Possible options:
32
     *  x, y, width, height
33
     * @return string
34
     */
35
    protected function options()
36
    {
37
        return [
38
            'width' => '4',
39
            'height' => '4',
40
        ];
41
    }
42
43
    /**
44
     * Get the widget view
45
     * @return string
46
     */
47
    protected function view()
48
    {
49
        return 'blog::admin.widgets.latest-posts';
50
    }
51
52
    /**
53
     * Get the widget data to send to the view
54
     * @return string
55
     */
56
    protected function data()
57
    {
58
        $limit = $this->setting->get('blog::latest-posts-amount', locale(), 5);
59
60
        return ['posts' => $this->post->latest($limit)];
61
    }
62
}
63