Skip to content

Commit eed75f9

Browse files
authored
Merge pull request #190 from shochdoerfer/feature/optimize_ci_neon
Check if classes referenced in neon config exist
2 parents 226c8c0 + d95f06e commit eed75f9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

bin/ci_markdown_neon_lint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare(strict_types=1);
1313

1414
require_once __DIR__ . '/../vendor/autoload.php';
1515

16-
// inspired by https://github.com/mathiasverraes/uptodocs this CLI script will lint
16+
// inspired by https://github.com/mathiasverraes/uptodocs this CLI script lints
1717
// the Neon snippets in the Markdown files like README.md
1818

1919
$path = realpath(__DIR__ . '/../');
@@ -48,7 +48,7 @@ foreach ($it as $file) {
4848
} catch (Nette\Neon\Exception $e) {
4949
$success = false;
5050
$relPath = str_replace($path . DIRECTORY_SEPARATOR, '', $file->getRealPath());
51-
echo "Failed parsing node ".$nodeCount." of file ".$relPath."\n";
51+
echo sprintf('Failed parsing node "%s" of file "%s"', $nodeCount, $relPath)."\n";
5252
}
5353
}
5454
}

bin/ci_neon_lint

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ foreach ($it as $file) {
2828
}
2929

3030
try {
31-
$content = file_get_contents($file->getRealPath());
32-
Nette\Neon\Neon::decode($content);
31+
$neon = Nette\Neon\Neon::decodeFile($file->getRealPath());
32+
array_walk_recursive($neon, function($value, $key) use($success) {
33+
if (($key === 'class') && !class_exists($value)) {
34+
throw new \RuntimeException(sprintf('Class "%s" does not exist', $value));
35+
}
36+
});
3337
} catch (Nette\Neon\Exception $e) {
3438
$success = false;
3539
$relPath = str_replace($path . DIRECTORY_SEPARATOR, '', $file->getRealPath());
36-
echo "Failed parsing ".$relPath."\n";
40+
echo sprintf('Failed parsing file "%s"', $relPath)."\n";
41+
} catch (\RuntimeException $e) {
42+
$success = false;
43+
echo $e->getMessage()."\n";
3744
}
3845
}
3946

0 commit comments

Comments
 (0)