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

File   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 8
c 4
b 2
f 0
lcom 1
cbo 1
dl 0
loc 55
ccs 0
cts 28
cp 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A exists() 0 4 1
A getContents() 0 4 2
A getExtension() 0 4 1
A getDirectoryName() 0 4 1
A getFileName() 0 4 1
A fromString() 0 4 1
A fromUrl() 0 4 1
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