1 | <?php |
||
17 | abstract class FrontMatterDocument extends ReadableDocument implements \IteratorAggregate, \ArrayAccess |
||
18 | { |
||
19 | const TEMPLATE = "---\n%s\n---\n\n%s"; |
||
20 | |||
21 | /** @var array Functions that are white listed and can be called from templates. */ |
||
22 | public static $whiteListedFunctions = [ |
||
23 | 'getPermalink', 'getRedirects', 'getTargetFile', 'getContent', |
||
24 | 'getFilename', 'getBasename', 'getExtension', 'isDraft', |
||
25 | ]; |
||
26 | |||
27 | /** @var array FrontMatter keys that will be defined internally and cannot be overridden by users. */ |
||
28 | protected $specialFrontMatter = [ |
||
29 | 'filePath' => null, |
||
30 | ]; |
||
31 | |||
32 | protected $frontMatterEvaluated = false; |
||
33 | protected $bodyContentEvaluated = false; |
||
34 | |||
35 | /** @var FrontMatterParser */ |
||
36 | protected $frontMatterParser; |
||
37 | |||
38 | /** @var array FrontMatter that is read from user documents. */ |
||
39 | protected $frontMatter = []; |
||
40 | |||
41 | /** @var int The number of lines that Twig template errors should offset. */ |
||
42 | protected $lineOffset = 0; |
||
43 | |||
44 | /// |
||
45 | // Getter functions |
||
46 | /// |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 19 | public function getIterator() |
|
55 | |||
56 | /** |
||
57 | * Get the number of lines that are taken up by FrontMatter and whitespace. |
||
58 | * |
||
59 | * @return int |
||
60 | */ |
||
61 | 1 | public function getLineOffset() |
|
65 | |||
66 | /** |
||
67 | * Get whether or not this document is a draft. |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | 4 | public function isDraft() |
|
75 | |||
76 | /// |
||
77 | // FrontMatter functionality |
||
78 | /// |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | 119 | public function readContent() |
|
124 | |||
125 | /** |
||
126 | * Get the FrontMatter for this document. |
||
127 | * |
||
128 | * @param bool $evaluateYaml Whether or not to evaluate any variables. |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | 30 | final public function getFrontMatter($evaluateYaml = true) |
|
145 | |||
146 | /** |
||
147 | * Evaluate the FrontMatter in this object by merging a custom array of data. |
||
148 | * |
||
149 | * @param array|null $variables An array of YAML variables to use in evaluating the `$permalink` value |
||
150 | */ |
||
151 | 9 | final public function evaluateFrontMatter(array $variables = null) |
|
159 | |||
160 | /** |
||
161 | * Returns true when the evaluated Front Matter has expanded values embeded. |
||
162 | * |
||
163 | * @return bool |
||
164 | */ |
||
165 | 2 | final public function hasExpandedFrontMatter() |
|
169 | |||
170 | /** |
||
171 | * Evaluate an array of data for FrontMatter variables. This function will modify the array in place. |
||
172 | * |
||
173 | * @param array $yaml An array of data containing FrontMatter variables |
||
174 | * |
||
175 | * @see $specialFrontMatter |
||
176 | * |
||
177 | * @throws YamlVariableUndefinedException A FrontMatter variable used does not exist |
||
178 | */ |
||
179 | 31 | private function evaluateYaml(&$yaml) |
|
195 | |||
196 | /// |
||
197 | // ArrayAccess Implementation |
||
198 | /// |
||
199 | |||
200 | /** |
||
201 | * {@inheritdoc} |
||
202 | */ |
||
203 | public function offsetSet($offset, $value) |
||
207 | |||
208 | /** |
||
209 | * {@inheritdoc} |
||
210 | */ |
||
211 | 34 | public function offsetExists($offset) |
|
222 | |||
223 | /** |
||
224 | * {@inheritdoc} |
||
225 | */ |
||
226 | public function offsetUnset($offset) |
||
230 | |||
231 | /** |
||
232 | * {@inheritdoc} |
||
233 | */ |
||
234 | 47 | public function offsetGet($offset) |
|
255 | } |
||
256 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.