Passed
Push — 0.7.0 ( 7cf8ff...8cbd21 )
by Alexander
04:15 queued 11s
created

Writers   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 9 3
A delete() 0 9 3
A __construct() 0 3 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
/**
26
 * Write and delete an environment variable.
27
 * 
28
 * @author Alexander Campo <[email protected]>
29
 */
30
final class Writers
31
{
32
    /**
33
     * The set of writers to use.
34
     * 
35
     * @var \Syscodes\Dotenv\Repository\Adapters\Writers $writers
36
     */
37
    protected $writers;
38
39
    /**
40
     * Constructor. Create a new Writers instance.
41
     * 
42
     * @param  \Syscodes\Dotenv\Repository\Adapters\Writers  $writers
43
     * 
44
     * @return void
45
     */
46
    public function __construct(array $writers)
47
    {
48
        $this->writers = $writers;
0 ignored issues
show
Documentation Bug introduced by
It seems like $writers of type array is incompatible with the declared type Syscodes\Dotenv\Repository\Adapters\Writers of property $writers.

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...
49
    }
50
51
    /**
52
     * Write to an environment variable.
53
     * 
54
     * @param  string  $name
55
     * @param  string  $value
56
     * 
57
     * @return bool 
58
     */
59
    public function write(string $name, string $value)
60
    {
61
        foreach ($this->writers as $writes) {
62
            if ( ! $writes->write($name, $value)) {
63
                return false;
64
            }
65
        }
66
67
        return true;
68
    }
69
70
    /**
71
     * Write to an environment variable.
72
     * 
73
     * @param  string  $name
74
     * 
75
     * @return bool 
76
     */
77
    public function delete(string $name)
78
    {
79
        foreach ($this->writers as $writes) {
80
            if ( ! $writes->delete($name)) {
81
                return false;
82
            }
83
        }
84
85
        return true;
86
    }
87
}