StaticFileResponse::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
namespace JsLocalization\Http\Responses;
3
4
use App;
5
use DateTime;
6
use Exception;
7
use Illuminate\Http\Response;
8
use Illuminate\Support\Facades\File;
9
10
class StaticFileResponse extends Response
11
{
12 3
    public function __construct($filePath)
13
    {
14 3
        parent::__construct();
15
16 3
        if (!File::isFile($filePath)) {
17 1
            throw new Exception("Cannot read file: $filePath");
18
        }
19
20 2
        $fileContent = file_get_contents($filePath);
21 2
        $this->setContent($fileContent);
22
23 2
        $lastModified = new DateTime();
24 2
        $lastModified->setTimestamp( File::lastModified($filePath) );
25
26 2
        $this->setLastModified($lastModified);
27
28 2
        $this->isNotModified(App::make('request'));
29
    }
30
}