Completed
Pull Request — master (#365)
by Alessandro
03:29
created

SymfonyProxy   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 72.21%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 55
ccs 13
cts 18
cp 0.7221
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCacheDir() 0 9 4
A clear() 0 18 3
A start() 0 4 1
A stop() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCache package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\HttpCache\Test\Proxy;
13
14
/**
15
 * Controls the Symfony HttpCache proxy server.
16
 *
17
 * SYMFONY_CACHE_DIR directory to use for cache
18
 *                   (default sys_get_temp_dir() + '/foshttpcache-symfony')
19
 */
20
class SymfonyProxy implements ProxyInterface
21
{
22
    /**
23
     * Get Symfony cache directory.
24
     *
25
     * @return string
26
     */
27 6
    public function getCacheDir()
28
    {
29 6
        $path = defined('SYMFONY_CACHE_DIR') ? SYMFONY_CACHE_DIR : sys_get_temp_dir().'/foshttpcache-symfony';
30 6
        if (!$path || '/' === $path) {
31 1
            throw new \RuntimeException('Invalid test setup, the cache dir is '.$path);
32
        }
33
34 5
        return $path;
35
    }
36
37
    /**
38
     * Start the proxy server.
39
     */
40
    public function start()
41
    {
42
        $this->clear();
43
    }
44
45
    /**
46
     * Stop the proxy server.
47
     */
48
    public function stop()
49
    {
50
        // nothing to do
51
    }
52
53
    /**
54
     * Clear all cached content from the proxy server.
55
     */
56 5
    public function clear()
57
    {
58 5
        $path = realpath($this->getCacheDir());
59
60
        // false means the directory does not exist yet - it surely is empty then
61 5
        if (!is_dir($path)) {
62 1
            return;
63
        }
64
65 4
        $path = $this->getCacheDir();
66 4
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
67
            // @codeCoverageIgnoreStart
68
            system('DEL /S '.$path);
69
        } else {
70
            // @codeCoverageIgnoreEnd
71 4
            system('rm -r '.$path);
72
        }
73 4
    }
74
}
75