TableFilterer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 10
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 5
    public function filter(array $tables, array $excludes): array
14
    {
15 5
        return array_values(array_filter(
16 5
            $tables,
17 5
            function (string $table) use ($excludes) {
18 5
                foreach ($excludes as $regex) {
19 5
                    $regex = mb_substr($regex, 0, 1) === '/' ? $regex : sprintf('/^%s$/', $regex);
20 5
                    if (preg_match($regex, $table)) {
21 5
                        return false;
22
                    }
23
                }
24 5
                return true;
25 5
            }
26
        ));
27
    }
28
}
29