@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | // Utility functions |
406 | 406 | // |
407 | 407 | |
408 | - private function castDateTimeTimezone(int|string $epochTime): bool|DateTime |
|
408 | + private function castDateTimeTimezone(int | string $epochTime): bool | DateTime |
|
409 | 409 | { |
410 | 410 | $timezone = new DateTimeZone(date_default_timezone_get()); |
411 | 411 | $value = DateTime::createFromFormat('U', (string)$epochTime); |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | return $value; |
415 | 415 | } |
416 | 416 | |
417 | - private function guessDateTime(mixed $guess): bool|DateTime |
|
417 | + private function guessDateTime(mixed $guess): bool | DateTime |
|
418 | 418 | { |
419 | 419 | if ($guess instanceof DateTime) { |
420 | 420 | return $guess; |
@@ -179,14 +179,16 @@ discard block |
||
179 | 179 | */ |
180 | 180 | private function handleDateField(): void |
181 | 181 | { |
182 | - if (!isset($this->frontMatter['date'])) { |
|
182 | + if (!isset($this->frontMatter['date'])) |
|
183 | + { |
|
183 | 184 | return; |
184 | 185 | } |
185 | 186 | |
186 | 187 | $date = &$this->frontMatter['date']; |
187 | 188 | $itemDate = $this->guessDateTime($date); |
188 | 189 | |
189 | - if (!$itemDate === false) { |
|
190 | + if (!$itemDate === false) |
|
191 | + { |
|
190 | 192 | $this->frontMatter['date'] = $itemDate->format('U'); |
191 | 193 | $this->frontMatter['year'] = $itemDate->format('Y'); |
192 | 194 | $this->frontMatter['month'] = $itemDate->format('m'); |
@@ -207,17 +209,25 @@ discard block |
||
207 | 209 | { |
208 | 210 | ++$this->nestingLevel; |
209 | 211 | |
210 | - foreach ($yaml as $key => &$value) { |
|
212 | + foreach ($yaml as $key => &$value) |
|
213 | + { |
|
211 | 214 | $this->yamlKeys[$this->nestingLevel] = $key; |
212 | 215 | $keys = implode('.', $this->yamlKeys); |
213 | 216 | |
214 | - if (in_array($key, self::$expandableFields, true)) { |
|
217 | + if (in_array($key, self::$expandableFields, true)) |
|
218 | + { |
|
215 | 219 | $value = $this->evaluateExpandableField($keys, $value); |
216 | - } elseif (is_array($value)) { |
|
220 | + } |
|
221 | + elseif (is_array($value)) |
|
222 | + { |
|
217 | 223 | $this->evaluateBlock($value); |
218 | - } elseif (is_string($value)) { |
|
224 | + } |
|
225 | + elseif (is_string($value)) |
|
226 | + { |
|
219 | 227 | $value = $this->evaluateBasicType($keys, $value); |
220 | - } elseif ($value instanceof DateTime) { |
|
228 | + } |
|
229 | + elseif ($value instanceof DateTime) |
|
230 | + { |
|
221 | 231 | $value = $this->castDateTimeTimezone($value->format('U')); |
222 | 232 | } |
223 | 233 | } |
@@ -234,19 +244,22 @@ discard block |
||
234 | 244 | */ |
235 | 245 | private function evaluateExpandableField($key, $fmStatement): array |
236 | 246 | { |
237 | - if (!is_array($fmStatement)) { |
|
247 | + if (!is_array($fmStatement)) |
|
248 | + { |
|
238 | 249 | $fmStatement = [$fmStatement]; |
239 | 250 | } |
240 | 251 | |
241 | 252 | $wip = []; |
242 | 253 | |
243 | - foreach ($fmStatement as $statement) { |
|
254 | + foreach ($fmStatement as $statement) |
|
255 | + { |
|
244 | 256 | $value = $this->evaluateBasicType($key, $statement, true); |
245 | 257 | |
246 | 258 | // Only continue expansion if there are Front Matter variables remain in the string, this means there'll be |
247 | 259 | // Front Matter variables referencing arrays |
248 | 260 | $expandingVars = $this->findFrontMatterVariables($value); |
249 | - if (!empty($expandingVars)) { |
|
261 | + if (!empty($expandingVars)) |
|
262 | + { |
|
250 | 263 | $value = $this->evaluateArrayType($key, $value, $expandingVars); |
251 | 264 | } |
252 | 265 | |
@@ -267,23 +280,28 @@ discard block |
||
267 | 280 | */ |
268 | 281 | private function evaluateArrayType($frontMatterKey, $expandableValue, $arrayVariableNames): array |
269 | 282 | { |
270 | - if (!is_array($expandableValue)) { |
|
283 | + if (!is_array($expandableValue)) |
|
284 | + { |
|
271 | 285 | $expandableValue = [$expandableValue]; |
272 | 286 | } |
273 | 287 | |
274 | 288 | $this->expansionUsed = true; |
275 | 289 | |
276 | - foreach ($arrayVariableNames as $variable) { |
|
290 | + foreach ($arrayVariableNames as $variable) |
|
291 | + { |
|
277 | 292 | $variableValue = $this->getVariableValue($frontMatterKey, $variable); |
278 | 293 | |
279 | - if (ArrayUtilities::is_multidimensional($variableValue)) { |
|
294 | + if (ArrayUtilities::is_multidimensional($variableValue)) |
|
295 | + { |
|
280 | 296 | throw new YamlUnsupportedVariableException("Yaml array expansion is not supported with multidimensional arrays with `{$variable}` for key `{$frontMatterKey}`"); |
281 | 297 | } |
282 | 298 | |
283 | 299 | $wip = []; |
284 | 300 | |
285 | - foreach ($expandableValue as &$statement) { |
|
286 | - foreach ($variableValue as $value) { |
|
301 | + foreach ($expandableValue as &$statement) |
|
302 | + { |
|
303 | + foreach ($variableValue as $value) |
|
304 | + { |
|
287 | 305 | $evaluatedValue = ($statement instanceof ExpandedValue) ? clone $statement : new ExpandedValue($statement); |
288 | 306 | |
289 | 307 | $varTemplate = $this->getVariableTemplate($variable); |
@@ -317,11 +335,14 @@ discard block |
||
317 | 335 | { |
318 | 336 | $variables = $this->findFrontMatterVariables($string); |
319 | 337 | |
320 | - foreach ($variables as $variable) { |
|
338 | + foreach ($variables as $variable) |
|
339 | + { |
|
321 | 340 | $value = $this->getVariableValue($key, $variable); |
322 | 341 | |
323 | - if (is_array($value) || is_bool($value)) { |
|
324 | - if ($ignoreArrays) { |
|
342 | + if (is_array($value) || is_bool($value)) |
|
343 | + { |
|
344 | + if ($ignoreArrays) |
|
345 | + { |
|
325 | 346 | continue; |
326 | 347 | } |
327 | 348 | |
@@ -373,13 +394,17 @@ discard block |
||
373 | 394 | $isPrimitive = !str_contains($varName, '.'); |
374 | 395 | $variableVal = null; |
375 | 396 | |
376 | - if ($isPrimitive) { |
|
397 | + if ($isPrimitive) |
|
398 | + { |
|
377 | 399 | $variableVal = __::get($this->frontMatter, $varName); |
378 | - } else { |
|
400 | + } |
|
401 | + else |
|
402 | + { |
|
379 | 403 | $variableVal = __::get($this->complexVariables, $varName); |
380 | 404 | } |
381 | 405 | |
382 | - if ($variableVal === null) { |
|
406 | + if ($variableVal === null) |
|
407 | + { |
|
383 | 408 | throw new YamlVariableUndefinedException("Yaml variable `{$varName}` is not defined for: {$key}"); |
384 | 409 | } |
385 | 410 | |
@@ -416,16 +441,21 @@ discard block |
||
416 | 441 | |
417 | 442 | private function guessDateTime(mixed $guess): bool|DateTime |
418 | 443 | { |
419 | - if ($guess instanceof DateTime) { |
|
444 | + if ($guess instanceof DateTime) |
|
445 | + { |
|
420 | 446 | return $guess; |
421 | 447 | } |
422 | - if (is_numeric($guess)) { |
|
448 | + if (is_numeric($guess)) |
|
449 | + { |
|
423 | 450 | return $this->castDateTimeTimezone($guess); |
424 | 451 | } |
425 | 452 | |
426 | - try { |
|
453 | + try |
|
454 | + { |
|
427 | 455 | return new DateTime($guess); |
428 | - } catch (Exception) { |
|
456 | + } |
|
457 | + catch (Exception) |
|
458 | + { |
|
429 | 459 | return false; |
430 | 460 | } |
431 | 461 | } |
@@ -47,7 +47,8 @@ |
||
47 | 47 | |
48 | 48 | public static function getWorkingDirectory() |
49 | 49 | { |
50 | - if (!self::$workingDirectory) { |
|
50 | + if (!self::$workingDirectory) |
|
51 | + { |
|
51 | 52 | return getcwd(); |
52 | 53 | } |
53 | 54 |
@@ -35,15 +35,18 @@ discard block |
||
35 | 35 | { |
36 | 36 | $langDef = $this->parseInfoString($infoString); |
37 | 37 | |
38 | - try { |
|
38 | + try |
|
39 | + { |
|
39 | 40 | $highlighted = $this->highlighter->highlight($langDef['language'], $rawCode); |
40 | 41 | $value = $highlighted->value; |
41 | 42 | |
42 | - if (Service::hasRunTimeFlag(RuntimeStatus::USING_LINE_NUMBERS) || count($langDef['selectedLines']) > 0) { |
|
43 | + if (Service::hasRunTimeFlag(RuntimeStatus::USING_LINE_NUMBERS) || count($langDef['selectedLines']) > 0) |
|
44 | + { |
|
43 | 45 | $lines = splitCodeIntoArray($value); |
44 | 46 | $value = ''; |
45 | 47 | |
46 | - foreach ($lines as $i => $line) { |
|
48 | + foreach ($lines as $i => $line) |
|
49 | + { |
|
47 | 50 | // `$i + 1` since our line numbers are indexed starting at 1 |
48 | 51 | $value .= vsprintf("<div class=\"loc%s\"><span>%s</span></div>\n", [ |
49 | 52 | isset($langDef['selectedLines'][$i + 1]) ? ' highlighted' : '', |
@@ -58,9 +61,12 @@ discard block |
||
58 | 61 | ]); |
59 | 62 | } |
60 | 63 | // Exception thrown when language not supported |
61 | - catch (DomainException) { |
|
64 | + catch (DomainException) |
|
65 | + { |
|
62 | 66 | trigger_error("An unsupported language (${langDef['language']}) was detected in a code block", E_USER_WARNING); |
63 | - } catch (Exception) { |
|
67 | + } |
|
68 | + catch (Exception) |
|
69 | + { |
|
64 | 70 | trigger_error('An error has occurred in the highlight.php language definition files', E_USER_WARNING); |
65 | 71 | } |
66 | 72 | |
@@ -82,7 +88,8 @@ discard block |
||
82 | 88 | |
83 | 89 | $bracePos = strpos($infoString, '{'); |
84 | 90 | |
85 | - if ($bracePos === false) { |
|
91 | + if ($bracePos === false) |
|
92 | + { |
|
86 | 93 | return $definition; |
87 | 94 | } |
88 | 95 | |
@@ -90,8 +97,10 @@ discard block |
||
90 | 97 | $lineDefinition = substr($infoString, $bracePos + 1, -1); |
91 | 98 | $lineNumbers = explode(',', $lineDefinition); |
92 | 99 | |
93 | - foreach ($lineNumbers as $lineNumber) { |
|
94 | - if (!str_contains($lineNumber, '-')) { |
|
100 | + foreach ($lineNumbers as $lineNumber) |
|
101 | + { |
|
102 | + if (!str_contains($lineNumber, '-')) |
|
103 | + { |
|
95 | 104 | $definition['selectedLines'][intval($lineNumber)] = true; |
96 | 105 | |
97 | 106 | continue; |
@@ -99,14 +108,16 @@ discard block |
||
99 | 108 | |
100 | 109 | $extremes = explode('-', $lineNumber); |
101 | 110 | |
102 | - if (count($extremes) !== 2) { |
|
111 | + if (count($extremes) !== 2) |
|
112 | + { |
|
103 | 113 | continue; |
104 | 114 | } |
105 | 115 | |
106 | 116 | $start = intval($extremes[0]); |
107 | 117 | $end = intval($extremes[1]); |
108 | 118 | |
109 | - for ($i = $start; $i <= $end; ++$i) { |
|
119 | + for ($i = $start; $i <= $end; ++$i) |
|
120 | + { |
|
110 | 121 | $definition['selectedLines'][$i] = true; |
111 | 122 | } |
112 | 123 | } |
@@ -59,7 +59,7 @@ |
||
59 | 59 | } |
60 | 60 | // Exception thrown when language not supported |
61 | 61 | catch (DomainException) { |
62 | - trigger_error("An unsupported language (${langDef['language']}) was detected in a code block", E_USER_WARNING); |
|
62 | + trigger_error("An unsupported language (${langdef['language']}) was detected in a code block", E_USER_WARNING); |
|
63 | 63 | } catch (Exception) { |
64 | 64 | trigger_error('An error has occurred in the highlight.php language definition files', E_USER_WARNING); |
65 | 65 | } |
@@ -30,7 +30,8 @@ |
||
30 | 30 | */ |
31 | 31 | protected function registerAsset(string $path): void |
32 | 32 | { |
33 | - if ($this->isValidURL($path)) { |
|
33 | + if ($this->isValidURL($path)) |
|
34 | + { |
|
34 | 35 | return; |
35 | 36 | } |
36 | 37 |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function createJail(): JailedDocument |
36 | 36 | { |
37 | - if ($this->jailInstance === null) { |
|
37 | + if ($this->jailInstance === null) |
|
38 | + { |
|
38 | 39 | $whiteListedFunctions = array_merge(self::$whiteListedFunctions, [ |
39 | 40 | ]); |
40 | 41 | |
@@ -68,10 +69,12 @@ discard block |
||
68 | 69 | */ |
69 | 70 | public function getJailedChildren(): array |
70 | 71 | { |
71 | - if ($this->jailedChildPageViews === null) { |
|
72 | + if ($this->jailedChildPageViews === null) |
|
73 | + { |
|
72 | 74 | $this->jailedChildPageViews = []; |
73 | 75 | |
74 | - foreach ($this->childPageViews as $key => &$child) { |
|
76 | + foreach ($this->childPageViews as $key => &$child) |
|
77 | + { |
|
75 | 78 | $this->jailedChildPageViews[$key] = $child->createJail(); |
76 | 79 | } |
77 | 80 | } |
@@ -58,7 +58,8 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function &getCollectableItem($relativeFilePath) |
60 | 60 | { |
61 | - if (!$this->hasCollectableItem($relativeFilePath)) { |
|
61 | + if (!$this->hasCollectableItem($relativeFilePath)) |
|
62 | + { |
|
62 | 63 | return null; |
63 | 64 | } |
64 | 65 | |
@@ -92,7 +93,8 @@ discard block |
||
92 | 93 | { |
93 | 94 | $fm = $this->getRawFrontMatter(); |
94 | 95 | |
95 | - if (isset($fm['collection'])) { |
|
96 | + if (isset($fm['collection'])) |
|
97 | + { |
|
96 | 98 | return $fm['collection']; |
97 | 99 | } |
98 | 100 |
@@ -36,7 +36,8 @@ discard block |
||
36 | 36 | { |
37 | 37 | $this->metadata = new NullableArray(); |
38 | 38 | |
39 | - if (!$this->noReadOnConstructor) { |
|
39 | + if (!$this->noReadOnConstructor) |
|
40 | + { |
|
40 | 41 | $this->readContent(); |
41 | 42 | } |
42 | 43 | } |
@@ -69,7 +70,8 @@ discard block |
||
69 | 70 | */ |
70 | 71 | final public function compile(): void |
71 | 72 | { |
72 | - if ($this->compiled) { |
|
73 | + if ($this->compiled) |
|
74 | + { |
|
73 | 75 | return; |
74 | 76 | } |
75 | 77 |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @param string[] $whiteListFunctions a list of function names that can be called |
33 | 33 | * @param string[] $jailedFunctions a list of functions that will be redirected to another function |
34 | 34 | */ |
35 | - public function __construct(TemplateReadyDocument &$object, private readonly array $whiteListFunctions, private array $jailedFunctions = []) |
|
35 | + public function __construct(TemplateReadyDocument & $object, private readonly array $whiteListFunctions, private array $jailedFunctions = []) |
|
36 | 36 | { |
37 | 37 | $this->object = &$object; |
38 | 38 | $this->debugInfo = []; |
@@ -47,12 +47,14 @@ discard block |
||
47 | 47 | |
48 | 48 | // Check if our function call is a jailed call, meaning the function should be mapped to special "jailed" |
49 | 49 | // jailed version of the function call. |
50 | - if (array_key_exists($getFxnCall, $this->jailedFunctions)) { |
|
50 | + if (array_key_exists($getFxnCall, $this->jailedFunctions)) |
|
51 | + { |
|
51 | 52 | return call_user_func_array([$this->object, $this->jailedFunctions[$getFxnCall]], $arguments); |
52 | 53 | } |
53 | 54 | |
54 | 55 | // Otherwise, test to see if the function call is in our white list and call it |
55 | - if (in_array($getFxnCall, $this->whiteListFunctions)) { |
|
56 | + if (in_array($getFxnCall, $this->whiteListFunctions)) |
|
57 | + { |
|
56 | 58 | return call_user_func_array([$this->object, $getFxnCall], $arguments); |
57 | 59 | } |
58 | 60 | |
@@ -61,21 +63,27 @@ discard block |
||
61 | 63 | |
62 | 64 | public function __debugInfo() |
63 | 65 | { |
64 | - if (!empty($this->debugInfo)) { |
|
66 | + if (!empty($this->debugInfo)) |
|
67 | + { |
|
65 | 68 | return $this->debugInfo; |
66 | 69 | } |
67 | 70 | |
68 | - if ($this->object instanceof FrontMatterDocument) { |
|
71 | + if ($this->object instanceof FrontMatterDocument) |
|
72 | + { |
|
69 | 73 | $this->debugInfo = $this->object->getFrontMatter(true); |
70 | 74 | } |
71 | 75 | |
72 | - foreach ($this->whiteListFunctions as $function) { |
|
76 | + foreach ($this->whiteListFunctions as $function) |
|
77 | + { |
|
73 | 78 | $value = preg_replace('/^(get|is)/', '', $function); |
74 | 79 | $value = lcfirst($value); |
75 | 80 | |
76 | - try { |
|
81 | + try |
|
82 | + { |
|
77 | 83 | $this->debugInfo[$value] = call_user_func([$this, $function]); |
78 | - } catch (BadMethodCallException) { |
|
84 | + } |
|
85 | + catch (BadMethodCallException) |
|
86 | + { |
|
79 | 87 | // Just throw away this information because there's no point in listing an accessible value in this |
80 | 88 | // object that doesn't actually exist. |
81 | 89 | } |
@@ -21,22 +21,27 @@ |
||
21 | 21 | */ |
22 | 22 | public function buildPermalink($force = false): void |
23 | 23 | { |
24 | - if ($this->permalink !== null && !$force) { |
|
24 | + if ($this->permalink !== null && !$force) |
|
25 | + { |
|
25 | 26 | return; |
26 | 27 | } |
27 | 28 | |
28 | - if ($this->frontMatterParser !== null && $this->frontMatterParser->hasExpansion()) { |
|
29 | + if ($this->frontMatterParser !== null && $this->frontMatterParser->hasExpansion()) |
|
30 | + { |
|
29 | 31 | throw new Exception('The permalink for this item has not been set'); |
30 | 32 | } |
31 | 33 | |
32 | 34 | $permalink = (is_array($this->frontMatter) && isset($this->frontMatter['permalink'])) ? |
33 | 35 | $this->frontMatter['permalink'] : $this->getPathPermalink(); |
34 | 36 | |
35 | - if (is_array($permalink)) { |
|
37 | + if (is_array($permalink)) |
|
38 | + { |
|
36 | 39 | $this->permalink = $permalink[0]; |
37 | 40 | array_shift($permalink); |
38 | 41 | $this->redirects = $permalink; |
39 | - } else { |
|
42 | + } |
|
43 | + else |
|
44 | + { |
|
40 | 45 | $this->permalink = $permalink; |
41 | 46 | $this->redirects = []; |
42 | 47 | } |