Completed
Push — master ( a9adfd...b66e97 )
by Kevin
02:14
created

Groundskeeper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 58
ccs 26
cts 26
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A clean() 0 15 1
A getOptions() 0 4 1
A configureOptions() 0 20 2
1
<?php
2
3
namespace Groundskeeper;
4
5
use Groundskeeper\Tokens\Tokenizer;
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
8
class Groundskeeper
9
{
10
    /** @var array */
11
    private $options;
12
13
    /**
14
     * Constructor
15
     */
16 16
    public function __construct(array $options = array())
17
    {
18 16
        $resolver = new OptionsResolver();
19 16
        $this->configureOptions($resolver);
20
21 16
        $this->options = $resolver->resolve($options);
22 11
    }
23
24 10
    public function clean($html)
25
    {
26
        // Tokenize
27 10
        $tokenizer = new Tokenizer($this->options);
28 10
        $tokens = $tokenizer->tokenize($html);
29
30
        // Clean
31
32
        // Output
33
        $outputClassName = 'Groundskeeper\\Output\\' .
34 10
            ucfirst($this->options['output']);
35 10
        $output = new $outputClassName();
36
37 10
        return $output->printTokens($tokens);
38
    }
39
40 1
    public function getOptions()
41
    {
42 1
        return $this->options;
43
    }
44
45 16
    protected function configureOptions(OptionsResolver $resolver)
46
    {
47
        // Set default options.
48 16
        $resolver->setDefaults(array(
49 16
            'indent-spaces' => 4,
50 16
            'output' => 'compact',
51
            'throw-on-error' => false
52 16
        ));
53
54
        // Validation
55 16
        $resolver->setAllowedValues('indent-spaces', function ($value) {
56 16
            if (!is_int($value)) {
57 1
                return false;
58
            }
59
60 15
            return $value >= 0;
61 16
        });
62 16
        $resolver->setAllowedValues('output', array('compact', 'pretty'));
63 16
        $resolver->setAllowedTypes('throw-on-error', 'bool');
64 16
    }
65
}
66