Completed
Push — master ( e52bc4...ec0ffa )
by Adam
03:07
created

File::getExtension()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
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
    /**
6
     * @return bool
7
     */
8
    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...
9
    {
10
        return file_exists($this->getValue());
11
    }
12
13
    /**
14
     * @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...
15
     */
16
    public function getContents()
17
    {
18
        return $this->exists() ? file_get_contents($this->getValue()) : false;
19
    }
20
21
    /**
22
     * @return string
23
     */
24
    public function getExtension()
25
    {
26
        return pathinfo($this->getValue(), PATHINFO_EXTENSION);
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getDirectoryName()
33
    {
34
        return pathinfo($this->getValue(), PATHINFO_DIRNAME);
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getFileName()
41
    {
42
        return pathinfo($this->getValue(), PATHINFO_FILENAME);
43
    }
44
45
    /**
46
     * @param string $string
47
     */
48
    public static function fromString($string)
49
    {
50
        return new static($string);
51
    }
52
53
    public static function fromUrl($url)
54
    {
55
        return self::fromString(file_get_contents($url));
56
    }
57
}
58