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

PublisherMapperFactory::fromURL()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
nc 5
nop 1
dl 0
loc 17
rs 9.6111
c 1
b 0
f 0
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