Completed
Push — master ( b30e53...9fbf6c )
by Victor
01:55
created

TextFileWriter::writeFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Victor Ribeiro <[email protected]>
5
 * Date: 10/04/16
6
 */
7
8
namespace LazyEight\DiTesto;
9
10
11
use LazyEight\DiTesto\Validator\TextFileWriterValidator;
12
use LazyEight\DiTesto\ValueObject\File;
13
14
class TextFileWriter
15
{
16
    /**
17
     * @var File
18
     */
19
    protected $file;
20
21
    /**
22
     * @param File $file
23
     */
24
    public function __construct(File $file)
25
    {
26
        $this->file = clone $file;
27
    }
28
29
    /**
30
     * write file to disk
31
     */
32
    public function writeFile()
33
    {
34
        $this->validateFile();
35
        $this->writeFileToDisk();
36
    }
37
38
    protected function writeFileToDisk()
39
    {
40
        file_put_contents($this->file->getLocation()->getValue());
41
    }
42
43
    /**
44
     * @return bool
45
     */
46
    protected function validateFile()
47
    {
48
        return (new TextFileWriterValidator($this->file))->validate();
0 ignored issues
show
Compatibility introduced by
$this->file of type object<LazyEight\DiTesto\ValueObject\File> is not a sub-type of object<LazyEight\DiTesto...ject\TextFile\TextFile>. It seems like you assume a child class of the class LazyEight\DiTesto\ValueObject\File to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
49
    }
50
}