Completed
Push — master ( 5b8d73...30d679 )
by Adam
21:09
created

File::exists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace BestServedCold\PhalueObjects;
2
3
class File extends ValueObject
4
{
5
    protected $checkExists = true;
6
    protected $timeout;
7
    protected $mustExist;
8
9 1
    public function __construct($value, $mustExist = true, $timeout = 10)
10
    {
11 1
        parent::__construct($value);
12 1
        $this->timeout = $timeout;
13 1
        $this->mustExist = $mustExist;
14 1
    }
15
16
    /**
17
     * @return bool
18
     */
19
    public function exists()
0 ignored issues
show
Coding Style introduced by
function exists() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
20
    {
21
        return file_exists($this->getValue());
22
    }
23
24
    /**
25
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|false?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
26
     */
27
    public function getContents()
28
    {
29
        return ! $this->mustExist || $this->exists()
30
            ? file_get_contents($this->getValue())
31
            : false;
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function getExtension()
38
    {
39
        return pathinfo($this->getValue(), PATHINFO_EXTENSION);
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getDirectoryName()
46
    {
47
        return pathinfo($this->getValue(), PATHINFO_DIRNAME);
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getFileName()
54
    {
55
        return pathinfo($this->getValue(), PATHINFO_FILENAME);
56
    }
57
58
    /**
59
     * @param string $string
60
     * @return static
61
     */
62
    public static function fromString($string)
63
    {
64
        return new static($string);
65
    }
66
}
67