Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
IsSubnetOf
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 evaluate
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Validator;
15
16/**
17 * Is subnet of validator class
18 *
19 * @category   Pop
20 * @package    Pop\Validator
21 * @author     Nick Sagona, III <dev@nolainteractive.com>
22 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
23 * @license    http://www.popphp.org/license     New BSD License
24 * @version    3.2.0
25 */
26class IsSubnetOf extends AbstractValidator
27{
28
29    /**
30     * Method to evaluate the validator
31     *
32     * @param  mixed $input
33     * @throws Exception
34     * @return boolean
35     */
36    public function evaluate($input = null)
37    {
38        // Check to make sure the input is a valid Ipv4 address.
39        if (!(new Ipv4())->evaluate($input)) {
40            throw new Exception('The IP address must be a valid IPv4 address.');
41        }
42
43        // Set the input, if passed
44        if (null !== $input) {
45            $this->input = $input;
46        }
47
48        // Set the default message
49        if (null === $this->message) {
50            $this->message = 'The value must be part of the subnet ' . $this->value . '.';
51        }
52
53        return (substr($this->input, 0, strrpos($this->input, '.')) == $this->value);
54    }
55
56}