RawImageCacheService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 44
c 0
b 0
f 0
ccs 0
cts 29
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 41 6
1
<?php namespace Onigoetz\Imagecache\Support\Raw;
2
3
use Onigoetz\Imagecache\Exceptions\InvalidPresetException;
4
use Onigoetz\Imagecache\Exceptions\NotFoundException;
5
use Onigoetz\Imagecache\Manager;
6
use Onigoetz\Imagecache\Transfer;
7
8
class RawImageCacheService
9
{
10
    public static function run($config, $request)
11
    {
12
        $imagecache = new Manager($config);
13
14
        try {
15
            $final_file = $imagecache->handleRequest($request['preset'], $request['file']);
16
        } catch (InvalidPresetException $e) {
17
            header('HTTP/1.0 404 Not Found');
18
            echo $e->getMessage();
19
20
            return;
21
        } catch (NotFoundException $e) {
22
            header('HTTP/1.0 404 Not Found');
23
            echo $e->getMessage();
24
25
            return;
26
        } catch (\RuntimeException $e) {
27
            header('HTTP/1.0 500 Internal Server Error');
28
            echo $e->getMessage();
29
30
            return;
31
        }
32
33
        $transfer = new Transfer($final_file);
34
35
        // if the status is 304, we don't
36
        // need to send the content with it
37
        if ($transfer->getStatus() == 304) {
38
            header('HTTP/1.1 304 Not Modified');
39
40
            return;
41
        }
42
43
        header('HTTP/1.1 200 OK');
44
45
        foreach ($transfer->getFormattedHeaders() as $header) {
46
            header($header);
47
        }
48
49
        $transfer->stream();
50
    }
51
}
52