Skip to content

Commit 1e3a1a3

Browse files
committed
Merge branch 'Namoshek-improve-configurability'
2 parents dbe0319 + f67bb9d commit 1e3a1a3

29 files changed

+179
-164
lines changed

README.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Here is an example output of the command:
3333

3434
- Is the configuration cached?
3535
- Are the routes cached?
36-
- Is the xdebug extension disabled?
36+
- Is the xdebug PHP extension disabled?
3737
- Is APP_DEBUG set to false?
3838

3939
## Installation
@@ -70,12 +70,11 @@ This will publish a `self-diagnosis.php` file in your `config` folder. This file
7070
return [
7171

7272
/*
73-
* List of all the environment names that are considered as "production".
73+
* A list of environment aliases mapped to the actual environment configuration.
7474
*/
75-
'productionEnvironments' => [
76-
'prod',
77-
'production',
78-
'live',
75+
'environment_aliases' => [
76+
'prod' => 'production',
77+
'live' => 'production',
7978
],
8079

8180
/*
@@ -85,40 +84,38 @@ return [
8584
\BeyondCode\SelfDiagnosis\Checks\AppKeyIsSet::class,
8685
\BeyondCode\SelfDiagnosis\Checks\CorrectPhpVersionIsInstalled::class,
8786
\BeyondCode\SelfDiagnosis\Checks\DatabaseCanBeAccessed::class,
88-
\BeyondCode\SelfDiagnosis\Checks\MigrationsAreUpToDate::class,
89-
\BeyondCode\SelfDiagnosis\Checks\PhpExtensionsAreInstalled::class,
87+
\BeyondCode\SelfDiagnosis\Checks\DirectoriesHaveCorrectPermissions::class,
9088
\BeyondCode\SelfDiagnosis\Checks\EnvFileExists::class,
9189
\BeyondCode\SelfDiagnosis\Checks\ExampleEnvironmentVariablesAreSet::class,
92-
\BeyondCode\SelfDiagnosis\Checks\DirectoriesHaveCorrectPermissions::class,
90+
\BeyondCode\SelfDiagnosis\Checks\MigrationsAreUpToDate::class,
91+
\BeyondCode\SelfDiagnosis\Checks\PhpExtensionsAreInstalled::class,
9392
\BeyondCode\SelfDiagnosis\Checks\StorageDirectoryIsLinked::class,
9493
],
9594

9695
/*
97-
* Production environment specific checks.
98-
*/
99-
'production' => [
100-
\BeyondCode\SelfDiagnosis\Checks\Production\ComposerWithoutDevDependenciesIsUpToDate::class,
101-
\BeyondCode\SelfDiagnosis\Checks\Production\ConfigurationIsCached::class,
102-
\BeyondCode\SelfDiagnosis\Checks\Production\RoutesAreCached::class,
103-
\BeyondCode\SelfDiagnosis\Checks\Production\XDebugIsNotEnabled::class,
104-
\BeyondCode\SelfDiagnosis\Checks\Production\DebugModeIsNotEnabled::class,
105-
],
106-
107-
/*
108-
* Development environment specific checks.
96+
* Environment specific checks that will only be performed for the corresponding environment.
10997
*/
110-
'development' => [
111-
\BeyondCode\SelfDiagnosis\Checks\Development\ComposerWithDevDependenciesIsUpToDate::class,
112-
\BeyondCode\SelfDiagnosis\Checks\Development\ConfigurationIsNotCached::class,
113-
\BeyondCode\SelfDiagnosis\Checks\Development\RoutesAreNotCached::class,
98+
'environment_checks' => [
99+
'development' => [
100+
\BeyondCode\SelfDiagnosis\Checks\ComposerWithDevDependenciesIsUpToDate::class,
101+
\BeyondCode\SelfDiagnosis\Checks\ConfigurationIsNotCached::class,
102+
\BeyondCode\SelfDiagnosis\Checks\RoutesAreNotCached::class,
103+
],
104+
'production' => [
105+
\BeyondCode\SelfDiagnosis\Checks\ComposerWithoutDevDependenciesIsUpToDate::class,
106+
\BeyondCode\SelfDiagnosis\Checks\ConfigurationIsCached::class,
107+
\BeyondCode\SelfDiagnosis\Checks\DebugModeIsNotEnabled::class,
108+
\BeyondCode\SelfDiagnosis\Checks\RoutesAreCached::class,
109+
\BeyondCode\SelfDiagnosis\Checks\XDebugIsNotEnabled::class,
110+
],
114111
],
115112

116113
];
117114
```
118115

119116
### Custom Checks
120117

121-
You can create custom checks, by implementing the `BeyondCode\SelfDiagnosis\Checks\Check` interface and adding the class to the config file.
118+
You can create custom checks, by implementing the [`BeyondCode\SelfDiagnosis\Checks\Check`](src/Checks/Check.php) interface and adding the class to the config file.
122119
Like this:
123120

124121
```php
@@ -131,29 +128,32 @@ class MyCustomCheck implements Check
131128
/**
132129
* The name of the check.
133130
*
131+
* @param array $config
134132
* @return string
135133
*/
136-
public function name(): string
134+
public function name(array $config): string
137135
{
138136
return 'My custom check.';
139137
}
140138

141139
/**
142140
* Perform the actual verification of this check.
143141
*
142+
* @param array $config
144143
* @return bool
145144
*/
146-
public function check(): bool
145+
public function check(array $config): bool
147146
{
148147
return true;
149148
}
150149

151150
/**
152151
* The error message to display in case the check does not pass.
153152
*
153+
* @param array $config
154154
* @return string
155155
*/
156-
public function message() : string
156+
public function message(array $config): string
157157
{
158158
return 'This is the error message that users see if "check" returns false.';
159159
}

config/config.php

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
return [
44

55
/*
6-
* List of all the environment names that are considered as "production".
6+
* A list of environment aliases mapped to the actual environment configuration.
77
*/
8-
'productionEnvironments' => [
9-
'prod',
10-
'production',
11-
'live',
8+
'environment_aliases' => [
9+
'prod' => 'production',
10+
'live' => 'production',
11+
'local' => 'development',
1212
],
1313

1414
/*
@@ -18,32 +18,35 @@
1818
\BeyondCode\SelfDiagnosis\Checks\AppKeyIsSet::class,
1919
\BeyondCode\SelfDiagnosis\Checks\CorrectPhpVersionIsInstalled::class,
2020
\BeyondCode\SelfDiagnosis\Checks\DatabaseCanBeAccessed::class,
21-
\BeyondCode\SelfDiagnosis\Checks\MigrationsAreUpToDate::class,
22-
\BeyondCode\SelfDiagnosis\Checks\PhpExtensionsAreInstalled::class,
21+
\BeyondCode\SelfDiagnosis\Checks\DirectoriesHaveCorrectPermissions::class => [
22+
'directories' => [
23+
storage_path(),
24+
base_path('bootstrap/cache'),
25+
],
26+
],
2327
\BeyondCode\SelfDiagnosis\Checks\EnvFileExists::class,
2428
\BeyondCode\SelfDiagnosis\Checks\ExampleEnvironmentVariablesAreSet::class,
25-
\BeyondCode\SelfDiagnosis\Checks\DirectoriesHaveCorrectPermissions::class,
29+
\BeyondCode\SelfDiagnosis\Checks\MigrationsAreUpToDate::class,
30+
\BeyondCode\SelfDiagnosis\Checks\PhpExtensionsAreInstalled::class,
2631
\BeyondCode\SelfDiagnosis\Checks\StorageDirectoryIsLinked::class,
2732
],
2833

2934
/*
30-
* Production environment specific checks.
31-
*/
32-
'production' => [
33-
\BeyondCode\SelfDiagnosis\Checks\Production\ComposerWithoutDevDependenciesIsUpToDate::class,
34-
\BeyondCode\SelfDiagnosis\Checks\Production\ConfigurationIsCached::class,
35-
\BeyondCode\SelfDiagnosis\Checks\Production\RoutesAreCached::class,
36-
\BeyondCode\SelfDiagnosis\Checks\Production\XDebugIsNotEnabled::class,
37-
\BeyondCode\SelfDiagnosis\Checks\Production\DebugModeIsNotEnabled::class,
38-
],
39-
40-
/*
41-
* Development environment specific checks.
35+
* Environment specific checks that will only be performed for the corresponding environment.
4236
*/
43-
'development' => [
44-
\BeyondCode\SelfDiagnosis\Checks\Development\ComposerWithDevDependenciesIsUpToDate::class,
45-
\BeyondCode\SelfDiagnosis\Checks\Development\ConfigurationIsNotCached::class,
46-
\BeyondCode\SelfDiagnosis\Checks\Development\RoutesAreNotCached::class,
37+
'environment_checks' => [
38+
'development' => [
39+
\BeyondCode\SelfDiagnosis\Checks\ComposerWithDevDependenciesIsUpToDate::class,
40+
\BeyondCode\SelfDiagnosis\Checks\ConfigurationIsNotCached::class,
41+
\BeyondCode\SelfDiagnosis\Checks\RoutesAreNotCached::class,
42+
],
43+
'production' => [
44+
\BeyondCode\SelfDiagnosis\Checks\ComposerWithoutDevDependenciesIsUpToDate::class,
45+
\BeyondCode\SelfDiagnosis\Checks\ConfigurationIsCached::class,
46+
\BeyondCode\SelfDiagnosis\Checks\DebugModeIsNotEnabled::class,
47+
\BeyondCode\SelfDiagnosis\Checks\RoutesAreCached::class,
48+
\BeyondCode\SelfDiagnosis\Checks\XDebugIsNotEnabled::class,
49+
],
4750
],
4851

4952
];

src/Checks/AppKeyIsSet.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class AppKeyIsSet implements Check
99
*
1010
* @return string
1111
*/
12-
public function name(): string
12+
public function name(array $config): string
1313
{
1414
return 'App key is set';
1515
}
@@ -19,7 +19,7 @@ public function name(): string
1919
*
2020
* @return bool
2121
*/
22-
public function check(): bool
22+
public function check(array $config): bool
2323
{
2424
return config('app.key') !== null;
2525
}
@@ -29,8 +29,8 @@ public function check(): bool
2929
*
3030
* @return string
3131
*/
32-
public function message() : string
32+
public function message(array $config): string
3333
{
3434
return 'The application key is not set. Call "php artisan key:generate" to create it.';
3535
}
36-
}
36+
}

src/Checks/Check.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ interface Check
77
/**
88
* The name of the check.
99
*
10+
* @param array $config
1011
* @return string
1112
*/
12-
public function name() : string;
13+
public function name(array $config): string;
1314

1415
/**
1516
* Perform the actual verification of this check.
1617
*
18+
* @param array $config
1719
* @return bool
1820
*/
19-
public function check() : bool;
21+
public function check(array $config): bool;
2022

2123
/**
2224
* The error message to display in case the check does not pass.
2325
*
26+
* @param array $config
2427
* @return string
2528
*/
26-
public function message() : string;
27-
}
29+
public function message(array $config): string;
30+
}

src/Checks/Development/ComposerWithDevDependenciesIsUpToDate.php renamed to src/Checks/ComposerWithDevDependenciesIsUpToDate.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace BeyondCode\SelfDiagnosis\Checks\Development;
3+
namespace BeyondCode\SelfDiagnosis\Checks;
44

55
use BeyondCode\SelfDiagnosis\Composer;
66
use BeyondCode\SelfDiagnosis\Checks\Check;
@@ -24,7 +24,7 @@ public function __construct(Composer $composer)
2424
*
2525
* @return string
2626
*/
27-
public function name(): string
27+
public function name(array $config): string
2828
{
2929
return 'Composer dependencies are up to date with the composer.lock file.';
3030
}
@@ -34,7 +34,7 @@ public function name(): string
3434
*
3535
* @return bool
3636
*/
37-
public function check(): bool
37+
public function check(array $config): bool
3838
{
3939
$this->output = $this->composer->installDryRun();
4040

@@ -46,7 +46,7 @@ public function check(): bool
4646
*
4747
* @return string
4848
*/
49-
public function message() : string
49+
public function message(array $config): string
5050
{
5151
return 'Your composer dependencies are not up to date. Call "composer install".' . $this->output;
5252
}

src/Checks/Production/ComposerWithoutDevDependenciesIsUpToDate.php renamed to src/Checks/ComposerWithoutDevDependenciesIsUpToDate.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace BeyondCode\SelfDiagnosis\Checks\Production;
3+
namespace BeyondCode\SelfDiagnosis\Checks;
44

55
use BeyondCode\SelfDiagnosis\Composer;
66
use BeyondCode\SelfDiagnosis\Checks\Check;
@@ -24,7 +24,7 @@ public function __construct(Composer $composer)
2424
*
2525
* @return string
2626
*/
27-
public function name(): string
27+
public function name(array $config): string
2828
{
2929
return 'Composer dependencies (without dev) are up to date with the composer.lock file.';
3030
}
@@ -34,7 +34,7 @@ public function name(): string
3434
*
3535
* @return bool
3636
*/
37-
public function check(): bool
37+
public function check(array $config): bool
3838
{
3939
$this->output = $this->composer->installDryRun('--no-dev');
4040

@@ -46,7 +46,7 @@ public function check(): bool
4646
*
4747
* @return string
4848
*/
49-
public function message() : string
49+
public function message(array $config): string
5050
{
5151
return 'Your composer dependencies are not up to date. Call "composer install".' . $this->output;
5252
}

src/Checks/Production/ConfigurationIsCached.php renamed to src/Checks/ConfigurationIsCached.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace BeyondCode\SelfDiagnosis\Checks\Production;
3+
namespace BeyondCode\SelfDiagnosis\Checks;
44

55
use BeyondCode\SelfDiagnosis\Checks\Check;
66

@@ -12,7 +12,7 @@ class ConfigurationIsCached implements Check
1212
*
1313
* @return string
1414
*/
15-
public function name(): string
15+
public function name(array $config): string
1616
{
1717
return 'Configuration is cached';
1818
}
@@ -22,7 +22,7 @@ public function name(): string
2222
*
2323
* @return bool
2424
*/
25-
public function check(): bool
25+
public function check(array $config): bool
2626
{
2727
return app()->configurationIsCached() === true;
2828
}
@@ -32,8 +32,8 @@ public function check(): bool
3232
*
3333
* @return string
3434
*/
35-
public function message(): string
35+
public function message(array $config): string
3636
{
3737
return 'Your configuration files should be cached in production. Call "php artisan config:cache" to cache the configuration.';
3838
}
39-
}
39+
}

src/Checks/Development/ConfigurationIsNotCached.php renamed to src/Checks/ConfigurationIsNotCached.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace BeyondCode\SelfDiagnosis\Checks\Development;
3+
namespace BeyondCode\SelfDiagnosis\Checks;
44

55
use BeyondCode\SelfDiagnosis\Checks\Check;
66

@@ -12,7 +12,7 @@ class ConfigurationIsNotCached implements Check
1212
*
1313
* @return string
1414
*/
15-
public function name(): string
15+
public function name(array $config): string
1616
{
1717
return 'Configuration is not cached';
1818
}
@@ -22,7 +22,7 @@ public function name(): string
2222
*
2323
* @return bool
2424
*/
25-
public function check(): bool
25+
public function check(array $config): bool
2626
{
2727
return app()->configurationIsCached() === false;
2828
}
@@ -32,8 +32,8 @@ public function check(): bool
3232
*
3333
* @return string
3434
*/
35-
public function message(): string
35+
public function message(array $config): string
3636
{
3737
return 'Your configuration files should not be cached during development. Call "php artisan config:clear" to clear the config cache.';
3838
}
39-
}
39+
}

0 commit comments

Comments
 (0)