Issues (14)

src/Messages/AbstractMessage.php (4 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Prozorov\DataVerification\Messages;
6
7
use Prozorov\DataVerification\App\Configuration;
0 ignored issues
show
The type Prozorov\DataVerification\App\Configuration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Prozorov\DataVerification\Models\Code;
9
use Prozorov\DataVerification\Types\Address;
10
11
abstract class AbstractMessage
12
{
13
    /**
14
     * @var string $template
15
     */
16
    protected $template;
17
18
    /**
19
     * @var string $transportCode
20
     */
21
    protected $transportCode;
22
23
    /**
24
     * @var Address $address
25
     */
26
    protected $address;
27
28
    /**
29
     * @var string $code
30
     */
31
    protected $code;
32
33
    /**
34
     * via.
35
     *
36
     * @access	public
37
     * @param	string	$code	
38
     * @return	AbstractMessage
39
     */
40 5
    public function via(string $code): AbstractMessage
41
    {
42 5
        $this->transportCode = $code;
43
44 5
        return $this;
45
    }
46
47
    /**
48
     * getTransportCode.
49
     *
50
     * @access	public
51
     * @return	string
52
     */
53 1
    public function getTransportCode(): string
54
    {
55 1
        return (string) $this->transportCode;
56
    }
57
58
    /**
59
     * setCode.
60
     *
61
     * @access	public
62
     * @param	Code	$code	
63
     * @return	AbstractMessage
64
     */
65 3
    public function setCode(Code $code): AbstractMessage
66
    {
67 3
        $this->code = $code;
0 ignored issues
show
Documentation Bug introduced by
It seems like $code of type Prozorov\DataVerification\Models\Code is incompatible with the declared type string of property $code.

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...
68
69 3
        return $this;
70
    }
71
72
    /**
73
     * getCode.
74
     *
75
     * @access	public
76
     * @return	Code
77
     */
78 3
    public function getCode(): Code
79
    {
80 3
        if (empty($this->code)) {
81
            throw new \InvalidArgumentException('Не установлен одноразовый пароль');
82
        }
83
84 3
        return $this->code;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->code returns the type string which is incompatible with the type-hinted return Prozorov\DataVerification\Models\Code.
Loading history...
85
    }
86
87
    /**
88
     * setTemplate.
89
     *
90
     * @access	public
91
     * @param	string	$text	
92
     * @return	AbstractMessage
93
     */
94
    public function setTemplate(string $text): AbstractMessage
95
    {
96
        $this->text = $text;
0 ignored issues
show
Bug Best Practice introduced by
The property text does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
97
98
        return $this;
99
    }
100
101
    /**
102
     * getTemplate.
103
     *
104
     * @access	public
105
     * @return	string
106
     */
107 3
    public function getTemplate(): string
108
    {
109 3
        if (empty($this->template)) {
110
            throw new \InvalidArgumentException('Не установлен шаблон сообщения');
111
        }
112
113 3
        return $this->template;
114
    }
115
116
    /**
117
     * setAddress.
118
     *
119
     * @access	public
120
     * @param	Address	$address	
121
     * @return	AbstractMessage
122
     */
123 3
    public function setAddress(Address $address): AbstractMessage
124
    {
125 3
        $this->address = $address;
126
127 3
        return $this;
128
    }
129
130
    /**
131
     * getAddress.
132
     *
133
     * @access	public
134
     * @return	Address
135
     */
136 3
    public function getAddress(): Address
137
    {
138 3
        return $this->address;
139
    }
140
141
    /**
142
     * render.
143
     *
144
     * @access	public
145
     * @return	string
146
     */
147 3
    public function render(): string
148
    {
149 3
        return str_replace('#OTP#', $this->getCode()->getOneTimePass(), $this->getTemplate());
150
    }
151
}
152