Test Failed
Branch master (17185c)
by Keoghan
06:01 queued 02:00
created

Config   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 46
ccs 19
cts 21
cp 0.9048
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 4
    public function __construct(Filesystem $files, PorterLibrary $porterLibrary)
18
    {
19 4
        $this->files = $files;
20 4
        $this->porterLibrary = $porterLibrary;
21 4
    }
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 1
    }
29
30 1
    public function updateIp($to)
31
    {
32 1
        $pattern = "/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/";
33 1
        $newConfig = preg_replace($pattern, "/{$to}", $this->getConfig());
34
35 1
        $this->putConfig($newConfig);
36 1
    }
37
38 2
    protected function getPath()
39
    {
40 2
        return $this->porterLibrary->configPath().'/dnsmasq/dnsmasq.conf';
41
    }
42
43 2
    protected function getConfig()
44
    {
45
        try {
46 2
            return $this->files->get($this->getPath());
47
        } catch (FileNotFoundException $e) {
48
            return '';
49
        }
50
    }
51
52 2
    protected function putConfig($content)
53
    {
54 2
        $this->files->put($this->getPath(), $content);
55 2
    }
56
}
57