1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This file is part of the Lazzard/ftp-bridge package. |
||
5 | * |
||
6 | * (c) El Amrani Chakir <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Lazzard\FtpBridge\Response; |
||
13 | |||
14 | /** |
||
15 | * Represents an FTP replay. |
||
16 | * |
||
17 | * @since 1.0 |
||
18 | * @author El Amrani Chakir <[email protected]> |
||
19 | */ |
||
20 | class Response |
||
21 | { |
||
22 | /** @var string */ |
||
23 | protected $raw; |
||
24 | |||
25 | /** @var int */ |
||
26 | protected $code; |
||
27 | |||
28 | /** @var string */ |
||
29 | protected $message; |
||
30 | |||
31 | /** @var bool */ |
||
32 | protected $multiline; |
||
33 | |||
34 | /** |
||
35 | * @param string $reply The raw FTP reply string. |
||
36 | */ |
||
37 | public function __construct($reply) |
||
38 | { |
||
39 | $parser = new ResponseParser($reply); |
||
40 | $response = $parser->parseToArray(); |
||
41 | |||
42 | $this->raw = $reply; |
||
43 | $this->code = $response['code']; |
||
0 ignored issues
–
show
|
|||
44 | $this->message = $response['message']; |
||
45 | $this->multiline = $response['multiline']; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Gets the raw (original) reply string sent by the server. |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getRaw() |
||
54 | { |
||
55 | return $this->raw; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Gets reply code. |
||
60 | * |
||
61 | * @return int |
||
62 | */ |
||
63 | public function getCode() |
||
64 | { |
||
65 | return $this->code; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Gets reply message. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getMessage() |
||
74 | { |
||
75 | return $this->message; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Whether the FTP response consists of multiple lines or not. |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | public function isMultiline() |
||
84 | { |
||
85 | return $this->multiline; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function hasCode() |
||
92 | { |
||
93 | return in_array($this->getCode(), func_get_args(), false); |
||
94 | } |
||
95 | } |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.