Build   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
eloc 7
c 3
b 0
f 0
dl 0
loc 67
rs 10
ccs 4
cts 12
cp 0.3333

6 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldUseEnvironmentFile() 0 3 2
A isRunning() 0 3 1
A environmentFile() 0 3 1
A getPath() 0 3 1
A environmentFilePath() 0 3 1
A getDirectoryPath() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Providers\Build;
15
16
use function dirname;
17
use Phar;
18
19
/**
20
 * @internal
21
 */
22
class Build
23
{
24
    /**
25
     * The name of the environment file.
26
     *
27
     * @var string
28
     */
29
    private $environmentFile = '.env';
30
31
    /**
32
     * Checks if the application is running from a Phar file.
33
     *
34
     * @return bool
35
     */
36 39
    public function isRunning(): bool
37
    {
38 39
        return Phar::running() !== '';
39
    }
40
41
    /**
42
     * Returns the directory path from where the Phar is running.
43
     *
44
     * @return string
45
     */
46
    public function getDirectoryPath(): string
47
    {
48
        return dirname($this->getPath());
49
    }
50
51
    /**
52
     * Returns the path from where the Phar is running.
53
     *
54
     * @return string
55
     */
56
    public function getPath(): string
57
    {
58
        return Phar::running(false);
59
    }
60
61
    /**
62
     * Returns the .env path with Phar running.
63
     *
64
     * @return string
65
     */
66
    public function environmentFilePath(): string
67
    {
68
        return $this->getDirectoryPath().DIRECTORY_SEPARATOR.$this->environmentFile;
69
    }
70
71
    /**
72
     * Checks if the build is running and there's an available environment file.
73
     *
74
     * @return bool
75
     */
76 39
    public function shouldUseEnvironmentFile(): bool
77
    {
78 39
        return $this->isRunning() && file_exists($this->environmentFilePath());
79
    }
80
81
    /**
82
     * The file for environment file.
83
     *
84
     * @return string
85
     */
86
    public function environmentFile(): string
87
    {
88
        return $this->environmentFile;
89
    }
90
}
91