Lines 0.00% 0 / 10
Functions and Methods 0.00% 0 / 1
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
CodegenError 0.00% 0 / 10 0.00% 0 / 1 110 0.00% 0 / 1
 messageTemplate 0.00% 0 / 10 0.00% 0 / 1 110
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Codegen\Exception;
6
7use Stewart\Contracts\Exception\ExceptionReason;
8
9enum CodegenError: string implements ExceptionReason
10{
11    case SnapshotUnreadable = 'snapshot_unreadable';
12    case SnapshotNotJson = 'snapshot_not_json';
13    case NotASnapshot = 'not_a_snapshot';
14    case OutputDirectoryNotCreatable = 'output_directory_not_creatable';
15    case FileNotWritable = 'file_not_writable';
16    case FileNotDeletable = 'file_not_deletable';
17    case UnmarkedFileInTheWay = 'unmarked_file_in_the_way';
18    case ShrinkRefused = 'shrink_refused';
19    case HomeAssistantNotRunning = 'home_assistant_not_running';
20
21    public function messageTemplate(): string
22    {
23        return match ($this) {
24            self::SnapshotUnreadable => 'Snapshot {path} cannot be read.',
25            self::SnapshotNotJson => 'Snapshot {path} is not valid JSON: {reason}',
26            self::NotASnapshot => '{path} is not a snapshot; write one with `stewart generate --snapshot-out`.',
27            self::OutputDirectoryNotCreatable => 'Cannot create output directory {path}.',
28            self::FileNotWritable => 'Cannot write {path}.',
29            self::FileNotDeletable => 'Cannot delete {path}.',
30            self::UnmarkedFileInTheWay => '{path} was not written by stewart generate; move it out of the output directory.',
31            self::ShrinkRefused => 'Generating would delete {deleted} of {existing} generated files; run `make generate ARGS=--allow-shrink` if that is intended.',
32            self::HomeAssistantNotRunning => 'Home Assistant is {state}; run `stewart generate` again once it has started.',
33        };
34    }
35}