Test Failed
Push — master ( dc68d1...1f5199 )
by Mathieu
02:31
created

NewsLoader::setObjType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Charcoal\Cms\Service\Loader;
4
5
// dependencies from `charcoal-core`
6
use Charcoal\Loader\CollectionLoader;
7
8
// PHP dependencies
9
use DateTime;
10
11
/**
12
 * News Loader
13
 */
14
class NewsLoader extends AbstractLoader
15
{
16
    /**
17
     * @var string $median The median between upcoming and archive entries.
18
     */
19
    protected $median;
20
21
    /**
22
     * @var object $objType The object to load.
23
     */
24
    protected $objType;
25
26
    /**
27
     * @return CollectionLoader
28
     */
29 View Code Duplication
    public function all()
0 ignored issues
show
Duplication introduced by
This method 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...
30
    {
31
        $proto = $this->newsProto();
32
        $loader = $this->collectionLoader()->setModel($proto);
33
        $loader->addFilter('active', true);
34
35
        return $loader;
36
    }
37
38
    public function newsProto()
39
    {
40
        return $this->modelFactory()->get($this->objType());
41
    }
42
43
    /**
44
     * @return CollectionLoader
45
     */
46 View Code Duplication
    public function published()
0 ignored issues
show
Duplication introduced by
This method 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...
47
    {
48
        $now = new DateTime();
49
        $loader = $this->all();
50
        $loader->addFilter('publish_date', $now->format('Y-m-d H:i:s'), [ 'operator' => '<=' ])
51
            ->addFilter('expiry_date', $now->format('Y-m-d H:i:s'), [ 'operator' => '>=' ]);
52
53
        return $loader;
54
    }
55
56
    /**
57
     * @return CollectionLoader
58
     */
59 View Code Duplication
    public function expired()
0 ignored issues
show
Duplication introduced by
This method 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...
60
    {
61
        $now = new DateTime();
62
        $loader = $this->all();
63
        $loader->addFilter('publish_date', $now->format('Y-m-d H:i:s'), [ 'operator' => '<=' ])
64
            ->addFilter('expiry_date', $now->format('Y-m-d H:i:s'), [ 'operator' => '<=' ]);
65
66
        return $loader;
67
    }
68
69
    /**
70
     * Fetch upcoming entries based on the median or now.
71
     * @return CollectionLoader
72
     */
73
    public function upcoming()
74
    {
75
        $loader = $this->published();
76
77
        return $loader;
78
    }
79
80
    /**
81
     * Fetch upcoming entries based on the median or now.
82
     * @return CollectionLoader
83
     */
84
    public function archive()
85
    {
86
        $loader = $this->expired();
87
88
        return $loader;
89
    }
90
91
    // ==========================================================================
92
    // GETTERS
93
    // ==========================================================================
94
95
    /**
96
     * @return mixed
97
     */
98
    public function median()
99
    {
100
        return $this->median;
101
    }
102
103
    /**
104
     * @return object
105
     */
106
    public function objType()
107
    {
108
        return $this->objType;
109
    }
110
111
    // ==========================================================================
112
    // SETTERS
113
    // ==========================================================================
114
115
    /**
116
     * @param string $median The median between upcoming and archive.
117
     * @return self
118
     */
119
    public function setMedian($median)
120
    {
121
        $this->median = $median;
122
123
        return $this;
124
    }
125
126
    /**
127
     * @param object $objType The object type.
128
     * @return self
129
     */
130
    public function setObjType($objType)
131
    {
132
        $this->objType = $objType;
133
134
        return $this;
135
    }
136
}
137