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

LeMondeMapper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 19 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
11
namespace App\Domain\Publisher;
12
13
use DateTime;
14
15
/**
16
 * Class LeMondeMapper
17
 *
18
 * @package App\Domain\Publisher
19
 */
20
class LeMondeMapper extends WebMapper
21
{
22
    public function process($data): array
23
    {
24
        if(!isset($data['JSON-LD'])) {
25
            return [];
26
        }
27
        $ld = $data['JSON-LD'];
28
29
        if ($ld && isset($ld['@type']) && 'NewsArticle' !== $ld['@type']) {
30
            throw new \Exception('not NewsArticle');
31
        }
32
33
        return [
34
            //            'langue' => 'fr',
35
            'périodique' => '[[Le Monde]]',
36
            'titre' => trim(html_entity_decode($ld['headline'])),
37
            'lire en ligne' => $ld['mainEntityOfPage']['@id'],
38
            'auteur1' =>  $data['meta']['og:article:author'] ?? null,
39
            // ['meta']['og:article:content_tier'] === 'free'
40
            'date' => $this->convertDate($ld['datePublished']), // 2020-03-20T04:31:07+01:00
41
        ];
42
    }
43
44
}
45