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

FilesystemWriter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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