Generic::getXpath()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
namespace Magefix\Behat\Page\Element;
3
4
use SensioLabs\Behat\PageObjectExtension\PageObject\Element;
5
6
/**
7
 * Class Parameter
8
 * @package Magefix\Behat\Page\Element
9
 * @author  Carlo Tasca <[email protected]>
10
 */
11
abstract class Generic extends Element implements Parameterable
12
{
13
    /**
14
     * @var string
15
     */
16
    private $parameter = '';
17
18
    /**
19
     * @param $parameter
20
     */
21
    public function setParameter($parameter)
22
    {
23
        $this->parameter = $parameter;
24
    }
25
26
    /**
27
     * @return string
28
     * @throws \Exception
29
     */
30
    public function getXpath()
31
    {
32
        if (empty($this->parameter)) {
33
            throw new \Exception("Parameter not set for element Xpath");
34
        }
35
36
        $realXPath = str_replace('{parameter}', $this->parameter, $this->selector['xpath']);
37
        $this->selector = ['xpath' => $realXPath];
38
39
        return $realXPath;
40
    }
41
}
42