Between   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B isValid() 0 26 3
A getMessage() 0 8 2
1
<?php
2
3
/**
4
 * @author: Abdul Qureshi. <[email protected]>
5
 * 
6
 * This file has been modified from the original source.
7
 * See original here:
8
 *
9
 * @link: https://github.com/progsmile/request-validator
10
 */
11
12
namespace TheSupportGroup\Common\Validator\Rules;
13
14
use TheSupportGroup\Common\Validator\Contracts\Rules\RuleInterface;
15
16
class Between extends BaseRule implements RuleInterface
17
{
18
    private $val1;
0 ignored issues
show
Unused Code introduced by
The property $val1 is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
    private $val2;
0 ignored issues
show
Unused Code introduced by
The property $val2 is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
20
    private $isNumeric = false;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function isValid()
26
    {
27
        if ($this->isNotRequiredAndEmpty()) {
28
            return true;
29
        }
30
31
        $values = explode(',', $this->getParams()[2]);
32
33
        $input = trim($this->getParams()[1]);
34
35
        $between = $this->Between(
0 ignored issues
show
Documentation Bug introduced by
The method Between does not exist on object<TheSupportGroup\C...alidator\Rules\Between>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
36
            trim($values[0]), // min
37
            trim($values[1]), // max
38
            true              // inclusive
39
        );
40
41
        if ($this->hasRule('numeric') !== false) {
42
            $this->isNumeric = true;
43
44
            return $between->validate($input);
45
        }
46
47
        $input = mb_strlen($input);
48
49
        return $between->validate($input);
50
    }
51
52
    /**
53
     * Returns error message from rule.
54
     *
55
     * @return string
56
     */
57
    public function getMessage()
58
    {
59
        if ($this->isNumeric) {
60
            return 'Field :field: should be between in :param: values';
61
        }
62
63
        return 'Field :field: length should be between :param: characters';
64
    }
65
}
66