Web::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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