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

LeMondeMapper::process()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
nc 3
nop 1
dl 0
loc 19
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
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