ChainRegexpResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 26
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addResolver() 0 7 2
A getRegexp() 0 11 3
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\ReferenceResolver;
4
5
use Kaliop\eZMigrationBundle\API\Exception\MigrationBundleException;
6
use Kaliop\eZMigrationBundle\API\ReferenceResolverInterface;
7
8
class ChainRegexpResolver extends ChainResolver implements RegexpBasedResolverInterface
9
{
10
    public function addResolver(ReferenceResolverInterface $resolver)
11
    {
12
        if (!$resolver instanceof RegexpBasedResolverInterface) {
13
            throw new MigrationBundleException("Can not add resolver of class " . get_class($resolver) . " to a chain regexp resolver");
14
        }
15
16
        parent::addResolver($resolver);
17
    }
18
19
    /**
20
     * NB: assumes that all the resolvers we chain use '/' as delimiter...
21
     * @return string
22
     */
23
    public function getRegexp()
24
    {
25
        $regexps = array();
26
        /** @var RegexpBasedResolverInterface $resolver */
27
        foreach ($this->resolvers as $resolver) {
28
            $regexp = substr($resolver->getRegexp(), 1, -1);
0 ignored issues
show
Bug introduced by
The method getRegexp() does not exist on Kaliop\eZMigrationBundle...erenceResolverInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Kaliop\eZMigrationBundle...nceResolverBagInterface or Kaliop\eZMigrationBundle...nceResolverBagInterface or Kaliop\eZMigrationBundle...eResolver\ChainResolver. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
            $regexp = substr($resolver->/** @scrutinizer ignore-call */ getRegexp(), 1, -1);
Loading history...
29
            if ($regexp !== '') {
30
                $regexps[] = $regexp;
31
            }
32
        }
33
        return '/(' . implode(')|(', $regexps) . '))/';
34
    }
35
}
36