WebResource::fetchContent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of sitemap-common.
4
 *
5
 * (c) 2016 Daniele Moraschi
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace SiteMap\Http;
12
13
use GuzzleHttp\ClientInterface;
14
15
class WebResource implements HttpResource
16
{
17
18
    /**
19
     * @var Url  $url
20
     */
21
    private $url;
22
23
    /**
24
     * @var mixed
25
     */
26
    private $content;
27
28
    /**
29
     * @var ClientInterface
30
     */
31
    private $httpClient;
32
33
    /**
34
     * WebResource constructor.
35
     *
36
     * @var Url  $url
37
     * @var ClientInterface  $client
38
     */
39
    public function __construct(Url $url, ClientInterface $httpClient)
40
    {
41
        $this->url = $url;
42
        $this->httpClient = $httpClient;
43
    }
44
45
    /**
46
     * @return Url
47
     */
48
    public function getURI()
49
    {
50
        return $this->url;
51
    }
52
53
    /**
54
     * @return string
55
     * @throws \Exception
56
     */
57
    public function getContent()
58
    {
59
        if (! $this->content) {
60
            $this->content = (string) $this->fetchContent();
61
        }
62
63
        return $this->content;
64
    }
65
66
    /**
67
     * @return mixed
68
     * @throws \Exception
69
     */
70
    private function fetchContent()
71
    {
72
        $response = $this->httpClient->get($this->getURI()->getWebUrl());
73
        return $response->getBody(true);
74
    }
75
76
}