Passed
Branch dev (1a31b5)
by Dispositif
03:03
created

ArticleFromURL::process()   B

Complexity

Conditions 10
Paths 10

Size

Total Lines 64
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 10
eloc 41
c 3
b 1
f 0
nc 10
nop 0
dl 0
loc 64
rs 7.6666

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
//use App\Application\PublisherAction;
13
//use App\Domain\Models\Wiki\ArticleOrLienBriseInterface;
14
//use App\Domain\WikiTemplateFactory;
15
//use Exception;
16
//use Throwable;
17
//
18
///**
19
// * news URL to {{Article}}.
20
// * Class ArticleFromURL
21
// *
22
// * @package App\Application\Examples
23
// */
24
//class ArticleFromURL
25
//{
26
//    private $publisherAction;
27
//    /**
28
//     * @var ArticleOrLienBriseInterface|null
29
//     */
30
//    private $article;
31
//    /**
32
//     * @var string
33
//     */
34
//    private $url;
35
//
36
//    public function __construct(PublisherAction $publisher)
37
//    {
38
//        $this->publisherAction = $publisher;
39
//        $this->url = $publisher->getUrl();
40
//        try {
41
//            $this->article = $this->process();
42
//        } catch (Exception $e) {
43
//            dump($e);
44
//            die;
45
//        }
46
//    }
47
//
48
//    /**
49
//     * @throws Exception
50
//     */
51
//    private function process(): ?ArticleOrLienBriseInterface
52
//    {
53
//        $mapper = PublisherMapperFactory::fromURL($this->url);
54
//        if (!$mapper) {
55
//            return null;
56
//        }
57
//        sleep(10);
58
//        $arrayLD = [];
59
//        try {
60
//            $html = $this->publisherAction->getHTMLSource();
61
//            $htmlData = $this->publisherAction->extractWebData($html);
62
//        } catch (Throwable $e) {
63
//            if (strpos($e->getMessage(), '404 Not Found') !== false
64
//                || strpos($e->getMessage(), '410 Gone') !== false
65
//            ) {
66
//                dump('****** lien brisé !!!!');
67
//                $lienBrise = WikiTemplateFactory::create('lien brisé');
68
//                $lienBrise->hydrate(
69
//                    [
70
//                        'url' => $this->url,
71
//                        'titre' => 'Article de presse',
72
//                        'brisé le' => date('d-m-Y'),
73
//                    ],
74
//                    true
75
//                );
76
//
77
//                return $lienBrise; // ok
78
//            }
79
//            echo "*** Erreur ".$e->getMessage()."\n";
80
//
81
//            return null;
82
//        }
83
//
84
//        if (empty($htmlData)) {
85
//            echo "*** Pas de data Json-LD ou meta\n";
86
//
87
//            return null;
88
//        }
89
//        $htmlData['url'] = $this->url;
90
//
91
//        try {
92
//            $articleData = $mapper->process($htmlData);
93
//        } catch (Throwable $e) {
94
//            echo sprintf(
95
//                "SKIP : %s %s:%s \n",
96
//                $e->getMessage(),
97
//                $e->getFile(),
98
//                $e->getLine()
99
//            );
100
//
101
//            return null;
102
//        }
103
//
104
//        if (!empty($articleData) && !empty($articleData['titre'])) {
105
//            $article = WikiTemplateFactory::create('article');
106
//            $article->hydrate($articleData, true);
107
//            if (!$article->hasParamValue('lire en ligne')) {
108
//                $article->setParam('lire en ligne', $this->url);
109
//            }
110
//
111
//            return $article; // ok
112
//        }
113
//
114
//        return null;
115
//    }
116
//
117
//    public function getResult(): ?ArticleOrLienBriseInterface
118
//    {
119
//        return $this->article;
120
//    }
121
//
122
//}
123