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

ServerAdapter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 67
rs 10
wmc 6

5 Methods

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