FilesystemWriter::save()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 2
dl 0
loc 8
ccs 5
cts 6
cp 0.8333
crap 3.0416
rs 9.4285
c 0
b 0
f 0
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