Completed
Pull Request — master (#178)
by ignace nyamagana
40:39
created

Validator::validateInteger()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 3
1
<?php
2
/**
3
* This file is part of the League.csv library
4
*
5
* @license http://opensource.org/licenses/MIT
6
* @link https://github.com/thephpleague/csv/
7
* @version 8.1.1
8
* @package League.csv
9
*
10
* For the full copyright and license information, please view the LICENSE
11
* file that was distributed with this source code.
12
*/
13
namespace League\Csv\Config;
14
15
use InvalidArgumentException;
16
17
/**
18
 *  A trait to configure and check CSV file and content
19
 *
20
 * @package League.csv
21
 * @since  6.0.0
22
 *
23
 */
24
trait Validator
25
{
26
    /**
27
     * Validate an integer
28
     *
29
     * @param int    $int
30
     * @param int    $minValue
31
     * @param string $errorMessage
32
     *
33
     * @throws InvalidArgumentException If the value is invalid
34
     *
35
     * @return int
36
     */
37
    protected function validateInteger($int, $minValue, $errorMessage)
38
    {
39
        if (false === ($int = filter_var($int, FILTER_VALIDATE_INT, ['options' => ['min_range' => $minValue]]))) {
40
            throw new InvalidArgumentException($errorMessage);
41
        }
42
        return $int;
43
    }
44
}
45