BundleFeatureLocator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getLocatorExamples() 0 6 1
A locateSpecifications() 0 16 3
1
<?php
2
3
/*
4
 * This file is part of the Behat Symfony2Extension
5
 *
6
 * (c) Konstantin Kudryashov <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Behat\Symfony2Extension\Specification;
13
14
use Behat\Symfony2Extension\Suite\SymfonyBundleSuite;
15
use Behat\Testwork\Specification\Locator\SpecificationLocator;
16
use Behat\Testwork\Specification\NoSpecificationsIterator;
17
use Behat\Testwork\Suite\Suite;
18
19
/**
20
 * @author Christophe Coevoet <[email protected]>
21
 */
22
final class BundleFeatureLocator implements SpecificationLocator
23
{
24
    /**
25
     * SpecificationLocator
26
     */
27
    private $baseLocator;
28
29
    /**
30
     * Initializes locator.
31
     *
32
     * @param SpecificationLocator $baseLocator
33
     */
34
    public function __construct(SpecificationLocator $baseLocator)
35
    {
36
        $this->baseLocator = $baseLocator;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getLocatorExamples()
43
    {
44
        return array(
45
            "a Symfony2 bundle path <comment>(@BundleName/)</comment>"
46
        );
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function locateSpecifications(Suite $suite, $locator)
53
    {
54
        if (!$suite instanceof SymfonyBundleSuite) {
55
            return new noSpecificationsIterator($suite);
56
        }
57
58
        $bundle = $suite->getBundle();
59
60
        if (0 !== strpos($locator, '@' . $bundle->getName())) {
61
            return new NoSpecificationsIterator($suite);
62
        }
63
64
        $locatorSuffix = substr($locator, strlen($bundle->getName()) + 1);
65
66
        return $this->baseLocator->locateSpecifications($suite, $bundle->getPath() . '/Features' . $locatorSuffix);
67
    }
68
}
69