Client::setParameter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace FipeApi;
4
use FipeApi\Constants\FipeApiParameter;
5
6
/**
7
 * Class Client
8
 *
9
 * @package FipeApi
10
 */
11
class Client
12
{
13
14
    /**
15
     * URL padrão
16
     */
17
    const DEFAULT_URL = "http://fipeapi.appspot.com/api/1";
18
19
    /**
20
     * Timeout padrão
21
     */
22
    const DEFAULT_TIMEOUT = 10;
23
24
    /**
25
     * Client constructor.
26
     *
27
     * @param array|null $params
28
     * @throws \Exception
29
     */
30
    public function __construct(array $params = null)
31
    {
32
33
        if(!is_null($params))
34
        {
35
            foreach ($params as $key => $param)
36
            {
37
                if(!in_array($key, array_keys($params)))
38
                    throw new \Exception(sprintf("Parâmetro %s inválido", $key));
39
            }
40
        }
41
42
        putenv(sprintf("%s=%s", FipeApiParameter::FIPE_API_HOST, Client::DEFAULT_URL));
43
        putenv(sprintf("%s=%s", FipeApiParameter::FIPE_API_TIMEOUT, Client::DEFAULT_TIMEOUT));
44
45
        if(!is_null($params) && is_array($params))
46
            foreach ($params as $key => $value)
47
                putenv(sprintf("%s=%s",$key,$value));
48
49
    }
50
51
    /**
52
     * @param FipeApiParameter $key
53
     * @param string $value
54
     */
55
    public function setParameter($key, $value)
56
    {
57
        putenv(sprintf("%s=%s",$key,$value));
58
    }
59
60
    /**
61
     * @param FipeApiParameter $key
62
     * @return string
63
     */
64
    public function getParameter($key)
65
    {
66
        return getenv($key);
67
    }
68
69
}