Completed
Push — master ( 0b908e...886262 )
by Kevin
02:30
created

Groundskeeper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 6
c 4
b 0
f 2
lcom 1
cbo 3
dl 0
loc 56
ccs 21
cts 21
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 3
A clean() 0 16 1
A getConfiguration() 0 4 1
A setLogger() 0 4 1
1
<?php
2
3
namespace Groundskeeper;
4
5
use Groundskeeper\Tokens\Tokenizer;
6
use Psr\Log\LoggerAwareInterface;
7
use Psr\Log\LoggerInterface;
8
9
class Groundskeeper implements LoggerAwareInterface
10
{
11
    /** @var Configuration */
12
    private $configuration;
13
14
    /** @var null|LoggerInterface */
15
    private $logger;
16
17
    /**
18
     * Constructor
19
     *
20
     * @param array|Configuration $options
21
     */
22 17
    public function __construct($options = array())
23
    {
24 17
        $this->logger = null;
25 17
        if ($options instanceof Configuration) {
26 2
            $this->configuration = $options;
27
28 1
            return;
29
        }
30
31 17
        if (!is_array($options)) {
32 16
            throw new \InvalidArgumentException('Invalid option type.');
33
        }
34
35 16
        $this->configuration = new Configuration($options);
36 16
    }
37
38 15
    public function clean($html)
39
    {
40
        // Tokenize
41 15
        $tokenizer = new Tokenizer($this->configuration);
42 15
        $tokenContainer = $tokenizer->tokenize($html);
43
44
        // Clean
45 15
        $tokenContainer->clean($this->logger);
46
47
        // Output
48
        $outputClassName = 'Groundskeeper\\Output\\' .
49 15
            ucfirst($this->configuration->get('output'));
50 15
        $output = new $outputClassName();
51
52 15
        return $output($tokenContainer);
53
    }
54
55 1
    public function getConfiguration()
56
    {
57 1
        return $this->configuration;
58
    }
59
60 16
    public function setLogger(LoggerInterface $logger)
61
    {
62 16
        $this->logger = $logger;
63 16
    }
64
}
65