AvailableConfigurations   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 17
dl 0
loc 64
ccs 20
cts 20
cp 1
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A getLocations() 0 3 1
A getFileNames() 0 7 1
A getList() 0 6 2
A locationsFromViewFinder() 0 6 1
1
<?php
2
3
namespace App\Support\Nginx;
4
5
use Symfony\Component\Finder\Finder;
6
use Symfony\Component\Finder\SplFileInfo;
7
8
class AvailableConfigurations
9
{
10
    protected $locations;
11
12
    /**
13
     * AvailableConfigurations constructor.
14
     *
15
     * @param array|null $locations
16
     */
17 3
    public function __construct($locations = null)
18
    {
19 3
        $this->locations = $locations ?: $this->locationsFromViewFinder();
20
    }
21
22
    /**
23
     * Get the list of conf files, indicating current.
24
     *
25
     * @param string|null $highlight
26
     *
27
     * @return mixed
28
     */
29 2
    public function getList($highlight = null)
30
    {
31 2
        return $this->getFileNames()
32 2
            ->mapWithKeys(function ($name) use ($highlight) {
33 2
                return [$name => $name.($name == $highlight ? ' (current)' : '')];
34 2
            })->toArray();
35
    }
36
37
    /**
38
     * Return the locations being used.
39
     *
40
     * @return array
41
     */
42 1
    public function getLocations()
43
    {
44 1
        return $this->locations;
45
    }
46
47
    /**
48
     * Retrieve the locations of NGiNX configurations.
49
     *
50
     * @return array
51
     */
52 1
    protected function locationsFromViewFinder()
53
    {
54 1
        return collect(view()->getFinder()->getPaths())
55 1
            ->map(function ($location) {
56 1
                return $location.'/nginx';
57 1
            })->toArray();
58
    }
59
60
    /**
61
     * Scour the locations and get a Collection of NGiNX files.
62
     *
63
     * @return \Illuminate\Support\Collection
64
     */
65 2
    protected function getFileNames()
66
    {
67 2
        return collect(iterator_to_array(
68 2
            Finder::create()->in($this->locations)->directories()
69 2
        ))->map(function (SplFileInfo $file) {
70 2
            return $file->getFilename();
71 2
        })->sort();
72
    }
73
}
74