Passed
Push — master ( b14536...d7fcc2 )
by Paweł
03:55
created

LocationQuery::findTopPosts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * Created for IG Client.
4
 * User: jakim <[email protected]>
5
 * Date: 2019-02-26
6
 */
7
8
namespace Jakim\Query;
9
10
11
use Jakim\Base\Query;
12
use jakim\ig\Endpoint;
13
use Jakim\Mapper\ExploreLocations;
14
use Jakim\Model\Location;
15
use Jakim\Model\Post;
16
use Jakim\Model\Tag;
17
18
class LocationQuery extends Query
19
{
20
    protected $exploreLocationsMapper;
21
22
    public function __construct($httpClient, ExploreLocations $exploreLocationsMapper = null)
23
    {
24
        parent::__construct($httpClient);
25
        $this->exploreLocationsMapper = $exploreLocationsMapper ?? new ExploreLocations();
26
    }
27
28
    public function findOne(string $id): Location
29
    {
30
        $url = Endpoint::exploreLocations($id);
31
        $data = $this->fetchContentAsArray($url);
32
33
        $this->throwEmptyContentExceptionIfEmpty($data);
34
35
        $data = $this->exploreLocationsMapper->normalizeData(Location::class, $data);
36
37
        return $this->exploreLocationsMapper->populate(Location::class, $data);
38
    }
39
40
    public function findTopPosts(string $id)
41
    {
42
        $url = Endpoint::exploreLocations($id);
43
        $data = $this->fetchContentAsArray($url);
44
45
        $this->throwEmptyContentExceptionIfEmpty($data);
46
47
        $items = $this->exploreLocationsMapper->normalizeData(Post::class, $data);
48
        foreach ($items as $item) {
49
            yield $this->exploreLocationsMapper->populate(Post::class, $item);
50
        }
51
    }
52
}