Completed
Pull Request — master (#289)
by Gavin
16:24 queued 13:47
created

SymfonyProxy   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 27.78%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 46
ccs 5
cts 18
cp 0.2778
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCacheDir() 0 4 2
A start() 0 4 1
A stop() 0 4 1
B clear() 0 14 5
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 5
    public function getCacheDir()
28
    {
29 5
        return defined('SYMFONY_CACHE_DIR') ? SYMFONY_CACHE_DIR : sys_get_temp_dir() . '/foshttpcache-symfony';
30
    }
31
32
    /**
33
     * Start the proxy server
34
     */
35
    public function start()
36
    {
37
        $this->clear();
38
    }
39
40
    /**
41
     * Stop the proxy server
42
     */
43
    public function stop()
44
    {
45
        // nothing to do
46
    }
47
48
    /**
49
     * Clear all cached content from the proxy server
50
     */
51 5
    public function clear()
52
    {
53 5
        if (is_dir($this->getCacheDir())) {
54
            $path = realpath($this->getCacheDir());
55
            if (!$this->getCacheDir() || '/' == $path) {
56
                throw new \Exception('Invalid test setup, the cache dir is ' . $path);
57
            }
58
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
59
                system('DEL /S '.$path);
60
            } else {
61
                system('rm -r '.$path);
62
            }
63
        }
64 5
    }
65
}
66