PathSanityCheck   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 29
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A looksLikeRegularExpression() 0 15 5
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle 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\HttpCacheBundle\Command;
13
14
use FOS\HttpCache\Exception\InvalidArgumentException;
15
16
trait PathSanityCheck
17
{
18
    /**
19
     * Check if the path looks like a regular expression.
20
     *
21
     * A sane path is non-empty and and contains no characters that are usually
22
     * found in regular expressions: does not start with ^ or end with $ and
23
     * does not contain the patterns .* or .+ or ().
24
     *
25
     * @param string $path
26
     *
27
     * @return bool Whether the path looks like it could be a regular expression
28
     */
29 12
    private function looksLikeRegularExpression($path)
30
    {
31 12
        if (strlen($path) < 1) {
32
            throw new InvalidArgumentException('Path to invalidate can not be empty. To invalidate the root path, use "/"');
33
        }
34
35 12
        if ('^' === $path[0]
36 11
            || '$' === substr($path, -1)
37 12
            || preg_match('/(\.[\*\+]|\(|\))/', $path)
38
        ) {
39 3
            return true;
40
        }
41
42 9
        return false;
43
    }
44
}
45