Passed
Pull Request — master (#43)
by Tibor
02:57
created

FeatureFilePath   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getKey() 0 4 1
A getValue() 0 4 1
A relativizePaths() 0 8 2
1
<?php
2
3
namespace Bex\Behat\ScreenshotExtension\Placeholder;
4
5
use Behat\Behat\EventDispatcher\Event\AfterScenarioTested;
6
use Bex\Behat\ScreenshotExtension\Placeholder\PlaceholderInterface;
7
8
class FeatureFilePath implements PlaceholderInterface
9
{
10
    const KEY = '%FEATURE_FILE_PATH%';
11
12
    /**
13
     * @var string
14
     */
15
    private $basePath;
16
    
17
    /**
18
     * @param string $basePath
19
     */
20
    public function __construct($basePath)
21
    {
22
        $this->basePath = $basePath;
23
    }
24
25
    public function getKey()
26
    {
27
        return self::KEY;   
28
    }
29
30
    public function getValue(AfterScenarioTested $event)
31
    {
32
        return $this->relativizePaths($event->getFeature()->getFile());
33
    }
34
35
    /**
36
     * Transforms path to relative.
37
     *
38
     * @param string $path
39
     *
40
     * @return string
41
     */
42
    private function relativizePaths($path)
43
    {
44
        if (!$this->basePath) {
45
            return $path;
46
        }
47
48
        return str_replace($this->basePath . DIRECTORY_SEPARATOR, '', $path);
49
    }
50
}
51