ColorsAdapter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A colour() 0 10 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