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

TextFileWriter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 2
Metric Value
wmc 4
c 2
b 1
f 2
lcom 1
cbo 3
dl 0
loc 37
ccs 0
cts 17
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A writeFile() 0 5 1
A writeFileToDisk() 0 4 1
A validateFile() 0 4 1
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
}