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

ArrayUtils   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
rs 10
wmc 5
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 10 3
A isMatchedString() 0 4 2
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
}