Completed
Push — master ( 9340bd...1c40df )
by Park Jong-Hun
05:35
created

ArrayUtils::isMatchedString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Core\Utils;
4
5
class ArrayUtils
6
{
7
    public static function find(array $arr, $str)
8
    {
9
        foreach ($arr as $item) {
10
            if(self::isMatchedString($item, $str)) {
11
                return $item;
12
            }
13
        }
14
15
        return false;
16
    }
17
18
    private static function isMatchedString($str1, $str2) {
19
        return preg_match(sprintf('/^%s$/', str_replace('*', '.*', str_replace('.', '\.', $str1))), $str2)
20
            || preg_match(sprintf('/^%s$/', str_replace('*', '.*', str_replace('.', '\.', $str2))), $str1);
21
    }
22
}