Completed
Push — master ( ff82ae...111118 )
by Paweł
02:07
created

PostQuery::findOne()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
/**
3
 * Created for IG Client.
4
 * User: jakim <[email protected]>
5
 * Date: 23.03.2018
6
 */
7
8
namespace Jakim\Query;
9
10
11
use Jakim\Base\Query;
12
use jakim\ig\Endpoint;
13
use Jakim\Mapper\MediaDetails;
14
use Jakim\Model\Post;
15
16
class PostQuery extends Query
17
{
18
    protected $mediaDetailsMapper;
19
20
    public function __construct($httpClient, MediaDetails $mediaDetailsMapper = null)
21
    {
22
        parent::__construct($httpClient);
23
        $this->mediaDetailsMapper = $mediaDetailsMapper ?: new MediaDetails();
24
    }
25
26
    public function findOne(string $shortCode): Post
27
    {
28
        $url = Endpoint::mediaDetails($shortCode);
29
        $data = $this->fetchContentAsArray($url);
30
31
        $data = $this->mediaDetailsMapper->normalizeData(Post::class, $data);
32
33
        return $this->mediaDetailsMapper->populate(Post::class, $data);
34
    }
35
}