Passed
Push — dev ( 043eb4...bf3609 )
by Dispositif
06:23
created

PublisherMapperFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromURL() 0 17 5
1
<?php
2
/**
3
 * This file is part of dispositif/wikibot application
4
 * 2019 © Philippe M. <[email protected]>
5
 * For the full copyright and MIT license information, please view the LICENSE file.
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Domain\Publisher;
11
12
/**
13
 * Class PublisherMapperFactory
14
 *
15
 * @package App\Domain\Publisher
16
 */
17
class PublisherMapperFactory
18
{
19
    /**
20
     * @param $url
21
     *
22
     * @return MapperInterface|null
23
     */
24
    public static function fromURL(string $url): ?MapperInterface
25
    {
26
        if (preg_match('#^https?://(www\.)?lemonde\.fr/[^ ]+$#i', $url)) {
27
            return new LeMondeMapper();
28
        }
29
        if (preg_match('#^https?://(www\.)?lefigaro\.fr/[^ ]+$#i', $url)) {
30
            return new FigaroMapper();
31
        }
32
        if (preg_match('#^https?://(www\.)?liberation\.fr/[^ ]+$#i', $url)) {
33
            return new LiberationMapper();
34
        }
35
        if (preg_match('#^https?://(www\.)?la-croix\.com/[^ ]+$#i', $url)) {
36
            return new LaCroixMapper();
37
        }
38
39
40
        return null;
41
    }
42
}
43