ValidatorAwareTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setValidator() 0 5 1
A getValidator() 0 10 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\Traits;
16
17
use Phossa2\Validate\Message\Message;
18
use Phossa2\Validate\Exception\NotFoundException;
19
use Phossa2\Validate\Interfaces\ValidatorInterface;
20
use Phossa2\Validate\Interfaces\ValidatorAwareInterface;
21
22
/**
23
 * ValidatorAwareTrait
24
 *
25
 * Implementation of ValidatorAwareInterface
26
 *
27
 * @package Phossa2\Validate
28
 * @author  Hong Zhang <[email protected]>
29
 * @see     ValidatorAwareInterface
30
 * @version 2.0.0
31
 * @since   2.0.0 added
32
 */
33
trait ValidatorAwareTrait
34
{
35
    /**
36
     * @var    ValidatorInterface
37
     * @access protected
38
     */
39
    protected $validator;
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function setValidator(ValidatorInterface $validator = null)
45
    {
46
        $this->validator = $validator;
47
        return $this;
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53
    public function getValidator()/*# : ValidatorInterface */
54
    {
55
        if (null === $this->validator) {
56
            throw new NotFoundException(
57
                Message::get(Message::VALIDATOR_NOT_FOUND, get_called_class()),
58
                Message::VALIDATOR_NOT_FOUND
59
            );
60
        }
61
        return $this->validator;
62
    }
63
}
64