Search   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 8
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 14 2
A getRows() 0 14 4
1
<?php
2
3
/**
4
 * This file is part of Laravel Meetups.
5
 *
6
 * (c) Nuno Maduro <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace LaravelMeetups\Jobs\Catalog;
13
14
use LaravelMeetups\Contracts\Jobs\Search as Contract;
15
use LaravelMeetups\Http\Client\Catalog\Strategy;
16
use LaravelMeetups\Http\Client\Query;
17
use LaravelMeetups\Http\Client\Transporter;
18
use LaravelMeetups\Jobs\AbstractSearch;
19
20
/**
21
 * Class Search.
22
 */
23
class Search extends AbstractSearch implements Contract
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function execute()
29
    {
30
        if ($maxRadius = $this->input->getArgument('max_radius')) {
31
            $this->config->setMaxRadius($maxRadius);
32
        }
33
34
        return array_map(function ($event) {
35
            $dom = $this->dom->load($event->innerHtml);
36
37
            return new Bag(clone $dom, array_map(function ($elem) use ($dom) {
38
                return (new $elem())->find($dom);
39
            }, $this->config->getCatalogProviders()));
40
        }, $this->getRows());
41
    }
42
43
    /**
44
     * Returns the catalog in rows.
45
     *
46
     * @return array
47
     */
48
    private function getRows()
49
    {
50
        $radius = $this->config->getRadiusInterval();
51
        $rows = [];
52
53
        while ($radius < $this->config->getMaxRadius()) {
54
            $this->config->setRadius($radius);
55
            $body = (new Transporter())->execute(new Query(new Strategy($this->config)));
56
            $rows = $this->dom->load($body)->getElementsByClass('event-listing-container-li') ?: [];
57
            $radius += $this->config->getRadiusInterval();
58
        }
59
60
        return is_array($rows) ? $rows : $rows->toArray();
61
    }
62
}
63