Passed
Push — develop ( e32fe8...a6721e )
by Brent
02:31
created

InvalidConfiguration::missingParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Stitcher\Exception;
4
5
use Pageon\Config;
6
use Stitcher\File;
7
8
class InvalidConfiguration extends StitcherException
9
{
10
    public static function siteConfigurationFileNotFound(): InvalidConfiguration
11
    {
12
        return new self(
13
            'No site configuration file was found.',
14
            <<<MD
15
All static pages should be configured in a site configuration file.
16
The path to this file can be configured in `./config/config.php`
17
18
```php
19
return [
20
    // ...
21
22
    'configurationFile' => File::path('src/site.yaml'),
23
];
24
```
25
26
This `site.yaml` file contains a list of routes and their configuration.
27
28
```yaml
29
/:
30
    template: home.twig
31
    # ...
32
33
/blog/page-{page}:
34
    template: blog/overview.twig
35
    # ...
36
37
/blog/{id}:
38
    template: blog/detail.twig
39
    # ...
40
```
41
MD
42
43
        );
44
    }
45
46 1
    public static function pageTemplateMissing(string $pageId): InvalidConfiguration
47
    {
48 1
        $templateDirectory = File::relativePath(Config::get('templateDirectory'));
49
50 1
        return new self(
51 1
            'A page requires a `template` value.',
52
            <<<MD
53 1
A template file should be saved in the `$templateDirectory` folder. 
54
Its path is relative to this template direcotry path. 
55
56
```yaml
57 1
$pageId:
58
    template: template.twig
59
```
60
61
The `templateDirectory` path can be overridden in a `php` config file which lives in the `./config` directory.
62
63
```php
64
return [
65
    // ...
66
    
67
    'templateDirectory' => File::path('resources/view'),
68
];
69
```
70
MD
71
72
        );
73
    }
74
75 1
    public static function pageIdMissing(): InvalidConfiguration
76
    {
77 1
        return new self('A page requires an `id` value.');
78
    }
79
80
    public static function fileNotFound(string $path): InvalidConfiguration
81
    {
82
        return new self("File with path `{$path}` could not be found.");
83
    }
84
85
    public static function invalidAdapterConfiguration(string $adapter, string $fields): InvalidConfiguration
86
    {
87
        return new self("The {$adapter} adapter requires following configuration: {$fields}");
88
    }
89
90
    public static function dotEnvNotFound(string $directory): InvalidConfiguration
91
    {
92
        return new self("Could not find `.env` file. Looked in {$directory}");
93
    }
94
95
    public static function missingParameter(string $parameter): InvalidConfiguration
96
    {
97
        return new self("Missing parameter `{$parameter}`, did you add it in your config file?");
98
    }
99
}
100