NameFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 27
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A getIterator() 8 8 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This program is free software. It comes without any warranty, to
4
 * the extent permitted by applicable law. You can redistribute it
5
 * and/or modify it under the terms of the Do What The Fuck You Want
6
 * To Public License, Version 2, as published by Sam Hocevar. See
7
 * http://www.wtfpl.net/ for more details.
8
 */
9
10
declare(strict_types = 1);
11
12
namespace hanneskod\classtools\Iterator\Filter;
13
14
use hanneskod\classtools\Iterator\ClassIterator;
15
use hanneskod\classtools\Iterator\Filter;
16
17
/**
18
 * Filter classes based on name
19
 *
20
 * @author Hannes Forsgård <[email protected]>
21
 */
22 View Code Duplication
final class NameFilter extends ClassIterator implements Filter
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
{
24
    use FilterTrait;
25
26
    /**
27
     * @var string Regular expression for matching definition names
28
     */
29
    private $pattern;
30
31
    /**
32
     * Register matching regular expression
33
     */
34
    public function __construct(string $pattern)
35
    {
36
        parent::__construct();
37
        $this->pattern = $pattern;
38
    }
39
40
    public function getIterator(): iterable
41
    {
42
        foreach ($this->getBoundIterator() as $className => $reflectedClass) {
43
            if (preg_match($this->pattern, $className)) {
44
                yield $className => $reflectedClass;
45
            }
46
        }
47
    }
48
}
49