GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BetweenValidator::validateField()   C
last analyzed

Complexity

Conditions 8
Paths 12

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 16
nc 12
nop 3
1
<?php
2
3
/**
4
 * This file is part of the PHPMongo package.
5
 *
6
 * (c) Dmytro Sokil <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sokil\Mongo\Validator;
13
14
use Sokil\Mongo\Structure;
15
16
/**
17
 * Validates value between specified
18
 *
19
 * @author Dmytro Sokil <[email protected]>
20
 */
21
class BetweenValidator extends \Sokil\Mongo\Validator
22
{
23
24
    public function validateField(Structure $document, $fieldName, array $params)
25
    {
26
        $value = $document->get($fieldName);
27
        if (!$value) {
28
            return;
29
        }
30
31
        if (!isset($params['min'])) {
32
            throw new Exception('Minimum value of range not specified');
33
        }
34
        
35
        if (!isset($params['max'])) {
36
            throw new Exception('Maximum value of range not specified');
37
        }
38
        
39
        if ($value < $params['min']) {
40
            if (empty($params['minMessage'])) {
41
                $params['minMessage'] = 'Field "' . $fieldName . '" less than minimal value of range in ' . get_called_class();
42
            }
43
            $document->addError($fieldName, $this->getName(), $params['minMessage']);
44
        }
45
        
46
        if ($value > $params['max']) {
47
            if (empty($params['maxMessage'])) {
48
                $params['maxMessage'] = 'Field "' . $fieldName . '" less than minimal value of range in ' . get_called_class();
49
            }
50
            $document->addError($fieldName, $this->getName(), $params['maxMessage']);
51
        }
52
    }
53
}
54