FilesystemWriter::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
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