Build::getPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 0
crap 2
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