Passed
Push — master ( 98d705...005cd7 )
by Vasyl
02:07
created

Helpers::arrayWrap()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: fomvasss
5
 * Date: 07.11.18
6
 * Time: 23:22
7
 */
8
9
namespace Fomvasss\LaravelStrTokens;
10
11
12
class Helpers
13
{
14
    /**
15
     * @param $value
16
     * @return array
17
     */
18
    public static function arrayWrap($value)
19
    {
20
        if (is_null($value)) {
21
            return [];
22
        }
23
24
        return ! is_array($value) ? [$value] : $value;
25
    }
26
27
    /**
28
     * @param $pattern
29
     * @param $value
30
     * @return bool
31
     */
32
    public static function strIs($pattern, $value)
33
    {
34
        $patterns = static::arrayWrap($pattern);
35
36
        if (empty($patterns)) {
37
            return false;
38
        }
39
40
        foreach ($patterns as $pattern) {
0 ignored issues
show
introduced by
$pattern is overwriting one of the parameters of this function.
Loading history...
41
            if ($pattern == $value) {
42
                return true;
43
            }
44
45
            $pattern = preg_quote($pattern, '#');
46
47
            $pattern = str_replace('\*', '.*', $pattern);
48
49
            if (preg_match('#^'.$pattern.'\z#u', $value) === 1) {
50
                return true;
51
            }
52
        }
53
54
        return false;
55
    }
56
}