Completed
Push — master ( 17f397...dedab2 )
by Samuel
13:14 queued 11:43
created

Web::doRun()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 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 1
    public function __construct($path, HttpInterface $http)
23
    {
24 1
        $this->path = realpath($path);
25 1
        $this->http = $http;
26 1
    }
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
        @unlink($file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
40
41 1
        return $content;
42
    }
43
44
    /**
45
     * @param string $filename
46
     * @return string
47
     */
48 1
    protected function createWebFile($filename)
49
    {
50 1
        $file = sprintf("%s/%s", $this->path, $filename);
51
52 1
        touch($file);
53 1
        chmod($file, 0664);
54
55 1
        return $file;
56
    }
57
58
    /**
59
     * @return string
60
     */
61 1
    protected function createFilename()
62
    {
63 1
        return sprintf('cachetool-%s.php', uniqid());
64
    }
65
}
66