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 |
||
11 | class FetchEntity |
||
12 | { |
||
13 | /** |
||
14 | * @param array|object $jobData |
||
15 | * @throws \InvalidArgumentException |
||
16 | */ |
||
17 | 1 | View Code Duplication | public function __construct($jobData = []) |
29 | |||
30 | /** @var string */ |
||
31 | public $uri = ""; |
||
|
|||
32 | |||
33 | /** @var string */ |
||
34 | public $destPath = ''; |
||
35 | |||
36 | /** @var bool */ |
||
37 | public $extract = false; |
||
38 | |||
39 | /** @var bool */ |
||
40 | public $cache = false; |
||
41 | |||
42 | /** @var bool */ |
||
43 | public $executable = false; |
||
44 | } |
||
45 |
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.