Completed
Push — master ( a449a7...7f0061 )
by Gino
12:11
created

SeriesPosts::defineProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace GinoPane\BlogTaxonomy\Components;
4
5
use RainLab\Blog\Models\Post;
6
use GinoPane\BlogTaxonomy\Plugin;
7
use GinoPane\BlogTaxonomy\Models\Series;
8
9
/**
10
 * Class SeriesPosts
11
 *
12
 * @package GinoPane\BlogTaxonomy\Components
13
 */
14 View Code Duplication
class SeriesPosts extends PostListAbstract
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * @var Series
18
     */
19
    public $series;
20
21
    /**
22
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
23
     */
24
    public function componentDetails()
25
    {
26
        return [
27
            'name'        => Plugin::LOCALIZATION_KEY . 'components.series_posts.name',
28
            'description' => Plugin::LOCALIZATION_KEY . 'components.series_posts.description'
29
        ];
30
    }
31
32
    /**
33
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
34
     */
35
    public function defineProperties()
36
    {
37
        $properties = [
38
                'series' => [
39
                    'title'       => 'Series Slug',
40
                    'description' => 'Look up the series using the supplied slug value.',
41
                    'type'        => 'string',
42
                    'default'     => '{{ :slug }}',
43
                ],
44
            ] + parent::defineProperties();
45
46
        return $properties;
47
    }
48
49
    /**
50
     * Prepare variables
51
     */
52
    protected function prepareContextItem()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
53
    {
54
        // load series
55
        $this->series = Series::where('slug', $this->property('series'))->first();
56
57
        return $this->series;
58
    }
59
60
    /**
61
     * @return mixed
62
     */
63
    protected function getPostsQuery()
64
    {
65
        $query = Post::whereHas('series', function ($query) {
66
            $query->where('slug', $this->series->slug);
67
        })->isPublished();
68
69
        return $query;
70
    }
71
}
72