Issues (138)

src/Traits/MessagesTrait.php (1 issue)

Labels
Severity
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
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