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

CirrusSearch::search()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 15
rs 10
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\Infrastructure;
12
13
/**
14
 * Dirty.
15
 * Class CirrusSearch
16
 *
17
 * @package App\Infrastructure
18
 */
19
class CirrusSearch
20
{
21
    /**
22
     * todo REFAC : move to API library
23
     *
24
     * @param string $url
25
     *
26
     * @return array
27
     */
28
    public function search(string $url): array
29
    {
30
        $json = file_get_contents($url);
31
32
        $myArray = json_decode($json, true);
33
        $result = $myArray['query']['search'];
34
        if (empty($result)) {
35
            return [];
36
        }
37
38
        foreach ($result as $res) {
39
            $titles[] = trim($res['title']);
40
        }
41
42
        return $titles;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $titles seems to be defined by a foreach iteration on line 38. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
43
    }
44
}
45