Completed
Push — master ( 9d78f0...b09679 )
by Florin
14:38 queued 44s
created

Files::getFiles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Makehappen\AutoMinifier;
4
5
class Files
6
{
7
    /**
8
     * Get files to minify and concatenate
9
     *
10
     * @return array
11
     */
12
    public function getFiles($strFilesFolder)
13
    {
14
        // abort if folder not found
15
        if (!is_dir($strFilesFolder)) {
16
            return [];
17
        }
18
19
        // get all files
20
        return scandir($strFilesFolder);
21
    }
22
23
    /**
24
     * Save Cache Bust
25
     *
26
     * @var string $strApplicationFileContents
27
     * @var string $strCacheBustFile
28
     * @return null
29
     */
30
    public function saveCacheBust($strApplicationFileContents = '', $strCacheBustFile = '')
31
    {
32
        // get contents signature
33
        $strNewCacheBust = md5($strApplicationFileContents);
34
35
        // get prior cache bust
36
        $strPriorCacheBust = $this->getCacheBust($strCacheBustFile);
37
38
        // if unchanged, stop here
39
        if ($strPriorCacheBust == $strNewCacheBust) {
40
            return $strPriorCacheBust;
41
        }
42
43
        // set new cache bust
44
        file_put_contents($strCacheBustFile, $strNewCacheBust);
45
46
        // return new cache bust
47
        return $strNewCacheBust;
48
    }
49
50
51
    /**
52
     * Get Cache Bust
53
     *
54
     * @var string $strCacheBustFile
55
     * @return bool|string
56
     */
57
    public function getCacheBust($strCacheBustFile = '')
58
    {
59
        // abort if file not found
60
        if (!file_exists($strCacheBustFile)) {
61
            return '';
62
        }
63
64
        // get cache bust file contents
65
        return file_get_contents($strCacheBustFile);
66
    }
67
}
68