Completed
Push — master ( 13a1bf...61ee69 )
by Gaige
13s queued 10s
created

ManifestReader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace ExoUNX\Vasri;
5
6
7
use Illuminate\Support\Facades\File;
8
use Exception;
9
10
/**
11
 * Class ManifestReader
12
 *
13
 * @package ExoUNX\Vasri
14
 * @author  Gaige Lama <[email protected]>
15
 * @license MIT License
16
 * @link    https://github.com/ExoUNX/Vasri
17
 */
18
class ManifestReader
19
{
20
21
    /**
22
     * @var
23
     */
24
    private $mixManifest;
25
26
    /**
27
     * @var
28
     */
29
    private $vasriManifest;
30
31
    /**
32
     * ManifestReader constructor.
33
     */
34
    public function __construct()
35
    {
36
        $this->mixManifest   = public_path('mix-manifest.json');
37
        $this->vasriManifest = base_path('vasri-manifest.json');
38
    }
39
40
    /**
41
     * @param  string  $file
42
     *
43
     * @return array
44
     */
45
    private function jsonFileToArray(string $file): array
46
    {
47
        return json_decode(file_get_contents($file), true);
48
    }
49
50
    /**
51
     * @return array
52
     * @throws Exception
53
     */
54
    public function getMixManifest(): array
55
    {
56
        if (File::exists($this->mixManifest)) {
57
            return $this->jsonFileToArray($this->mixManifest);
58
        } else {
59
            throw new Exception('Incorrect file path or file does not exist for mix-manifest.json');
60
        }
61
    }
62
63
    /**
64
     * @return array
65
     * @throws Exception
66
     */
67
    public function getVasriManifest(): array
68
    {
69
        if (File::exists($this->mixManifest)) {
70
            return $this->jsonFileToArray($this->vasriManifest);
71
        } else {
72
            throw new Exception('Incorrect file path or file does not exist for vasri-manifest.json');
73
        }
74
    }
75
76
}
77