ConfigPathGuesser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A guess() 0 11 3
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