@@ -65,7 +65,8 @@ discard block |
||
| 65 | 65 | { |
| 66 | 66 | $Block = parent::blockHeader($Line); |
| 67 | 67 | |
| 68 | - if (isset($Block['element']['text'])) { |
|
| 68 | + if (isset($Block['element']['text'])) |
|
| 69 | + { |
|
| 69 | 70 | $Block['element']['attributes']['id'] = $this->slugifyHeader($Block); |
| 70 | 71 | } |
| 71 | 72 | |
@@ -79,10 +80,12 @@ discard block |
||
| 79 | 80 | // https://github.com/erusev/parsedown-extra/issues/134 |
| 80 | 81 | $Block = @parent::blockSetextHeader($Line, $Block); |
| 81 | 82 | |
| 82 | - if (isset($Block['element']['name'])) { |
|
| 83 | + if (isset($Block['element']['name'])) |
|
| 84 | + { |
|
| 83 | 85 | $element = $Block['element']['name']; |
| 84 | 86 | |
| 85 | - if (in_array($element, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'])) { |
|
| 87 | + if (in_array($element, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'])) |
|
| 88 | + { |
|
| 86 | 89 | $Block['element']['attributes']['id'] = $this->slugifyHeader($Block); |
| 87 | 90 | } |
| 88 | 91 | } |
@@ -93,7 +96,8 @@ discard block |
||
| 93 | 96 | protected function blockFencedCodeComplete($block) |
| 94 | 97 | { |
| 95 | 98 | // The class has a `language-` prefix, remove this to get the language |
| 96 | - if (isset($block['element']['text']['attributes']) && Service::hasRunTimeFlag(RuntimeStatus::USING_HIGHLIGHTER)) { |
|
| 99 | + if (isset($block['element']['text']['attributes']) && Service::hasRunTimeFlag(RuntimeStatus::USING_HIGHLIGHTER)) |
|
| 100 | + { |
|
| 97 | 101 | $cssClass = $block['element']['text']['attributes']['class']; |
| 98 | 102 | $block['markup'] = $this->highlightCode($cssClass, $block['element']['text']['text']); |
| 99 | 103 | |
@@ -107,7 +111,8 @@ discard block |
||
| 107 | 111 | { |
| 108 | 112 | $imageBlock = parent::inlineImage($Excerpt); |
| 109 | 113 | |
| 110 | - if ($imageBlock !== null) { |
|
| 114 | + if ($imageBlock !== null) |
|
| 115 | + { |
|
| 111 | 116 | $imageSrc = trim((string)$imageBlock['element']['attributes']['src']); |
| 112 | 117 | |
| 113 | 118 | $this->registerAsset($imageSrc); |
@@ -18,7 +18,8 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | public function addMarkupEngines(/* iterable */ $markupEngines): void |
| 20 | 20 | { |
| 21 | - foreach ($markupEngines as $markupEngine) { |
|
| 21 | + foreach ($markupEngines as $markupEngine) |
|
| 22 | + { |
|
| 22 | 23 | $this->addMarkupEngine($markupEngine); |
| 23 | 24 | } |
| 24 | 25 | } |
@@ -28,10 +29,14 @@ discard block |
||
| 28 | 29 | $extensions = $markupEngine->getExtensions(); |
| 29 | 30 | $primaryExt = __::first($extensions); |
| 30 | 31 | |
| 31 | - foreach ($extensions as $k => $extension) { |
|
| 32 | - if ($k === 0) { |
|
| 32 | + foreach ($extensions as $k => $extension) |
|
| 33 | + { |
|
| 34 | + if ($k === 0) |
|
| 35 | + { |
|
| 33 | 36 | $this->enginesByExtension[$extension] = $markupEngine; |
| 34 | - } else { |
|
| 37 | + } |
|
| 38 | + else |
|
| 39 | + { |
|
| 35 | 40 | $this->enginesByExtension[$extension] = &$this->enginesByExtension[$primaryExt]; |
| 36 | 41 | } |
| 37 | 42 | } |
@@ -41,7 +46,8 @@ discard block |
||
| 41 | 46 | |
| 42 | 47 | public function getEngineByTag($tag) |
| 43 | 48 | { |
| 44 | - if (isset($this->enginesByTags[$tag])) { |
|
| 49 | + if (isset($this->enginesByTags[$tag])) |
|
| 50 | + { |
|
| 45 | 51 | return $this->enginesByTags[$tag]; |
| 46 | 52 | } |
| 47 | 53 | |
@@ -50,7 +56,8 @@ discard block |
||
| 50 | 56 | |
| 51 | 57 | public function getEngineByExtension($extension) |
| 52 | 58 | { |
| 53 | - if (isset($this->enginesByExtension[$extension])) { |
|
| 59 | + if (isset($this->enginesByExtension[$extension])) |
|
| 60 | + { |
|
| 54 | 61 | return $this->enginesByExtension[$extension]; |
| 55 | 62 | } |
| 56 | 63 | |
@@ -171,7 +171,7 @@ |
||
| 171 | 171 | return __::get($this->configuration, 'twig.autoescape'); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - public function getRedirectTemplate(): false|string |
|
| 174 | + public function getRedirectTemplate(): false | string |
|
| 175 | 175 | { |
| 176 | 176 | return __::get($this->configuration, 'templates.redirect'); |
| 177 | 177 | } |
@@ -210,18 +210,21 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | private function parseConfig(File $configFile = null): array |
| 212 | 212 | { |
| 213 | - if ($configFile === null) { |
|
| 213 | + if ($configFile === null) |
|
| 214 | + { |
|
| 214 | 215 | return []; |
| 215 | 216 | } |
| 216 | 217 | |
| 217 | 218 | $this->currentFile = $configFile; |
| 218 | 219 | |
| 219 | - try { |
|
| 220 | + try |
|
| 221 | + { |
|
| 220 | 222 | $this->isRecursiveImport($configFile); |
| 221 | 223 | |
| 222 | 224 | $parsedConfig = Yaml::parse($configFile->getContents()); |
| 223 | 225 | |
| 224 | - if ($parsedConfig === null) { |
|
| 226 | + if ($parsedConfig === null) |
|
| 227 | + { |
|
| 225 | 228 | $parsedConfig = []; |
| 226 | 229 | } |
| 227 | 230 | |
@@ -230,13 +233,17 @@ discard block |
||
| 230 | 233 | unset($parsedConfig[self::IMPORT_KEYWORD]); |
| 231 | 234 | |
| 232 | 235 | return $parsedConfig; |
| 233 | - } catch (ParseException $e) { |
|
| 236 | + } |
|
| 237 | + catch (ParseException $e) |
|
| 238 | + { |
|
| 234 | 239 | $this->logger->error('{file}: parsing failed... {message}', [ |
| 235 | 240 | 'message' => $e->getMessage(), |
| 236 | 241 | 'file' => $configFile, |
| 237 | 242 | ]); |
| 238 | 243 | $this->logger->error('Using default configuration...'); |
| 239 | - } catch (RecursiveConfigurationException $e) { |
|
| 244 | + } |
|
| 245 | + catch (RecursiveConfigurationException $e) |
|
| 246 | + { |
|
| 240 | 247 | $this->logger->error("{file}: you can't recursively import a file that's already been imported: {import}", [ |
| 241 | 248 | 'file' => $configFile, |
| 242 | 249 | 'import' => $e->getRecursiveImport(), |
@@ -297,7 +304,8 @@ discard block |
||
| 297 | 304 | */ |
| 298 | 305 | private function handleImports(array &$configuration): void |
| 299 | 306 | { |
| 300 | - if (!isset($configuration[self::IMPORT_KEYWORD])) { |
|
| 307 | + if (!isset($configuration[self::IMPORT_KEYWORD])) |
|
| 308 | + { |
|
| 301 | 309 | $this->logger->debug('{file}: does not import any other files', [ |
| 302 | 310 | 'file' => $this->currentFile->getRelativeFilePath(), |
| 303 | 311 | ]); |
@@ -305,13 +313,15 @@ discard block |
||
| 305 | 313 | return; |
| 306 | 314 | } |
| 307 | 315 | |
| 308 | - if (!is_array($imports = $configuration[self::IMPORT_KEYWORD])) { |
|
| 316 | + if (!is_array($imports = $configuration[self::IMPORT_KEYWORD])) |
|
| 317 | + { |
|
| 309 | 318 | $this->logger->error('{file}: the reserved "import" keyword can only be an array'); |
| 310 | 319 | |
| 311 | 320 | return; |
| 312 | 321 | } |
| 313 | 322 | |
| 314 | - foreach ($imports as $import) { |
|
| 323 | + foreach ($imports as $import) |
|
| 324 | + { |
|
| 315 | 325 | $this->handleImport($import, $configuration); |
| 316 | 326 | } |
| 317 | 327 | } |
@@ -325,7 +335,8 @@ discard block |
||
| 325 | 335 | */ |
| 326 | 336 | private function handleImport($importDef, array &$configuration): void |
| 327 | 337 | { |
| 328 | - if (!is_string($importDef)) { |
|
| 338 | + if (!is_string($importDef)) |
|
| 339 | + { |
|
| 329 | 340 | $this->logger->error('{file}: invalid import: {message}', [ |
| 330 | 341 | 'file' => $this->configFile->getRelativeFilePath(), |
| 331 | 342 | 'message' => $importDef, |
@@ -336,7 +347,8 @@ discard block |
||
| 336 | 347 | |
| 337 | 348 | $import = $this->configFile->createFileForRelativePath($importDef); |
| 338 | 349 | |
| 339 | - if (!$this->isValidImport($import)) { |
|
| 350 | + if (!$this->isValidImport($import)) |
|
| 351 | + { |
|
| 340 | 352 | return; |
| 341 | 353 | } |
| 342 | 354 | |
@@ -345,10 +357,13 @@ discard block |
||
| 345 | 357 | 'import' => $import->getRelativeFilePath(), |
| 346 | 358 | ]); |
| 347 | 359 | |
| 348 | - try { |
|
| 360 | + try |
|
| 361 | + { |
|
| 349 | 362 | $importedConfig = $this->parseConfig($import); |
| 350 | 363 | $configuration = $this->mergeImports($importedConfig, $configuration); |
| 351 | - } catch (FileNotFoundException) { |
|
| 364 | + } |
|
| 365 | + catch (FileNotFoundException) |
|
| 366 | + { |
|
| 352 | 367 | $this->logger->warning('{file}: could not find file to import: {import}', [ |
| 353 | 368 | 'file' => $this->configFile->getRelativeFilePath(), |
| 354 | 369 | 'import' => $import, |
@@ -363,17 +378,25 @@ discard block |
||
| 363 | 378 | { |
| 364 | 379 | $errorMsg = ''; |
| 365 | 380 | |
| 366 | - if ($filePath->isDir()) { |
|
| 381 | + if ($filePath->isDir()) |
|
| 382 | + { |
|
| 367 | 383 | $errorMsg = 'a directory'; |
| 368 | - } elseif ($filePath->isLink()) { |
|
| 384 | + } |
|
| 385 | + elseif ($filePath->isLink()) |
|
| 386 | + { |
|
| 369 | 387 | $errorMsg = 'a symbolically linked file'; |
| 370 | - } elseif ($this->currentFile->getAbsolutePath() == $filePath->getAbsolutePath()) { |
|
| 388 | + } |
|
| 389 | + elseif ($this->currentFile->getAbsolutePath() == $filePath->getAbsolutePath()) |
|
| 390 | + { |
|
| 371 | 391 | $errorMsg = 'yourself'; |
| 372 | - } elseif (($ext = $filePath->getExtension()) != 'yml' && $ext != 'yaml') { |
|
| 392 | + } |
|
| 393 | + elseif (($ext = $filePath->getExtension()) != 'yml' && $ext != 'yaml') |
|
| 394 | + { |
|
| 373 | 395 | $errorMsg = 'a non-YAML configuration'; |
| 374 | 396 | } |
| 375 | 397 | |
| 376 | - if (!($noErrors = empty($errorMsg))) { |
|
| 398 | + if (!($noErrors = empty($errorMsg))) |
|
| 399 | + { |
|
| 377 | 400 | $this->logger->error("{file}: you can't import {message}: {import}", [ |
| 378 | 401 | 'file' => $this->configFile->getRelativeFilePath(), |
| 379 | 402 | 'message' => $errorMsg, |
@@ -389,7 +412,8 @@ discard block |
||
| 389 | 412 | */ |
| 390 | 413 | private function isRecursiveImport(File $filePath): void |
| 391 | 414 | { |
| 392 | - if (in_array($filePath->getRelativeFilePath(), self::$configImports)) { |
|
| 415 | + if (in_array($filePath->getRelativeFilePath(), self::$configImports)) |
|
| 416 | + { |
|
| 393 | 417 | throw new RecursiveConfigurationException($filePath, sprintf( |
| 394 | 418 | 'The %s file has already been imported', |
| 395 | 419 | $filePath->getRelativeFilePath() |
@@ -412,11 +436,13 @@ discard block |
||
| 412 | 436 | |
| 413 | 437 | private function handleDefaultOperations(): void |
| 414 | 438 | { |
| 415 | - if (substr($this->getTargetFolder(), 0, 1) != '_') { |
|
| 439 | + if (substr($this->getTargetFolder(), 0, 1) != '_') |
|
| 440 | + { |
|
| 416 | 441 | $this->configuration['exclude'][] = $this->getTargetFolder(); |
| 417 | 442 | } |
| 418 | 443 | |
| 419 | - if ($this->configuration['build']['preserveCase']) { |
|
| 444 | + if ($this->configuration['build']['preserveCase']) |
|
| 445 | + { |
|
| 420 | 446 | Service::setRuntimeFlag(RuntimeStatus::COMPILER_PRESERVE_CASE); |
| 421 | 447 | } |
| 422 | 448 | } |
@@ -18,7 +18,8 @@ |
||
| 18 | 18 | $columns = array_shift($rows); |
| 19 | 19 | $csv = []; |
| 20 | 20 | |
| 21 | - foreach ($rows as $row) { |
|
| 21 | + foreach ($rows as $row) |
|
| 22 | + { |
|
| 22 | 23 | $csv[] = array_combine($columns, $row); |
| 23 | 24 | } |
| 24 | 25 | |
@@ -16,14 +16,16 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | public static function transformData($content): array |
| 18 | 18 | { |
| 19 | - if (!function_exists('simplexml_load_string')) { |
|
| 19 | + if (!function_exists('simplexml_load_string')) |
|
| 20 | + { |
|
| 20 | 21 | throw new DependencyMissingException('XML', 'XML support is not available with the current PHP installation.'); |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | 24 | libxml_use_internal_errors(true); |
| 24 | 25 | $data = json_decode(json_encode(simplexml_load_string($content), JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR); |
| 25 | 26 | |
| 26 | - if ($data === false || $data === null) { |
|
| 27 | + if ($data === false || $data === null) |
|
| 28 | + { |
|
| 27 | 29 | return []; |
| 28 | 30 | } |
| 29 | 31 | |
@@ -17,13 +17,17 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | public static function transformData($content): array |
| 19 | 19 | { |
| 20 | - try { |
|
| 20 | + try |
|
| 21 | + { |
|
| 21 | 22 | $data = Yaml::parse($content, Yaml::PARSE_DATETIME); |
| 22 | - } catch (Exception) { |
|
| 23 | + } |
|
| 24 | + catch (Exception) |
|
| 25 | + { |
|
| 23 | 26 | return []; |
| 24 | 27 | } |
| 25 | 28 | |
| 26 | - if ($data === null) { |
|
| 29 | + if ($data === null) |
|
| 30 | + { |
|
| 27 | 31 | return []; |
| 28 | 32 | } |
| 29 | 33 | |
@@ -20,21 +20,24 @@ |
||
| 20 | 20 | |
| 21 | 21 | public function addDataTransformers(/* iterable */ $dataTransformers): void |
| 22 | 22 | { |
| 23 | - foreach ($dataTransformers as $dataTransformer) { |
|
| 23 | + foreach ($dataTransformers as $dataTransformer) |
|
| 24 | + { |
|
| 24 | 25 | $this->addDataTransformer($dataTransformer); |
| 25 | 26 | } |
| 26 | 27 | } |
| 27 | 28 | |
| 28 | 29 | public function addDataTransformer(DataTransformerInterface $transformer): void |
| 29 | 30 | { |
| 30 | - foreach ($transformer->getExtensions() as $extension) { |
|
| 31 | + foreach ($transformer->getExtensions() as $extension) |
|
| 32 | + { |
|
| 31 | 33 | $this->transformers[$extension] = $transformer; |
| 32 | 34 | } |
| 33 | 35 | } |
| 34 | 36 | |
| 35 | 37 | public function getTransformer($extension) |
| 36 | 38 | { |
| 37 | - if (isset($this->transformers[$extension])) { |
|
| 39 | + if (isset($this->transformers[$extension])) |
|
| 40 | + { |
|
| 38 | 41 | return $this->transformers[$extension]; |
| 39 | 42 | } |
| 40 | 43 | |
@@ -16,7 +16,8 @@ |
||
| 16 | 16 | { |
| 17 | 17 | $data = json_decode($content, true, 512, JSON_THROW_ON_ERROR); |
| 18 | 18 | |
| 19 | - if ($data === null) { |
|
| 19 | + if ($data === null) |
|
| 20 | + { |
|
| 20 | 21 | return []; |
| 21 | 22 | } |
| 22 | 23 | |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | |
| 14 | 14 | abstract class HtmlUtils |
| 15 | 15 | { |
| 16 | - public static function htmlXPath(DOMDocument &$DOMDocument, $html, $xpathQuery) |
|
| 16 | + public static function htmlXPath(DOMDocument & $DOMDocument, $html, $xpathQuery) |
|
| 17 | 17 | { |
| 18 | 18 | $html = self::normalizeHTML($html); |
| 19 | 19 | |
@@ -27,10 +27,12 @@ discard block |
||
| 27 | 27 | $xmlErrors = libxml_get_errors(); |
| 28 | 28 | |
| 29 | 29 | /** @var LibXMLError $error */ |
| 30 | - foreach ($xmlErrors as $error) { |
|
| 30 | + foreach ($xmlErrors as $error) |
|
| 31 | + { |
|
| 31 | 32 | // Ignore errors about invalid tags |
| 32 | 33 | // http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors |
| 33 | - if ($error->code === 801) { |
|
| 34 | + if ($error->code === 801) |
|
| 35 | + { |
|
| 34 | 36 | continue; |
| 35 | 37 | } |
| 36 | 38 | |
@@ -46,7 +48,8 @@ discard block |
||
| 46 | 48 | |
| 47 | 49 | private static function normalizeHTML($html) |
| 48 | 50 | { |
| 49 | - if (!str_contains((string)$html, '<body>') || !str_contains((string)$html, '</body>')) { |
|
| 51 | + if (!str_contains((string)$html, '<body>') || !str_contains((string)$html, '</body>')) |
|
| 52 | + { |
|
| 50 | 53 | return sprintf('<body>%s</body>', $html); |
| 51 | 54 | } |
| 52 | 55 | |