Lines 100.00% 6 / 6
Methods 100.00% 4 / 4
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 buildHeaderComment 100.00% 1 / 1 100.00% 1 / 1 1
 isGenerated 100.00% 1 / 1 100.00% 1 / 1 1
 printGenerated 100.00% 3 / 3 100.00% 1 / 1 1
 printGeneratedStatements 100.00% 1 / 1 100.00% 1 / 1 1
10final class GeneratedCodePrinter extends PsrPrinter
11{
12    public const string MARKER = '@generated by `stewart generate`';
13
14    public bool $singleParameterOnOneLine = true;
15
16    public static function buildHeaderComment(): string
17    {
18        return \sprintf("/**\n * %s.\n *\n * Do not edit: run `make generate` instead.\n */", self::MARKER);
19    }
20
21    public static function isGenerated(string $contents): bool
22    {
23        return str_contains($contents, self::MARKER);
24    }
25
26    public function printGenerated(PhpNamespace $namespace): string
27    {
28        // Printed by hand: nette puts the file comment above `declare`; this repository puts it below.
29        return "<?php\n\ndeclare(strict_types=1);\n\n"
30            . self::buildHeaderComment() . "\n\n"
31            . $this->printNamespace($namespace);
32    }
33
34    public function printGeneratedStatements(string $namespace, string $statements): string
35    {
36        return "<?php\n\n" . self::buildHeaderComment() . \sprintf("\n\nnamespace %s;\n\n%s\n", $namespace, $statements);
37    }
38}