AbstractValidator::addMessage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of slick/validator package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Validator;
11
12
/**
13
 * AbstractValidator
14
 *
15
 * @package Slick\Validator
16
 * @author  Filipe Silva <[email protected]>
17
 */
18
abstract class AbstractValidator
19
{
20
21
    /**
22
     * @var mixed The value to evaluate
23
     */
24
    protected $value;
25
26
    /**
27
     * @readwrite
28
     * @var array
29
     */
30
    protected $message = '';
31
32
    /**
33
     * @var array Error messages templates
34
     */
35
    protected $messageTemplate = '';
36
37
    /**
38
     * Returns an array of messages that explain why the most recent
39
     * isValid() call returned false. The array keys are validation failure
40
     * message identifiers, and the array values are the corresponding
41
     * human-readable message strings.
42
     *
43
     * @return array
44
     */
45 22
    public function getMessage()
46
    {
47 22
        return $this->message;
48
    }
49
50
    /**
51
     * Sets a custom message for a given identifier
52
     *
53
     * @param string $message
54
     *
55
     * @return AbstractValidator
56
     */
57 4
    public function setMessage($message)
58
    {
59 4
        $this->messageTemplate = $message;
0 ignored issues
show
Documentation Bug introduced by
It seems like $message of type string is incompatible with the declared type array of property $messageTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60 4
        return $this;
61
    }
62
63
    /**
64
     * Adds a message using a template.
65
     *
66
     * @param string $template Message template.
67
     *
68
     * @return AbstractValidator
69
     */
70 34
    protected function addMessage($template)
0 ignored issues
show
Unused Code introduced by
The parameter $template is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72 34
        $arguments = func_get_args();
73 34
        $template = $arguments[0];
74
75 34
        $arguments[0] = $template;
76
77 34
        $this->message = sizeof($arguments) > 1
0 ignored issues
show
Documentation Bug introduced by
It seems like sizeof($arguments) > 1 ?...s->message = $template) of type * is incompatible with the declared type array of property $message.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
78 34
            ? call_user_func_array('sprintf', $arguments)
79 34
            : $this->message = $template;
80
81 34
        return $this;
82
    }
83
84
}
85