Passed
Push — master ( 03ea78...8fc551 )
by Harry
10:08
created

TableFilterer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 0 12 4
1
<?php
2
3
namespace Graze\Sprout\Parser;
4
5
class TableFilterer
6
{
7
    /**
8
     * @param string[] $tables   list of tables to filter
9
     * @param string[] $excludes List of regular expressions to filter tables based on
10
     *
11
     * @return string[] List of table with the excludes removed
12
     */
13
    public function filter(array $tables, array $excludes): array
14
    {
15
        return array_values(array_filter(
16
            $tables,
17
            function (string $table) use ($excludes) {
18
                foreach ($excludes as $regex) {
19
                    $regex = mb_substr($regex, 0, 1) === '/' ? $regex : sprintf('/^%s$/', $regex);
20
                    if (preg_match($regex, $table)) {
21
                        return false;
22
                    }
23
                }
24
                return true;
25
            }
26
        ));
27
    }
28
}
29