Completed
Push — master ( 75bb5a...dea818 )
by Mathieu
07:39
created

News::setInfoUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Charcoal\Cms;
4
5
use \DateTime;
6
use \DateTimeInterface;
7
use \InvalidArgumentException;
8
9
use \Psr\Http\Message\RequestInterface;
10
use \Psr\Http\Message\ResponseInterface;
11
12
// Dependencies from `charcoal-translation`
13
use \Charcoal\Translation\TranslationString;
14
15
// Dependencies from `charcoal-base`
16
use \Charcoal\Object\Content;
17
use \Charcoal\Object\CategorizableInterface;
18
use \Charcoal\Object\CategorizableTrait;
19
use \Charcoal\Object\PublishableInterface;
20
use \Charcoal\Object\PublishableTrait;
21
22
// Dependencies from `charcoal-app`
23
use \Charcoal\App\Routable\RoutableInterface;
24
use \Charcoal\App\Routable\RoutableTrait;
25
26
// Intra-module (`charcoal-cms`) dependencies
27
use \Charcoal\Cms\MetatagInterface;
28
use \Charcoal\Cms\SearchableInterface;
29
30
/**
31
* News
32
*/
33
class News extends Content implements
34
    CategorizableInterface,
35
    MetatagInterface,
36
    PublishableInterface,
37
    RoutableInterface,
38
    SearchableInterface
39
{
40
    use CategorizableTrait;
41
    use PublishableTrait;
42
    use MetatagTrait;
43
    use RoutableTrait;
44
    use SearchableTrait;
45
46
    /**
47
    * @var TranslationString $title
48
    */
49
    private $title;
50
51
    /**
52
    * @var TranslationString $title
53
    */
54
    private $subtitle;
55
56
    /**
57
    * @var TranslationString $content
58
    */
59
    private $content;
60
61
    /**
62
    * @var array $contentStructure
63
    */
64
    private $contentStructure;
0 ignored issues
show
Unused Code introduced by
The property $contentStructure is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
65
66
    /**
67
    * @var DateTime $newsDate
68
    */
69
    private $newsDate;
70
71
    /**
72
    * @var TranslationString $image
73
    */
74
    private $image;
0 ignored issues
show
Unused Code introduced by
The property $image is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
75
76
    /**
77
    * @var Collection $documents
78
    */
79
    public $documents;
80
81
    /**
82
    * @var TranslationString $infoUrl
83
    */
84
    private $infoUrl;
85
86
    /**
87
    * CategorizableTrait > categoryType()
88
    *
89
    * @return string
90
    */
91
    public function categoryType()
92
    {
93
        return 'charcoal/cms/news-category';
94
    }
95
96
    /**
97
    * @param mixed $title
98
    * @return TranslationString
99
    */
100
    public function setTitle($title)
101
    {
102
        $this->title = new TranslationString($title);
103
        return $this;
104
    }
105
106
    /**
107
    * @return TranslationString
108
    */
109
    public function title()
110
    {
111
        return $this->title;
112
    }
113
114
    /**
115
    * @param mixed $subbtitle
0 ignored issues
show
Documentation introduced by
There is no parameter named $subbtitle. Did you maybe mean $subtitle?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
116
    * @return Event Chainable
117
    */
118
    public function setSubtitle($subtitle)
119
    {
120
        $this->subtitle = new TranslationString($subtitle);
121
        return $this;
122
    }
123
124
    /**
125
    * @return TranslationString
126
    */
127
    public function subtitle()
128
    {
129
        return $this->subtitle;
130
    }
131
132
    /**
133
    * @param mixed $content
134
    * @return Event Chainable
135
    */
136
    public function setContent($content)
137
    {
138
        $this->content = new TranslationString($content);
139
        return $this;
140
    }
141
142
    /**
143
    * @return TranslationString
144
    */
145
    public function content()
146
    {
147
        return $this->content;
148
    }
149
150
    /**
151
     * @param mixed $newsDate The news date.
152
     * @throws InvalidArgumentException If the timestamp is invalid.
153
     * @return ObjectRevision Chainable
154
     */
155
    public function setNewsDate($newsDate)
156
    {
157
        if ($newsDate === null) {
158
            $this->newsDate = null;
159
            return $this;
160
        }
161
        if (is_string($newsDate)) {
162
            $newsDate = new DateTime($newsDate);
163
        }
164
        if (!($newsDate instanceof DateTimeInterface)) {
165
            throw new InvalidArgumentException(
166
                'Invalid "Revision Date" value. Must be a date/time string or a DateTimeInterface object.'
167
            );
168
        }
169
        $this->newsDate = $newsDate;
170
        return $this;
171
    }
172
173
    /**
174
     * @return DateTime|null
175
     */
176
    public function newsDate()
177
    {
178
        return $this->newsDate;
179
    }
180
181
    public function setInfoUrl($url)
182
    {
183
        $this->infoUrl = new TranslationString($url);
184
        return $this;
185
    }
186
187
    public function infoUrl()
188
    {
189
        return $this->infoUrl;
190
    }
191
192
    /**
193
    * MetatagTrait > canonical_url
194
    *
195
    * @return string
196
    * @todo
197
    */
198
    public function canonicalUrl()
199
    {
200
        return '';
201
    }
202
203
    /**
204
    * RoutableInterface > handle_route()
205
    *
206
    * @param string $path
207
    * @param RequestInterface $request
208
    * @param ResponseInterface $response
209
    * @throws InvalidArgumentException
210
    * @return callable|null Route dispatcher
211
    */
212
    public function routeHandler($path, RequestInterface $request, ResponseInterface $response)
213
    {
214
        if (!is_string($path)) {
215
            throw new InvalidArgumentExeption(
216
                'Route path must be a string'
217
            );
218
        }
219
        $match_path = $path == 'xxx'; // Insert logic here...
220
        if($match_path) {
221
            return function(RequestInterface $request, ResponseInterface $response) use ($path) {
222
                $response->write($path);
223
            };
224
        }
225
        else {
226
            return null;
227
        }
228
    }
229
230
}
231