Util::containsUrl()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
rs 9.4285
ccs 6
cts 6
cp 1
cc 3
eloc 6
nc 4
nop 2
crap 3
1
<?php
2
3
namespace Rj\FrontendBundle\Util;
4
5
class Util
6
{
7
    /**
8
     * @param string $subject
9
     *
10
     * @return bool
11
     */
12 7
    public static function containsNotUrl($subject)
13
    {
14 7
        return static::containsUrl($subject, true);
15
    }
16
17
    /**
18
     * @param string $subject
19
     * @param bool   $negate
20
     *
21
     * @return bool
22
     */
23 29
    public static function containsUrl($subject, $negate = false)
24
    {
25 29
        if (is_string($subject)) {
26 2
            $subject = [$subject];
27
        }
28
29 29
        $flags = $negate ? PREG_GREP_INVERT : null;
30
31 29
        $result = preg_grep('|^(https?:)?//|', $subject, $flags);
32
33 29
        return !empty($result);
34
    }
35
}
36