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

PlaceholderReplacer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Bex\Behat\ScreenshotExtension\Service;
4
5
use Behat\Behat\EventDispatcher\Event\AfterScenarioTested;
6
7
class PlaceholderReplacer
8
{
9
    /**
10
     * @var array
11
     */
12
    private $placeholders;
13
    
14
    /**
15
     * @param array $placeholders
16
     */
17
    public function __construct(array $placeholders = [])
18
    {
19
        $this->placeholders = $placeholders;
20
    }
21
22
    /**
23
     * @param string $text
24
     * @param AfterScenarioTested $event
25
     *
26
     * @return string
27
     */
28
    public function replaceAll($text, AfterScenarioTested $event)
29
    {
30
        foreach ($this->placeholders as $placeholder) {
31
            if (strpos($text, $placeholder->getKey()) !== false) {
32
                $text = str_replace($placeholder->getKey(), $placeholder->getValue($event), $text);
33
            }
34
        }
35
36
        return $text;
37
    }
38
}
39