ColorsAdapter::__construct()   A
last analyzed

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 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