File   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 65
ccs 14
cts 14
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A extension() 0 4 1
A exists() 0 4 1
A contents() 0 8 2
A get() 0 8 2
A put() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of Payload.
5
 *
6
 * (c) DraperStudio <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace DraperStudio\Payload\Utils;
13
14
use DraperStudio\Payload\Exceptions\FileDoesNotExistException;
15
16
/**
17
 * Class File.
18
 */
19
class File
20
{
21
    /**
22
     * @param $path
23
     *
24
     * @return mixed
25
     */
26 45
    public static function extension($path)
27
    {
28 45
        return pathinfo($path, PATHINFO_EXTENSION);
29
    }
30
31
    /**
32
     * @param $path
33
     *
34
     * @return bool
35
     */
36 39
    public static function exists($path)
37
    {
38 39
        return file_exists($path);
39
    }
40
41
    /**
42
     * @param $path
43
     *
44
     * @return string
45
     *
46
     * @throws FileDoesNotExistException
47
     */
48 24
    public static function contents($path)
49
    {
50 24
        if (self::exists($path)) {
51 21
            return trim(file_get_contents($path));
52
        }
53
54 3
        throw new FileDoesNotExistException(sprintf('%s is not a valid file', $path));
55
    }
56
57
    /**
58
     * @param $path
59
     *
60
     * @return mixed
61
     *
62
     * @throws FileDoesNotExistException
63
     */
64 9
    public static function get($path)
65
    {
66 9
        if (self::exists($path)) {
67 6
            return require $path;
68
        }
69
70 3
        throw new FileDoesNotExistException(sprintf('%s is not a valid file', $path));
71
    }
72
73
    /**
74
     * @param $path
75
     * @param $contents
76
     *
77
     * @return bool
78
     */
79 24
    public static function put($path, $contents)
80
    {
81 24
        return (bool) file_put_contents($path, $contents);
82
    }
83
}
84