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

ArrayUtils::find()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 2
dl 0
loc 10
rs 9.4285
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
}