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

Groundskeeper::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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