Background   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 37
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A format() 0 9 1
A getBackgroundShortDescription() 0 4 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
19
namespace KawaiiGherkin\Formatter;
20
21
use Behat\Gherkin\Node\BackgroundNode;
22
23
/**
24
 * @author  Jefersson Nathan  <[email protected]>
25
 * @license MIT
26
 */
27
final class Background extends AbstractFormatter
28
{
29
    private $align;
30
31
    /**
32
     * @param string $align
33
     */
34 1
    public function __construct($align = Step::ALIGN_TO_RIGHT)
35
    {
36 1
        $this->align = $align;
37 1
    }
38
39
    /**
40
     * @param BackgroundNode $background
41
     *
42
     * @return string
43
     */
44 1
    public function format(BackgroundNode $background)
45
    {
46 1
        $shortDesc = $this->getBackgroundShortDescription($background) . "\n";
47
48 1
        $step  = new Step($this->align);
49 1
        $steps = $step->format($background->getSteps());
50
51 1
        return $this->indent() . $shortDesc . $steps;
52
    }
53
54
    /**
55
     * @param BackgroundNode $background
56
     *
57
     * @return string
58
     */
59 1
    private function getBackgroundShortDescription(BackgroundNode $background)
60
    {
61 1
        return trim(sprintf('%s: %s', trim($background->getKeyword()), trim($background->getTitle())));
62
    }
63
}
64