Reader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 64
ccs 12
cts 14
cp 0.8571
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
read() 0 1 ?
A check() 0 11 2
A contents() 0 6 2
A get() 0 6 2
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\Readers;
13
14
use DraperStudio\Payload\Exceptions\InvalidFileTypeException;
15
use DraperStudio\Payload\Utils\File;
16
17
/**
18
 * Class Reader.
19
 */
20
abstract class Reader
21
{
22
    /**
23
     * @var array
24
     */
25
    protected $extensions = [];
26
27
    /**
28
     * @param $path
29
     * @param null $class
30
     *
31
     * @return mixed
32
     */
33
    abstract public function read($path, $class = null);
34
35
    /**
36
     * @param $path
37
     *
38
     * @return bool
39
     *
40
     * @throws InvalidFileTypeException
41
     */
42 42
    public function check($path)
43
    {
44 42
        $extension = File::extension($path);
45
46 42
        if (!in_array($extension, $this->extensions)) {
47 21
            throw new InvalidFileTypeException(
48 21
                sprintf('%s is an invalid file type for the %s class', $extension, get_class($this)));
49
        }
50
51 21
        return true;
52
    }
53
54
    /**
55
     * @param $path
56
     *
57
     * @return string
58
     *
59
     * @throws InvalidFileTypeException
60
     * @throws \DraperStudio\Payload\Exceptions\FileDoesNotExistException
61
     */
62 36
    public function contents($path)
63
    {
64 36
        if ($this->check($path)) {
65 18
            return File::contents($path);
66
        }
67
    }
68
69
    /**
70
     * @param $path
71
     *
72
     * @return mixed
73
     *
74
     * @throws InvalidFileTypeException
75
     * @throws \DraperStudio\Payload\Exceptions\FileDoesNotExistException
76
     */
77 6
    public function get($path)
78
    {
79 6
        if ($this->check($path)) {
80 3
            return File::get($path);
81
        }
82
    }
83
}
84