Passed
Push — 0.7.0 ( a316e5...a89e02 )
by Alexander
03:01
created

ArrayAdapter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 74
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 5 1
A isSupported() 0 3 1
A has() 0 3 1
A delete() 0 5 1
A read() 0 7 2
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.
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
21
 */
22
23
namespace Syscodes\Dotenv\Repository\Adapters;
24
25
use Syscodes\Contracts\Dotenv\Adapter;
26
27
/**
28
 * Read, write and delete an environment variable for arrays.
29
 * 
30
 * @author Alexander Campo <[email protected]>
31
 */
32
class ArrayAdapter implements Adapter
33
{
34
    /**
35
     * Internal storage for array data.
36
     * 
37
     * @var array $data
38
     */
39
    protected $data = [];
40
41
    /**
42
     * Determines if the adapter is supported.
43
     * 
44
     * @return bool
45
     */
46
    public function isSupported()
47
    {
48
        return true;
49
    }
50
51
    /**
52
     * Check if a variable exists.
53
     * 
54
     * @param  string  $name
55
     * 
56
     * @return bool
57
     */
58
    public function has(string $name)
59
    {
60
        return array_key_exists($name, $this->data);
61
    }
62
63
    /**
64
     * Read an environment variable.
65
     * 
66
     * @param  string  $name
67
     * 
68
     * @return mixed
69
     */
70
    public function read(string $name)
71
    {
72
        if ($this->has($name)) {
73
            return $this->data[$name];
74
        }
75
76
        return null;
77
    }
78
79
     /**
80
     * Write to an environment variable.
81
     * 
82
     * @param  string  $name
83
     * @param  string  $value
84
     * 
85
     * @return bool
86
     */
87
    public function write(string $name, string $value)
88
    {
89
        $this->data[$name] = $value;
90
91
        return true;
92
    }
93
94
    /**
95
     * Delete an environment variable.
96
     * 
97
     * @param  string  $name
98
     * 
99
     * @return bool
100
     */
101
    public function delete(string $name)
102
    {
103
        unset($this->data[$name]);
104
105
        return true;
106
    }
107
}