Client::sendHttpRequest()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Movavi\Http;
4
5
use Movavi\Exception\DisallowedUrlException;
6
use Movavi\Exception\UnavailableServiceException;
7
8
/**
9
 * Class Client
10
 *
11
 * Simple Http-Client
12
 *
13
 * @package Movavi\Http
14
 */
15
class Client implements ClientInterface
16
{
17
    /**
18
     * Client constructor.
19
     *
20
     * @throws DisallowedUrlException
21
     */
22
    public function __construct()
23
    {
24
        if(!ini_get('allow_url_fopen')){
25
            throw new DisallowedUrlException();
26
        }
27
    }
28
29
    /**
30
     * Makes http-request and returns raw data
31
     *
32
     * @param string $url
33
     *
34
     * @return string
35
     *
36
     * @throws UnavailableServiceException
37
     */
38
    public function sendHttpRequest(string $url): string
39
    {
40
        if (!$content = file_get_contents($url)) {
41
            throw new UnavailableServiceException();
42
        }
43
44
        return $content;
45
    }
46
}
47