ColorsAdapter::colour()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
1
<?php
2
3
namespace PhpSchool\PSX;
4
5
use Colors\Color;
6
use Colors\NoStyleFoundException;
7
8
/**
9
 * Class ColorsAdapter
10
 * @package PhpSchool\PSX
11
 * @author Aydin Hassan <[email protected]>
12
 */
13
class ColorsAdapter implements ColourAdapterInterface
14
{
15
    /**
16
     * @var Color
17
     */
18
    private $color;
19
20
    /**
21
     * @param Color $color
22
     */
23
    public function __construct(Color $color)
24
    {
25
        $this->color = $color;
26
    }
27
28
    /**
29
     * @param string $string
30
     * @param string $colour
31
     *
32
     * @return string
33
     */
34
    public function colour($string, $colour)
35
    {
36
        try {
37
            return $this->color->__invoke($string)
38
                ->apply($colour)
39
                ->__toString();
40
        } catch (NoStyleFoundException $e) {
41
            return $string;
42
        }
43
    }
44
}
45