Passed
Push — master ( a4c5f9...448818 )
by Keoghan
18:30
created

Config   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 46
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A updateIp() 0 6 1
A __construct() 0 4 1
A getPath() 0 3 1
A getConfig() 0 6 2
A putConfig() 0 3 1
A updateDomain() 0 5 1
1
<?php
2
3
namespace App\Support\Dnsmasq;
4
5
use App\PorterLibrary;
6
use Illuminate\Contracts\Filesystem\FileNotFoundException;
7
use Illuminate\Filesystem\Filesystem;
8
9
class Config
10
{
11
    /** @var Filesystem */
12
    protected $files;
13
14
    /** @var PorterLibrary */
15
    private $porterLibrary;
16
17 6
    public function __construct(Filesystem $files, PorterLibrary $porterLibrary)
18
    {
19 6
        $this->files = $files;
20 6
        $this->porterLibrary = $porterLibrary;
21
    }
22
23 1
    public function updateDomain($from, $to)
24
    {
25 1
        $newConfig = preg_replace("/\/.{$from}\//", "/.{$to}/", $this->getConfig());
26
27 1
        $this->putConfig($newConfig);
28
    }
29
30 3
    public function updateIp($to)
31
    {
32 3
        $pattern = "/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/";
33 3
        $newConfig = preg_replace($pattern, "/{$to}", $this->getConfig());
34
35 3
        $this->putConfig($newConfig);
36
    }
37
38 4
    protected function getPath()
39
    {
40 4
        return $this->porterLibrary->configPath().'/dnsmasq/dnsmasq.conf';
41
    }
42
43 4
    protected function getConfig()
44
    {
45
        try {
46 4
            return $this->files->get($this->getPath());
47
        } catch (FileNotFoundException $e) {
48
            return '';
49
        }
50
    }
51
52 4
    protected function putConfig($content)
53
    {
54 4
        $this->files->put($this->getPath(), $content);
55
    }
56
}
57