Completed
Push — master ( e81671...a22352 )
by André
93:06 queued 73:42
created

MailToHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 14 4
A getOptionsResolver() 0 11 1
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Bundle\EzPublishCoreBundle\URLChecker\Handler;
8
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
11
class MailToHandler extends AbstractURLHandler
12
{
13
    const MAILTO_PATTERN = '/^mailto:(.+)@([^?]+)(\\?.*)?$/';
14
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function validate(array $urls)
19
    {
20
        if (!$this->options['enabled']) {
21
            return;
22
        }
23
24
        foreach ($urls as $url) {
25
            if (preg_match(self::MAILTO_PATTERN, $url->url, $matches)) {
26
                $host = trim($matches[2]);
27
28
                $this->setUrlStatus($url, checkdnsrr($host, 'MX'));
29
            }
30
        }
31
    }
32
33
    /**
34
     * Returns options resolver.
35
     *
36
     * @return OptionsResolver
37
     */
38
    protected function getOptionsResolver()
39
    {
40
        $resolver = new OptionsResolver();
41
        $resolver->setDefaults([
42
            'enabled' => true,
43
        ]);
44
45
        $resolver->setAllowedTypes('enabled', 'bool');
46
47
        return $resolver;
48
    }
49
}
50