ConfigPathGuesser::guess()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Bencagri\Artisan\Deployer\Helper;
4
5
6
class ConfigPathGuesser
7
{
8
    private const LEGACY_CONFIG_DIR = '%s/config';
9
    private const CONFIG_DIR = '%s/etc';
10
11
    public static function guess(string $projectDir, string $stage): string
12
    {
13
        if (is_dir($configDir = sprintf(self::CONFIG_DIR, $projectDir))) {
14
            return sprintf('%s/%s/deploy.php', $configDir, $stage);
15
        }
16
17
        if (is_dir($configDir = sprintf(self::LEGACY_CONFIG_DIR, $projectDir))) {
18
            return sprintf('%s/deploy_%s.php', $configDir, $stage);
19
        }
20
21
        throw new \RuntimeException(sprintf('None of the usual Laravel config dirs exist in the application. Create one of these dirs before continuing: "%s" or "%s".', self::CONFIG_DIR, self::LEGACY_CONFIG_DIR));
22
    }
23
}
24