Completed
Push — chore/php-8-migration ( 0b97e4...588942 )
by Vladimir
09:24
created
src/Document/PermalinkFrontMatterDocument.php 1 patch
Braces   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,22 +21,27 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
src/Document/FrontMatterDocument.php 1 patch
Braces   +38 added lines, -18 removed lines patch added patch discarded remove patch
@@ -92,7 +92,8 @@  discard block
 block discarded – undo
92 92
      */
93 93
     final public function getFrontMatter($evaluateYaml = true): array
94 94
     {
95
-        if ($this->frontMatter === null) {
95
+        if ($this->frontMatter === null)
96
+        {
96 97
             throw new LogicException('FrontMatter has not been evaluated yet, be sure FrontMatterDocument::evaluateFrontMatter() is called before.');
97 98
         }
98 99
 
@@ -133,7 +134,8 @@  discard block
 block discarded – undo
133 134
      */
134 135
     public function offsetExists($offset): bool
135 136
     {
136
-        if (isset($this->frontMatter[$offset]) || isset($this->specialFrontMatter[$offset])) {
137
+        if (isset($this->frontMatter[$offset]) || isset($this->specialFrontMatter[$offset]))
138
+        {
137 139
             return true;
138 140
         }
139 141
 
@@ -155,17 +157,20 @@  discard block
 block discarded – undo
155 157
      */
156 158
     public function offsetGet($offset): mixed
157 159
     {
158
-        if (isset($this->specialFrontMatter[$offset])) {
160
+        if (isset($this->specialFrontMatter[$offset]))
161
+        {
159 162
             return $this->specialFrontMatter[$offset];
160 163
         }
161 164
 
162 165
         $fxnCall = 'get' . ucfirst((string)$offset);
163 166
 
164
-        if (in_array($fxnCall, self::$whiteListedFunctions) && method_exists($this, $fxnCall)) {
167
+        if (in_array($fxnCall, self::$whiteListedFunctions) && method_exists($this, $fxnCall))
168
+        {
165 169
             return call_user_func_array([$this, $fxnCall], []);
166 170
         }
167 171
 
168
-        if (isset($this->frontMatter[$offset])) {
172
+        if (isset($this->frontMatter[$offset]))
173
+        {
169 174
             return $this->frontMatter[$offset];
170 175
         }
171 176
 
@@ -181,12 +186,14 @@  discard block
 block discarded – undo
181 186
      */
182 187
     protected function beforeReadContents(): mixed
183 188
     {
184
-        if (!$this->file->exists()) {
189
+        if (!$this->file->exists())
190
+        {
185 191
             throw new FileNotFoundException(null, 0, null, $this->file->getAbsolutePath());
186 192
         }
187 193
 
188 194
         // If the "Last Modified" time is equal to what we have on record, then there's no need to read the file again
189
-        if ($this->metadata['last_modified'] === $this->file->getMTime()) {
195
+        if ($this->metadata['last_modified'] === $this->file->getMTime())
196
+        {
190 197
             return false;
191 198
         }
192 199
 
@@ -200,7 +207,8 @@  discard block
 block discarded – undo
200 207
      */
201 208
     protected function readContents($readNecessary): mixed
202 209
     {
203
-        if (!$readNecessary) {
210
+        if (!$readNecessary)
211
+        {
204 212
             return [];
205 213
         }
206 214
 
@@ -208,11 +216,13 @@  discard block
 block discarded – undo
208 216
         $rawFileContents = $this->file->getContents();
209 217
         preg_match('/---\R(.*?\R)?---(\s+)(.*)/s', (string)$rawFileContents, $fileStructure);
210 218
 
211
-        if (count($fileStructure) != 4) {
219
+        if (count($fileStructure) != 4)
220
+        {
212 221
             throw new InvalidSyntaxException('Invalid FrontMatter file', 0, null, $this->getRelativeFilePath());
213 222
         }
214 223
 
215
-        if (empty(trim((string)$fileStructure[3]))) {
224
+        if (empty(trim((string)$fileStructure[3])))
225
+        {
216 226
             throw new InvalidSyntaxException('FrontMatter files must have a body to render', 0, null, $this->getRelativeFilePath());
217 227
         }
218 228
 
@@ -225,7 +235,8 @@  discard block
 block discarded – undo
225 235
     protected function afterReadContents($fileStructure): void
226 236
     {
227 237
         // The file wasn't modified since our last read, so we can exit out quickly
228
-        if (empty($fileStructure)) {
238
+        if (empty($fileStructure))
239
+        {
229 240
             return;
230 241
         }
231 242
 
@@ -244,16 +255,21 @@  discard block
 block discarded – undo
244 255
 
245 256
         $fmHash = md5((string)$fileStructure[1]);
246 257
 
247
-        if ($this->metadata['fm_hash'] !== $fmHash) {
258
+        if ($this->metadata['fm_hash'] !== $fmHash)
259
+        {
248 260
             $this->metadata['fm_hash'] = $fmHash;
249 261
 
250
-            if (!empty(trim((string)$fileStructure[1]))) {
262
+            if (!empty(trim((string)$fileStructure[1])))
263
+            {
251 264
                 $this->rawFrontMatter = Yaml::parse($fileStructure[1], Yaml::PARSE_DATETIME);
252 265
 
253
-                if (!empty($this->rawFrontMatter) && !is_array($this->rawFrontMatter)) {
266
+                if (!empty($this->rawFrontMatter) && !is_array($this->rawFrontMatter))
267
+                {
254 268
                     throw new ParseException('The evaluated FrontMatter should be an array');
255 269
                 }
256
-            } else {
270
+            }
271
+            else
272
+            {
257 273
                 $this->rawFrontMatter = [];
258 274
             }
259 275
         }
@@ -264,7 +280,8 @@  discard block
 block discarded – undo
264 280
 
265 281
         $bodyHash = md5((string)$fileStructure[3]);
266 282
 
267
-        if ($this->metadata['body_sum'] !== $bodyHash) {
283
+        if ($this->metadata['body_sum'] !== $bodyHash)
284
+        {
268 285
             $this->metadata['body_sum'] = $bodyHash;
269 286
             $this->bodyContent = $fileStructure[3];
270 287
             $this->bodyContentEvaluated = false;
@@ -282,7 +299,8 @@  discard block
 block discarded – undo
282 299
      */
283 300
     private function evaluateYaml(array &$yaml, array $complexVariables = []): void
284 301
     {
285
-        try {
302
+        try
303
+        {
286 304
             // The second parameter for this parser must match the $specialFrontMatter structure
287 305
             $this->frontMatterParser = new FrontMatterParser($yaml, [
288 306
                 'basename' => $this->getBasename(),
@@ -291,7 +309,9 @@  discard block
 block discarded – undo
291 309
             ]);
292 310
             $this->frontMatterParser->addComplexVariables($complexVariables);
293 311
             $this->frontMatterParser->parse();
294
-        } catch (Exception $e) {
312
+        }
313
+        catch (Exception $e)
314
+        {
295 315
             throw FileAwareException::castException($e, $this->getRelativeFilePath());
296 316
         }
297 317
     }
Please login to merge, or discard this patch.
src/Document/PermalinkDocumentTrait.php 1 patch
Braces   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,14 +32,16 @@  discard block
 block discarded – undo
32 32
      */
33 33
     final public function getTargetFile($permalink = null): string
34 34
     {
35
-        if ($permalink === null) {
35
+        if ($permalink === null)
36
+        {
36 37
             $permalink = $this->getPermalink();
37 38
         }
38 39
 
39 40
         $missingFile = substr((string)$permalink, -1) == '/';
40 41
         $permalink = str_replace('/', DIRECTORY_SEPARATOR, (string)$permalink);
41 42
 
42
-        if ($missingFile) {
43
+        if ($missingFile)
44
+        {
43 45
             $permalink = rtrim($permalink, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'index.html';
44 46
         }
45 47
 
@@ -65,7 +67,8 @@  discard block
 block discarded – undo
65 67
      */
66 68
     final public function getRedirects(): array
67 69
     {
68
-        if ($this->redirects === null) {
70
+        if ($this->redirects === null)
71
+        {
69 72
             $this->getPermalink();
70 73
         }
71 74
 
@@ -85,14 +88,16 @@  discard block
 block discarded – undo
85 88
         $cleanPath = ltrim($cleanPath, DIRECTORY_SEPARATOR);
86 89
 
87 90
         // Handle vfs:// paths by replacing their forward slashes with the OS appropriate directory separator
88
-        if (DIRECTORY_SEPARATOR !== '/') {
91
+        if (DIRECTORY_SEPARATOR !== '/')
92
+        {
89 93
             $cleanPath = str_replace('/', DIRECTORY_SEPARATOR, $cleanPath);
90 94
         }
91 95
 
92 96
         // Check the first folder and see if it's a data folder (starts with an underscore) intended for stakx
93 97
         $folders = explode(DIRECTORY_SEPARATOR, $cleanPath);
94 98
 
95
-        if (str_starts_with($folders[0], '_')) {
99
+        if (str_starts_with($folders[0], '_'))
100
+        {
96 101
             array_shift($folders);
97 102
         }
98 103
 
@@ -117,7 +122,8 @@  discard block
 block discarded – undo
117 122
         // Remove all disallowed characters
118 123
         $permalink = preg_replace('/[^0-9a-zA-Z-_\/\\\.]/', '', $permalink);
119 124
 
120
-        if (in_array(fs::getExtension($permalink), self::$extensionsToStrip)) {
125
+        if (in_array(fs::getExtension($permalink), self::$extensionsToStrip))
126
+        {
121 127
             $permalink = fs::removeExtension($permalink);
122 128
         }
123 129
 
@@ -125,7 +131,8 @@  discard block
 block discarded – undo
125 131
         $permalink = preg_replace('/^[^0-9a-zA-Z-_]*/', '', $permalink);
126 132
 
127 133
         // Convert permalinks to lower case
128
-        if (!Service::hasRunTimeFlag(RuntimeStatus::COMPILER_PRESERVE_CASE)) {
134
+        if (!Service::hasRunTimeFlag(RuntimeStatus::COMPILER_PRESERVE_CASE))
135
+        {
129 136
             $permalink = mb_strtolower($permalink, 'UTF-8');
130 137
         }
131 138
 
Please login to merge, or discard this patch.
src/Document/DataItem.php 1 patch
Braces   +13 added lines, -6 removed lines patch added patch discarded remove patch
@@ -58,17 +58,21 @@  discard block
 block discarded – undo
58 58
         $parser->addComplexVariables($complexVariables);
59 59
         $parser->parse();
60 60
 
61
-        if (!is_null($parser) && $parser->hasExpansion()) {
61
+        if (!is_null($parser) && $parser->hasExpansion())
62
+        {
62 63
             throw new LogicException('The permalink for this item has not been set.');
63 64
         }
64 65
 
65 66
         $permalink = $this->frontMatter['permalink'];
66 67
 
67
-        if (is_array($permalink)) {
68
+        if (is_array($permalink))
69
+        {
68 70
             $this->permalink = $permalink[0];
69 71
             array_shift($permalink);
70 72
             $this->redirects = $permalink;
71
-        } else {
73
+        }
74
+        else
75
+        {
72 76
             $this->permalink = $permalink;
73 77
             $this->redirects = [];
74 78
         }
@@ -166,15 +170,18 @@  discard block
 block discarded – undo
166 170
     {
167 171
         $fxnCall = 'get' . ucfirst((string)$offset);
168 172
 
169
-        if (in_array($fxnCall, FrontMatterDocument::$whiteListedFunctions) && method_exists($this, $fxnCall)) {
173
+        if (in_array($fxnCall, FrontMatterDocument::$whiteListedFunctions) && method_exists($this, $fxnCall))
174
+        {
170 175
             return call_user_func_array([$this, $fxnCall], []);
171 176
         }
172 177
 
173
-        if (isset($this->data[$offset])) {
178
+        if (isset($this->data[$offset]))
179
+        {
174 180
             return $this->data[$offset];
175 181
         }
176 182
 
177
-        if (isset($this->frontMatter[$offset])) {
183
+        if (isset($this->frontMatter[$offset]))
184
+        {
178 185
             return $this->frontMatter[$offset];
179 186
         }
180 187
 
Please login to merge, or discard this patch.
src/Document/RepeaterPageView.php 1 patch
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,8 +33,10 @@
 block discarded – undo
33 33
      */
34 34
     public function _getPermalinkWhere(array $where): ?string
35 35
     {
36
-        foreach ($this->permalinks as $expandedValue) {
37
-            if ($expandedValue->getIterators() === $where) {
36
+        foreach ($this->permalinks as $expandedValue)
37
+        {
38
+            if ($expandedValue->getIterators() === $where)
39
+            {
38 40
                 return $expandedValue->getEvaluated();
39 41
             }
40 42
         }
Please login to merge, or discard this patch.
src/Document/TemplateEngineDependent.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,8 @@
 block discarded – undo
78 78
      */
79 79
     protected function parseTemplateLanguage($bodyContent): string
80 80
     {
81
-        if ($this->templateEngine !== null) {
81
+        if ($this->templateEngine !== null)
82
+        {
82 83
             $this->importDependencies = $this->templateEngine->getTemplateImportDependencies($bodyContent);
83 84
             $this->dataDependencies = [
84 85
                 'collections' => $this->templateEngine->getAssortmentDependencies('collections', $bodyContent),
Please login to merge, or discard this patch.
src/Document/BasePageView.php 1 patch
Braces   +11 added lines, -5 removed lines patch added patch discarded remove patch
@@ -55,7 +55,8 @@  discard block
 block discarded – undo
55 55
 
56 56
         $instance->evaluateFrontMatter([], $complexVariables);
57 57
 
58
-        if ($instance->hasExpandedFrontMatter()) {
58
+        if ($instance->hasExpandedFrontMatter())
59
+        {
59 60
             return new RepeaterPageView($filePath);
60 61
         }
61 62
 
@@ -74,7 +75,8 @@  discard block
 block discarded – undo
74 75
      */
75 76
     public static function createVirtual($frontMatter, $body): StaticPageView
76 77
     {
77
-        if (vfsStreamWrapper::getRoot() == null) {
78
+        if (vfsStreamWrapper::getRoot() == null)
79
+        {
78 80
             vfsStream::setup();
79 81
         }
80 82
 
@@ -108,12 +110,16 @@  discard block
 block discarded – undo
108 110
 
109 111
         $contentItemBody = fs::getInternalResource('redirect.html.twig');
110 112
 
111
-        try {
112
-            if (!empty($redirectTemplate)) {
113
+        try
114
+        {
115
+            if (!empty($redirectTemplate))
116
+            {
113 117
                 $redirectView = new File($redirectTemplate);
114 118
                 $contentItemBody = $redirectView->getContents();
115 119
             }
116
-        } catch (Exception $e) {
120
+        }
121
+        catch (Exception $e)
122
+        {
117 123
             trigger_error($e->getMessage(), E_USER_WARNING);
118 124
         }
119 125
 
Please login to merge, or discard this patch.
src/Document/ContentItem.php 1 patch
Braces   +8 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,10 +34,12 @@  discard block
 block discarded – undo
34 34
     {
35 35
         $fm = $this->getFrontMatter();
36 36
 
37
-        if (isset($fm['redirect_from'])) {
37
+        if (isset($fm['redirect_from']))
38
+        {
38 39
             $redirects = $fm['redirect_from'];
39 40
 
40
-            if (!is_array($redirects)) {
41
+            if (!is_array($redirects))
42
+            {
41 43
                 $redirects = [$redirects];
42 44
             }
43 45
 
@@ -54,10 +56,12 @@  discard block
 block discarded – undo
54 56
      */
55 57
     public function getContent(): string
56 58
     {
57
-        if (!$this->bodyContentEvaluated) {
59
+        if (!$this->bodyContentEvaluated)
60
+        {
58 61
             $this->bodyContent = $this->parseTemplateLanguage($this->bodyContent);
59 62
 
60
-            if ($this->markupEngine) {
63
+            if ($this->markupEngine)
64
+            {
61 65
                 $this->bodyContent = $this->markupEngine->parse($this->bodyContent, $this);
62 66
             }
63 67
 
Please login to merge, or discard this patch.
src/Filesystem/File.php 1 patch
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,13 +62,15 @@
 block discarded – undo
62 62
      */
63 63
     public function getContents(): string
64 64
     {
65
-        if (!$this->exists()) {
65
+        if (!$this->exists())
66
+        {
66 67
             throw $this->buildNotFoundException();
67 68
         }
68 69
 
69 70
         $content = file_get_contents($this->getAbsolutePath());
70 71
 
71
-        if ($content === false) {
72
+        if ($content === false)
73
+        {
72 74
             $error = error_get_last();
73 75
 
74 76
             throw new RuntimeException($error['message']);
Please login to merge, or discard this patch.