StrlenMin::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 5
crap 3
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Filter\Rule\Sanitize;
10
11
use Aura\Filter\Rule\AbstractStrlen;
12
13
/**
14
 *
15
 * Sanitizes a string to a minimum length by padding it.
16
 *
17
 * @package Aura.Filter
18
 *
19
 */
20
class StrlenMin extends AbstractStrlen
21
{
22
    /**
23
     *
24
     * Sanitizes a string to a minimum length by padding it.
25
     *
26
     * @param object $subject The subject to be filtered.
27
     *
28
     * @param string $field The subject field name.
29
     *
30
     * @param int $min The minimum length.
31
     *
32
     * @param string $pad_string Pad using this string.
33
     *
34
     * @param int $pad_type A `STR_PAD_*` constant.
35
     *
36
     * @return bool True if the value was sanitized, false if not.
37
     *
38
     */
39 7
    public function __invoke($subject, $field, $min, $pad_string = ' ', $pad_type = STR_PAD_RIGHT)
40
    {
41 7
        $value = $subject->$field;
42 7
        if (! is_scalar($value)) {
43 1
            return false;
44
        }
45 6
        if ($this->strlen($value) < $min) {
46 2
            $subject->$field = $this->strpad($value, $min, $pad_string, $pad_type);
47
        }
48 6
        return true;
49
    }
50
}
51