Passed
Push — 0.7.0 ( c2424f...06148a )
by Alexander
02:45
created

Dotenv::setVariable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 3
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php 
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file license.md.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2021 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md
21
 */
22
23
namespace Syscodes\Dotenv;
24
25
use InvalidArgumentException;
26
use Syscodes\Dotenv\Loader\Loader;
27
use Syscodes\Dotenv\Store\StoreBuilder;
28
use Syscodes\Dotenv\Repository\RepositoryCreator;
29
30
/**
31
 * Manages .env files.
32
 * 
33
 * @author Alexander Campo <[email protected]>
34
 */
35
final class Dotenv
36
{
37
    /**
38
     * The Loader instance.
39
     * 
40
     * @var \Syscodes\Dotenv\Loader\Loader $loader
41
     */
42
    protected $loader;
43
44
    /**
45
     * The Repository creator instance.
46
     * 
47
     * @var \Syscodes\Dotenv\Repository\RepositoryCreator $repository
48
     */
49
    protected $repository;
50
51
    /**
52
     * The file store instance.
53
     * 
54
     * @var \Syscodes\Dotenv\Repository\FileStore $store
0 ignored issues
show
Bug introduced by
The type Syscodes\Dotenv\Repository\FileStore was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
55
     */
56
    protected $store;
57
58
    /**
59
     * Activate use of putenv, by default is true.
60
     * 
61
     * @var bool $usePutenv 
62
     */
63
    protected $usePutenv = true;
64
65
    /**
66
     * Constructor. Create a new Dotenv instance.
67
     * 
68
     * @param  \Syscodes\Dotenv\Store\StoreBuilder  $store
69
     * @param  \Syscodes\Dotenv\Loader\Loader  $loader
70
     * @param  \Syscodes\Dotenv\Repository\RepositoryCreator  $repository
71
     * 
72
     * @return void
73
     */
74
    public function __construct($store, Loader $loader, $repository)
75
    {
76
        $this->store      = $store;
0 ignored issues
show
Documentation Bug introduced by
It seems like $store of type Syscodes\Dotenv\Store\StoreBuilder is incompatible with the declared type Syscodes\Dotenv\Repository\FileStore of property $store.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
77
        $this->loader     = $loader;
78
        $this->repository = $repository;
79
    }
80
81
    /**
82
     * Create a new Dotenv instance.
83
     * Builds the path to our file.
84
     * 
85
     * @param  \Syscodes\Dotenv\Repository\RepositoryCreator  $repository
86
     * @param  string|string[]  $path
87
     * @param  string|string[]  $names
88
     * @param  bool  $modeEnabled  (true by default)
89
     * 
90
     * @return \Syscodes\Dotenv\Dotenv
91
     */
92
    public static function create($repository, $paths, $names = null, bool $modeEnabled = true)
93
    {
94
        $store = $names === null ? StoreBuilder::createWithDefaultName() : StoreBuilder::createWithNoNames();
95
96
        foreach ((array) $paths as $path) {
97
            $store = $store->addPath($path);
98
        }
99
        
100
        foreach ((array) $names as $name) {
101
            $store = $store->addName($name);
102
        }
103
104
        if ($modeEnabled) {
105
            $store = $store->modeEnabled();
106
        }
107
108
        return new self($store->make(), new Loader($repository), $repository);
0 ignored issues
show
Bug introduced by
$store->make() of type Syscodes\Dotenv\Store\FileStore is incompatible with the type Syscodes\Dotenv\Store\StoreBuilder expected by parameter $store of Syscodes\Dotenv\Dotenv::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

108
        return new self(/** @scrutinizer ignore-type */ $store->make(), new Loader($repository), $repository);
Loading history...
109
    }
110
111
    /**
112
     * Will load the .env file and process it. So that we end all settings in the PHP 
113
     * environment vars: getenv(), $_ENV, and $_SERVER.
114
     * 
115
     * @return bool
116
     */
117
    public function load()
118
    {        
119
        return $this->loader->load($this->store->read());
120
    }
121
}