Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
15 | class DatabaseManager |
||
16 | { |
||
17 | use Injector; |
||
18 | |||
19 | /** |
||
20 | * @var ConnectionManager コネクションマネージャ |
||
21 | */ |
||
22 | private $connectionManager; |
||
23 | |||
24 | /** |
||
25 | * @var DatabaseDriver データベースコネクション |
||
26 | */ |
||
27 | private $connection; |
||
28 | |||
29 | /** |
||
30 | * @var Query クエリオブジェクト |
||
31 | */ |
||
32 | private $query; |
||
33 | |||
34 | /** |
||
35 | * @var Logger ロガー |
||
36 | */ |
||
37 | private $logger; |
||
38 | |||
39 | /** |
||
40 | * constructor |
||
41 | * @param Container 依存コンテナ |
||
42 | */ |
||
43 | public function __construct(Container $container) |
||
48 | |||
49 | /** |
||
50 | * destructor |
||
51 | */ |
||
52 | public function __destruct() |
||
56 | |||
57 | /** |
||
58 | * データベース接続する |
||
59 | * すでに接続中であれば再接続はしない |
||
60 | */ |
||
61 | public function connect() |
||
71 | |||
72 | /** |
||
73 | * データベース切断する |
||
74 | */ |
||
75 | public function disconnect() |
||
92 | |||
93 | /** |
||
94 | * トランザクションを開始する |
||
95 | * @param int $isolationLevel トランザクション分離レベル |
||
96 | */ |
||
97 | public function beginTransaction(int $isolationLevel) |
||
122 | |||
123 | /** |
||
124 | * コミットする |
||
125 | */ |
||
126 | View Code Duplication | public function commit() |
|
146 | |||
147 | /** |
||
148 | * ロールバックする |
||
149 | */ |
||
150 | View Code Duplication | public function rollback() |
|
170 | |||
171 | /** |
||
172 | * ロールバックが発生したかどうか |
||
173 | * @return boolean ロールバックが発生したかどうか |
||
174 | */ |
||
175 | public function isRollback() |
||
179 | |||
180 | /** |
||
181 | * トランザクション内かどうか |
||
182 | * @return boolean トランザクション内かどうか |
||
183 | */ |
||
184 | public function inTransaction() |
||
188 | |||
189 | /** |
||
190 | * DB接続されているか |
||
191 | * @param boolean 接続有無 |
||
192 | */ |
||
193 | public function isConnected() |
||
197 | |||
198 | /** |
||
199 | * トランザクション分離レベルを返却する |
||
200 | * @return int トランザクション分離レベル |
||
201 | */ |
||
202 | public function getTransactionIsolation() |
||
206 | |||
207 | /** |
||
208 | * データベース接続が可能かどうか |
||
209 | * @param string Modelファイルパス |
||
210 | * @return boolean 接続可否 |
||
211 | */ |
||
212 | public function loadConnection($filepath) |
||
221 | |||
222 | /** |
||
223 | * クエリを設定する |
||
224 | * @param string SQL |
||
225 | * @param array<string> パラメータ |
||
226 | */ |
||
227 | public function query($sql, array $bind = []) |
||
237 | } |
||
238 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.