Completed
Push — master ( b66e97...9d450b )
by Kevin
02:16
created

Groundskeeper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 6
c 3
b 0
f 2
lcom 1
cbo 2
dl 0
loc 49
ccs 17
cts 20
cp 0.85
rs 10

3 Methods

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