ValidatorTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 0
cbo 2
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateConfiguration() 0 8 2
A validateResponseCode() 0 6 3
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