Passed
Push — 0.7.0 ( 91f75a...a316e5 )
by Alexander
09:55
created

RepositoryCreator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 60
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createDefaultAdapters() 0 5 1
A defaultAdapters() 0 4 2
A make() 0 3 1
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.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\Repository;
24
25
use Syscodes\Contracts\Dotenv\Adapter;
26
use Syscodes\Dotenv\Repository\Adapters\ArrayAdapter;
27
use Syscodes\Dotenv\Repository\Adapters\ApacheAdapter;
28
use Syscodes\Dotenv\Repository\Adapters\PutenvAdapter;
29
use Syscodes\Dotenv\Repository\Adapters\ServerAdapter;
30
31
/**
32
 * Allows you to bring all the adapters.
33
 * 
34
 * @author Alexander Campo <[email protected]>
35
 */
36
final class RepositoryCreator
37
{
38
    protected const ADAPTERS_DEFAULT = [
39
        ApacheAdapter::class,
40
        ArrayAdapter::class,
41
        PutenvAdapter::class,
42
        ServerAdapter::class,
43
    ];
44
45
    /**
46
     * Gets adapters allow list to use.
47
     * 
48
     * @var string[] $allowlist
49
     */
50
    protected $allowlist;
51
52
    /**
53
     * Constructor. Create a new Repository creator instance.
54
     * 
55
     * @param  \Syscodes\Contracts\Dotenv\Adapter[]  $adapter
56
     * 
57
     * @return void
58
     */
59
    public function __construct(array $adapter = [])
60
    {
61
        $this->allowList = $adapter;
0 ignored issues
show
Bug Best Practice introduced by
The property allowList does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
62
    }
63
64
    /**
65
     * Create a new repository creator instance with the default adapters added.
66
     * 
67
     * @return \Syscodes\Dotenv\Repository\RepositoryCreator
68
     */
69
    public function createDefaultAdapters()
70
    {
71
        $adapters = iterator_to_array(self::defaultAdapters());
72
73
        return new static($adapters);
74
    }
75
    
76
    /**
77
     * Return the array of default adapters.
78
     * 
79
     * @return \Syscodes\Contracts\Dotenv\Adapter
80
     */
81
    protected static function defaultAdapters()
82
    {
83
        foreach (self::ADAPTERS_DEFAULT as $adapter) {
84
            yield new $adapter;
0 ignored issues
show
Bug Best Practice introduced by
The expression yield new $adapter() returns the type Generator which is incompatible with the documented return type Syscodes\Contracts\Dotenv\Adapter.
Loading history...
85
        }
86
    }
87
88
    /**
89
     * Creates a new repository instance.
90
     * 
91
     * @return \Syscodes\Contracts\Dotenv\Repository
92
     */
93
    public function make()
94
    {
95
        return new AdapterRepository($this->allowlist);
0 ignored issues
show
Bug introduced by
$this->allowlist of type string[] is incompatible with the type Syscodes\Dotenv\Repository\Adapter expected by parameter $adapter of Syscodes\Dotenv\Reposito...pository::__construct(). ( Ignorable by Annotation )

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

95
        return new AdapterRepository(/** @scrutinizer ignore-type */ $this->allowlist);
Loading history...
96
    }
97
}