FilesystemWriter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 8 3
A create() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoind\Config;
6
7
use BitWasp\Bitcoind\Exception\BitcoindException;
8
9
class FilesystemWriter extends Writer
10
{
11 10
    public function save(string $filePath, Config $config)
12
    {
13 10
        $file = "";
14 10
        foreach ($config->all() as $key => $option) {
15 10
            $file .= "{$key}={$option}\n";
16
        }
17 10
        if (!file_put_contents($filePath, $file)) {
18
            throw new BitcoindException("Failed to write config file");
19
        }
20 10
    }
21
22 10
    public function create(string $filePath, Config $config)
23
    {
24 10
        if (file_exists($filePath)) {
25 1
            throw new BitcoindException("Cannot overwrite existing files with FilesystemWriter::create");
26
        }
27
28 9
        return $this->save($filePath, $config);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->save($filePath, $config) targeting BitWasp\Bitcoind\Config\FilesystemWriter::save() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
29
    }
30
}
31