CacheStamp::cacheStamp()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 13
rs 10
ccs 6
cts 7
cp 0.8571
cc 3
nc 4
nop 1
crap 3.0261
1
<?php
2
3
namespace mQueue\View\Helper;
4
5
use Zend_View_Helper_Abstract;
6
7
class CacheStamp extends Zend_View_Helper_Abstract
8
{
9
    /**
10
     * Inject the last modified time of file.
11
     * This avoid browser cache and force reloading when the file changed.
12
     *
13
     * @param string $fileName
14
     *
15
     * @return string
16
     */
17 13
    public function cacheStamp($fileName)
18
    {
19
        // In development, use non minified version
20 13
        if (APPLICATION_ENV == 'development') {
21
            $fileName = str_replace('/js/min/', '/js/', $fileName);
22
        }
23
24 13
        $fullPath = APPLICATION_PATH . '/../public/' . $fileName;
25 13
        if (is_file($fullPath)) {
26 13
            $fileName = $this->view->serverUrl() . $this->view->baseUrl($fileName) . '?' . filemtime($fullPath);
27
        }
28
29 13
        return $fileName;
30
    }
31
}
32