GumpValidator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 47
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 2
A filter() 0 5 1
A getError() 0 4 1
A getGump() 0 7 2
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Validate
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Validate;
16
17
use Phossa2\Shared\Base\ObjectAbstract;
18
use Phossa2\Validate\Interfaces\ValidatorInterface;
19
20
/**
21
 * GumpValidator
22
 *
23
 * Validator using "wixel/gump"
24
 *
25
 * @package Phossa2\Validate
26
 * @author  Hong Zhang <[email protected]>
27
 * @version 2.0.0
28
 * @since   2.0.0 added
29
 */
30
class GumpValidator extends ObjectAbstract implements ValidatorInterface
31
{
32
    /**
33
     * @var    \GUMP
34
     * @access protected
35
     */
36
    protected $gump;
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function validate(array $data, array $rules)/*# : bool */
42
    {
43
        $data = $this->getGump()->sanitize($data);
44
        return true === $this->getGump()->validate($data, $rules) ?
45
            true : false;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51
    public function filter(array $data, array $rules)/*# : array */
52
    {
53
        $data = $this->getGump()->sanitize($data);
54
        return $this->getGump()->filter($data, $rules);
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function getError()/*# : array */
61
    {
62
        return $this->getGump()->get_errors_array();
63
    }
64
65
    /**
66
     * @return \GUMP
67
     * @access protected
68
     */
69
    protected function getGump()/*# : Gump */
70
    {
71
        if (null === $this->gump) {
72
            $this->gump = new \GUMP();
73
        }
74
        return $this->gump;
75
    }
76
}
77