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 |
||
16 | class EMTTretQuote extends EMTTret |
||
17 | { |
||
18 | /** |
||
19 | * Базовые параметры тофа |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | public $title = "Кавычки"; |
||
24 | |||
25 | |||
26 | public $rules = array( |
||
27 | 'quotes_outside_a' => array( |
||
28 | 'description' => 'Кавычки вне тэга <a>', |
||
29 | //'pattern' => '/(\<%%\_\_.+?\>)\"(.+?)\"(\<\/%%\_\_.+?\>)/s', |
||
|
|||
30 | 'pattern' => '/(\<%%\_\_[^\>]+\>)\"(.+?)\"(\<\/%%\_\_[^\>]+\>)/s', |
||
31 | 'replacement' => '"\1\2\3"' |
||
32 | ), |
||
33 | |||
34 | 'open_quote' => array( |
||
35 | 'description' => 'Открывающая кавычка', |
||
36 | 'pattern' => '/(^|\(|\s|\>|-)((\"|\\\")+)(\S+)/iue', |
||
37 | 'replacement' => '$m[1] . str_repeat(self::QUOTE_FIRS_OPEN, substr_count($m[2],"\"") ) . $m[4]' |
||
38 | ), |
||
39 | 'close_quote' => array( |
||
40 | 'description' => 'Закрывающая кавычка', |
||
41 | 'pattern' => '/([a-zа-яё0-9]|\.|\&hellip\;|\!|\?|\>|\)|\:|\+|\%|\@|\#|\$|\*)((\"|\\\")+)(\.|\&hellip\;|\;|\:|\?|\!|\,|\s|\)|\<\/|\<|$)/uie', |
||
42 | 'replacement' => '$m[1] . str_repeat(self::QUOTE_FIRS_CLOSE, substr_count($m[2],"\"") ) . $m[4]' |
||
43 | ), |
||
44 | 'close_quote_adv' => array( |
||
45 | 'description' => 'Закрывающая кавычка особые случаи', |
||
46 | //'pattern' => '/([a-zа-яё0-9]|\.|\&hellip\;|\!|\?|\>|\)|\:)((\"|\\\"|\«\;)+)(\<.+?\>)(\.|\&hellip\;|\;|\:|\?|\!|\,|\s|\)|\<\/|$)/uie', |
||
47 | 'pattern' => |
||
48 | array( |
||
49 | '/([a-zа-яё0-9]|\.|\&hellip\;|\!|\?|\>|\)|\:|\+|\%|\@|\#|\$|\*)((\"|\\\"|\«\;)+)(\<[^\>]+\>)(\.|\&hellip\;|\;|\:|\?|\!|\,|\)|\<\/|$| )/uie', |
||
50 | '/([a-zа-яё0-9]|\.|\&hellip\;|\!|\?|\>|\)|\:|\+|\%|\@|\#|\$|\*)(\s+)((\"|\\\")+)(\s+)(\.|\&hellip\;|\;|\:|\?|\!|\,|\)|\<\/|$| )/uie', |
||
51 | '/\>(\«\;)\.($|\s|\<)/ui', |
||
52 | '/\>(\«\;),($|\s|\<|\S)/ui', |
||
53 | '/\>(\«\;):($|\s|\<|\S)/ui', |
||
54 | '/\>(\«\;);($|\s|\<|\S)/ui', |
||
55 | '/\>(\«\;)\)($|\s|\<|\S)/ui', |
||
56 | '/((\"|\\\")+)$/uie', |
||
57 | ), |
||
58 | 'replacement' => |
||
59 | array( |
||
60 | '$m[1] . str_repeat(self::QUOTE_FIRS_CLOSE, substr_count($m[2],"\"")+substr_count($m[2],"«") ) . $m[4]. $m[5]', |
||
61 | '$m[1] .$m[2]. str_repeat(self::QUOTE_FIRS_CLOSE, substr_count($m[3],"\"")+substr_count($m[3],"«") ) . $m[5]. $m[6]', |
||
62 | '>».\2', |
||
63 | '>»,\2', |
||
64 | '>»:\2', |
||
65 | '>»;\2', |
||
66 | '>»)\2', |
||
67 | 'str_repeat(self::QUOTE_FIRS_CLOSE, substr_count($m[1],"\"") )', |
||
68 | ), |
||
69 | ), |
||
70 | 'open_quote_adv' => array( |
||
71 | 'description' => 'Открывающая кавычка особые случаи', |
||
72 | 'pattern' => '/(^|\(|\s|\>)(\"|\\\")(\s)(\S+)/iue', |
||
73 | 'replacement' => '$m[1] . self::QUOTE_FIRS_OPEN .$m[4]' |
||
74 | ), |
||
75 | 'close_quote_adv_2' => array( |
||
76 | 'description' => 'Закрывающая кавычка последний шанс', |
||
77 | 'pattern' => '/(\S)((\"|\\\")+)(\.|\&hellip\;|\;|\:|\?|\!|\,|\s|\)|\<\/|\<|$)/uie', |
||
78 | 'replacement' => '$m[1] . str_repeat(self::QUOTE_FIRS_CLOSE, substr_count($m[2],"\"") ) . $m[4]' |
||
79 | ), |
||
80 | 'quotation' => array( |
||
81 | 'description' => 'Внутренние кавычки-лапки и дюймы', |
||
82 | 'function' => 'build_sub_quotations' |
||
83 | ), |
||
84 | ); |
||
85 | |||
86 | protected function inject_in($pos, $text, &$thetext) |
||
90 | |||
91 | protected function build_sub_quotations() |
||
192 | } |
||
193 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.