Passed
Branch master (35cb72)
by Jonathan
02:41 queued 01:09
created

ConfigWriter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 68
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getConfigFile() 0 4 1
A configExists() 0 4 1
A getCurrentConfig() 0 7 2
A setCurrentConfig() 0 7 2
1
<?php
2
namespace Spekkionu\Assetcachebuster\Writer;
3
4
use Illuminate\Filesystem\Filesystem;
5
6
class ConfigWriter implements WriterInterface
7
{
8
    /**
9
     * @var Filesystem
10
     */
11
    private $filesystem;
12
    /**
13
     * @var
14
     */
15
    private $config_path;
16
17
    /**
18
     * ConfigWriter constructor.
19
     * @param Filesystem $filesystem
20
     * @param string $config_path
21
     */
22 4
    public function __construct(Filesystem $filesystem, $config_path)
23
    {
24 4
        $this->filesystem = $filesystem;
25 4
        $this->config_path = $config_path;
26 4
    }
27
28
    /**
29
     * Get the key file and contents.
30
     *
31
     * @return array
32
     */
33 4
    protected function getConfigFile()
34
    {
35 4
        return $this->config_path . DIRECTORY_SEPARATOR . "assetcachebuster.php";
36
    }
37
38
    /**
39
     * Check if the config file exists
40
     * 
41
     * @return bool
42
     */
43 4
    protected function configExists()
44
    {
45 4
        return $this->filesystem->exists($this->getConfigFile());
46
    }
47
48
    /**
49
     * Returns current config as string
50
     *
51
     * @return string
52
     */
53 2
    public function getCurrentConfig()
54
    {
55 2
        if (!$this->configExists()) {
56 1
            throw new \InvalidArgumentException('The config file does not exist. Did you run the vendor:publish command?');
57
        }
58 1
        return $this->filesystem->get($this->getConfigFile());
59
    }
60
61
    /**
62
     * Saves config as current config
63
     * @param string $content
64
     * @return void
65
     */
66 2
    public function setCurrentConfig($content)
67
    {
68 2
        if (!$this->configExists()) {
69 1
            throw new \InvalidArgumentException('The config file does not exist. Did you run the vendor:publish command?');
70
        }
71 1
        $this->filesystem->put($this->getConfigFile(), $content);
72 1
    }
73
}
74