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

FeatureFilePath::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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