MessagesTrait::getMessageTemplate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 1
b 0
f 1
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Nip\Form\Traits;
4
5
/**
6
 * Trait MessagesTrait
7
 * @package Nip\Form\Traits
8
 */
9
trait MessagesTrait
10
{
11
    protected $_messages = [
12
        'error' => [],
13
    ];
14
15
    protected $_messageTemplates = [];
16
17
18
    /**
19
     * @param string $type
20
     * @return mixed
21
     */
22
    public function getMessagesType($type = 'error')
23
    {
24
        return $this->_messages[$type];
25
    }
26
27
    /**
28
     * @param $message
29
     * @param string $type
30
     * @return $this
31
     */
32
    public function addMessage($message, $type = 'error')
33
    {
34
        $this->_messages[$type][] = $message;
35
36
        return $this;
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function getMessages()
43
    {
44
        $messages = $this->_messages;
45
        $messages['error'] = $this->getErrors();
0 ignored issues
show
Bug introduced by
It seems like getErrors() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        /** @scrutinizer ignore-call */ 
46
        $messages['error'] = $this->getErrors();
Loading history...
46
47
        return $messages;
48
    }
49
50
    /**
51
     * @param string $name
52
     * @return mixed
53
     */
54
    public function getMessageTemplate($name)
55
    {
56
        return isset($this->_messageTemplates[$name]) ? $this->_messageTemplates[$name] : null;
57
    }
58
}
59