ValidatorTrait::validateResponseCode()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 3
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Vinelab\UrlShortener\Validators;
4
5
use Vinelab\UrlShortener\Exceptions\MissingConfigurationException;
6
use Vinelab\UrlShortener\Exceptions\ResponseErrorException;
7
8
/**
9
 * Class ValidatorTrait holds the basic shared validators across all drivers.
10
 *
11
 * @category Validator Trait
12
 *
13
 * @author  Mahmoud Zalt <[email protected]>
14
 */
15
trait ValidatorTrait
16
{
17
    /**
18
     * validate the input parameter in the config file is not missed.
19
     *
20
     * @param $parameter
21
     *
22
     * @return mixed
23
     *
24
     * @throws \Vinelab\UrlShortener\Validators\MissingConfigurationException
25
     */
26
    public function validateConfiguration($parameter)
27
    {
28
        if (!$parameter) {
29
            throw new MissingConfigurationException("Missing the configuration ($parameter).");
30
        }
31
32
        return $parameter;
33
    }
34
35
    /**
36
     * validate response is OK (200).
37
     *
38
     * @param $code
39
     *
40
     * @throws \Vinelab\UrlShortener\Validators\ResponseErrorException
41
     */
42
    public function validateResponseCode($code)
43
    {
44
        if (!$code || $code != '200') {
45
            throw new ResponseErrorException("Response is not OK! Response code = $code");
46
        }
47
    }
48
}
49