Completed
Pull Request — master (#10)
by Tomáš
06:04 queued 03:12
created

FilesystemWriter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 29
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A write() 0 10 2
1
<?php
2
3
/*
4
 * This file is a part of Sculpin.
5
 *
6
 * (c) Dragonfly Development Inc.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Symplify\PHP7_Sculpin\Output;
13
14
use Symfony\Component\Filesystem\Filesystem;
15
16
final class FilesystemWriter
17
{
18
    /**
19
     * @var Filesystem
20
     */
21
    private $filesystem;
22
23
    /**
24
     * @var string
25
     */
26
    private $outputDir;
27
28 1
    public function __construct(Filesystem $filesystem, string $outputDir)
29
    {
30 1
        $this->filesystem = $filesystem;
31 1
        $this->outputDir = $outputDir;
32 1
    }
33
34 1
    public function write(SourceOutput $output)
35
    {
36 1
        $outputPath = $this->outputDir.'/'.$output->permalink()->relativeFilePath();
37 1
        if ($output->hasFileReference()) {
38 1
            $this->filesystem->copy($output->file(), $outputPath, true);
0 ignored issues
show
Documentation introduced by
$output->file() is of type object<SplFileInfo>|null, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
        } else {
40
            $this->filesystem->mkdir(dirname($outputPath));
41
            file_put_contents($outputPath, $output->formattedContent());
42
        }
43 1
    }
44
}
45