Web   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 49
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createFilename() 0 3 1
A doRun() 0 13 2
A __construct() 0 4 1
A createWebFile() 0 8 1
1
<?php
2
3
/*
4
 * This file is part of CacheTool.
5
 *
6
 * (c) Samuel Gordalina <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CacheTool\Adapter;
13
14
use CacheTool\Adapter\Http\HttpInterface;
15
use CacheTool\Code;
16
17
class Web extends AbstractAdapter
18
{
19
    private $path;
20
    private $http;
21
22 5
    public function __construct($path, HttpInterface $http)
23
    {
24 5
        $this->path = realpath($path);
25 5
        $this->http = $http;
26 5
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    protected function doRun(Code $code)
32
    {
33 1
        $filename = $this->createFilename();
34 1
        $file = $this->createWebFile($filename);
35 1
        $code->writeTo($file);
36
37 1
        $content = $this->http->fetch($filename);
38
39 1
        if (!@unlink($file)) {
40
            $this->logger->debug(sprintf('Web: Could not delete file: %s', $file));
41
        }
42
43 1
        return $content;
44
    }
45
46
    /**
47
     * @param string $filename
48
     * @return string
49
     */
50 1
    protected function createWebFile($filename)
51
    {
52 1
        $file = sprintf("%s/%s", $this->path, $filename);
53
54 1
        touch($file);
55 1
        chmod($file, 0664);
56
57 1
        return $file;
58
    }
59
60
    /**
61
     * @return string
62
     */
63 1
    protected function createFilename()
64
    {
65 1
        return sprintf('cachetool-%s.php', uniqid('', true));
66
    }
67
}
68