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:
Complex classes like Markdown often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Markdown, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Markdown implements MarkdownInterface { |
||
17 | /** |
||
18 | * Define the package version |
||
19 | * @var string |
||
20 | */ |
||
21 | const MARKDOWNLIB_VERSION = "1.8.0"; |
||
22 | |||
23 | /** |
||
24 | * Simple function interface - Initialize the parser and return the result |
||
25 | * of its transform method. This will work fine for derived classes too. |
||
26 | * |
||
27 | * @api |
||
28 | * |
||
29 | * @param string $text |
||
30 | * @return string |
||
31 | */ |
||
32 | 107 | public static function defaultTransform($text) { |
|
48 | |||
49 | /** |
||
50 | * Configuration variables |
||
51 | */ |
||
52 | |||
53 | /** |
||
54 | * Change to ">" for HTML output. |
||
55 | * @var string |
||
56 | */ |
||
57 | public $empty_element_suffix = " />"; |
||
58 | |||
59 | /** |
||
60 | * The width of indentation of the output markup |
||
61 | * @var int |
||
62 | */ |
||
63 | public $tab_width = 4; |
||
64 | |||
65 | /** |
||
66 | * Change to `true` to disallow markup or entities. |
||
67 | * @var boolean |
||
68 | */ |
||
69 | public $no_markup = false; |
||
70 | public $no_entities = false; |
||
71 | |||
72 | |||
73 | /** |
||
74 | * Change to `true` to enable line breaks on \n without two trailling spaces |
||
75 | * @var boolean |
||
76 | */ |
||
77 | public $hard_wrap = false; |
||
78 | |||
79 | /** |
||
80 | * Predefined URLs and titles for reference links and images. |
||
81 | * @var array |
||
82 | */ |
||
83 | public $predef_urls = array(); |
||
84 | public $predef_titles = array(); |
||
85 | |||
86 | /** |
||
87 | * Optional filter function for URLs |
||
88 | * @var callable |
||
89 | */ |
||
90 | public $url_filter_func = null; |
||
91 | |||
92 | /** |
||
93 | * Optional header id="" generation callback function. |
||
94 | * @var callable |
||
95 | */ |
||
96 | public $header_id_func = null; |
||
97 | |||
98 | /** |
||
99 | * Optional function for converting code block content to HTML |
||
100 | * @var callable |
||
101 | */ |
||
102 | public $code_block_content_func = null; |
||
103 | |||
104 | /** |
||
105 | * Optional function for converting code span content to HTML. |
||
106 | * @var callable |
||
107 | */ |
||
108 | public $code_span_content_func = null; |
||
109 | |||
110 | /** |
||
111 | * Class attribute to toggle "enhanced ordered list" behaviour |
||
112 | * setting this to true will allow ordered lists to start from the index |
||
113 | * number that is defined first. |
||
114 | * |
||
115 | * For example: |
||
116 | * 2. List item two |
||
117 | * 3. List item three |
||
118 | * |
||
119 | * Becomes: |
||
120 | * <ol start="2"> |
||
121 | * <li>List item two</li> |
||
122 | * <li>List item three</li> |
||
123 | * </ol> |
||
124 | * |
||
125 | * @var bool |
||
126 | */ |
||
127 | public $enhanced_ordered_list = false; |
||
128 | |||
129 | /** |
||
130 | * Parser implementation |
||
131 | */ |
||
132 | |||
133 | /** |
||
134 | * Regex to match balanced [brackets]. |
||
135 | * Needed to insert a maximum bracked depth while converting to PHP. |
||
136 | * @var int |
||
137 | */ |
||
138 | protected $nested_brackets_depth = 6; |
||
139 | protected $nested_brackets_re; |
||
140 | |||
141 | protected $nested_url_parenthesis_depth = 4; |
||
142 | protected $nested_url_parenthesis_re; |
||
143 | |||
144 | /** |
||
145 | * Table of hash values for escaped characters: |
||
146 | * @var string |
||
147 | */ |
||
148 | protected $escape_chars = '\`*_{}[]()>#+-.!'; |
||
149 | protected $escape_chars_re; |
||
150 | |||
151 | /** |
||
152 | * Constructor function. Initialize appropriate member variables. |
||
153 | * @return void |
||
|
|||
154 | */ |
||
155 | 2 | public function __construct() { |
|
174 | |||
175 | |||
176 | /** |
||
177 | * Internal hashes used during transformation. |
||
178 | * @var array |
||
179 | */ |
||
180 | protected $urls = array(); |
||
181 | protected $titles = array(); |
||
182 | protected $html_hashes = array(); |
||
183 | |||
184 | /** |
||
185 | * Status flag to avoid invalid nesting. |
||
186 | * @var boolean |
||
187 | */ |
||
188 | protected $in_anchor = false; |
||
189 | |||
190 | /** |
||
191 | * Status flag to avoid invalid nesting. |
||
192 | * @var boolean |
||
193 | */ |
||
194 | protected $in_emphasis_processing = false; |
||
195 | |||
196 | /** |
||
197 | * Called before the transformation process starts to setup parser states. |
||
198 | * @return void |
||
199 | */ |
||
200 | 107 | protected function setup() { |
|
208 | |||
209 | /** |
||
210 | * Called after the transformation process to clear any variable which may |
||
211 | * be taking up memory unnecessarly. |
||
212 | * @return void |
||
213 | */ |
||
214 | 107 | protected function teardown() { |
|
219 | |||
220 | /** |
||
221 | * Main function. Performs some preprocessing on the input text and pass |
||
222 | * it through the document gamut. |
||
223 | * |
||
224 | * @api |
||
225 | * |
||
226 | * @param string $text |
||
227 | * @return string |
||
228 | */ |
||
229 | 107 | public function transform($text) { |
|
263 | |||
264 | /** |
||
265 | * Define the document gamut |
||
266 | * @var array |
||
267 | */ |
||
268 | protected $document_gamut = array( |
||
269 | // Strip link definitions, store in hashes. |
||
270 | "stripLinkDefinitions" => 20, |
||
271 | "runBasicBlockGamut" => 30, |
||
272 | ); |
||
273 | |||
274 | /** |
||
275 | * Strips link definitions from text, stores the URLs and titles in |
||
276 | * hash references |
||
277 | * @param string $text |
||
278 | * @return string |
||
279 | */ |
||
280 | 48 | View Code Duplication | protected function stripLinkDefinitions($text) { |
312 | |||
313 | /** |
||
314 | * The callback to strip link definitions |
||
315 | * @param array $matches |
||
316 | * @return string |
||
317 | */ |
||
318 | 9 | protected function _stripLinkDefinitions_callback($matches) { |
|
325 | |||
326 | /** |
||
327 | * Hashify HTML blocks |
||
328 | * @param string $text |
||
329 | * @return string |
||
330 | */ |
||
331 | 48 | protected function hashHTMLBlocks($text) { |
|
478 | |||
479 | /** |
||
480 | * The callback for hashing HTML blocks |
||
481 | * @param string $matches |
||
482 | * @return string |
||
483 | */ |
||
484 | 9 | protected function _hashHTMLBlocks_callback($matches) { |
|
489 | |||
490 | /** |
||
491 | * Called whenever a tag must be hashed when a function insert an atomic |
||
492 | * element in the text stream. Passing $text to through this function gives |
||
493 | * a unique text-token which will be reverted back when calling unhash. |
||
494 | * |
||
495 | * The $boundary argument specify what character should be used to surround |
||
496 | * the token. By convension, "B" is used for block elements that needs not |
||
497 | * to be wrapped into paragraph tags at the end, ":" is used for elements |
||
498 | * that are word separators and "X" is used in the general case. |
||
499 | * |
||
500 | * @param string $text |
||
501 | * @param string $boundary |
||
502 | * @return string |
||
503 | */ |
||
504 | 107 | protected function hashPart($text, $boundary = 'X') { |
|
515 | |||
516 | /** |
||
517 | * Shortcut function for hashPart with block-level boundaries. |
||
518 | * @param string $text |
||
519 | * @return string |
||
520 | */ |
||
521 | 107 | protected function hashBlock($text) { |
|
524 | |||
525 | /** |
||
526 | * Define the block gamut - these are all the transformations that form |
||
527 | * block-level tags like paragraphs, headers, and list items. |
||
528 | * @var array |
||
529 | */ |
||
530 | protected $block_gamut = array( |
||
531 | "doHeaders" => 10, |
||
532 | "doHorizontalRules" => 20, |
||
533 | "doLists" => 40, |
||
534 | "doCodeBlocks" => 50, |
||
535 | "doBlockQuotes" => 60, |
||
536 | ); |
||
537 | |||
538 | /** |
||
539 | * Run block gamut tranformations. |
||
540 | * |
||
541 | * We need to escape raw HTML in Markdown source before doing anything |
||
542 | * else. This need to be done for each block, and not only at the |
||
543 | * begining in the Markdown function since hashed blocks can be part of |
||
544 | * list items and could have been indented. Indented blocks would have |
||
545 | * been seen as a code block in a previous pass of hashHTMLBlocks. |
||
546 | * |
||
547 | * @param string $text |
||
548 | * @return string |
||
549 | */ |
||
550 | 20 | protected function runBlockGamut($text) { |
|
554 | |||
555 | /** |
||
556 | * Run block gamut tranformations, without hashing HTML blocks. This is |
||
557 | * useful when HTML blocks are known to be already hashed, like in the first |
||
558 | * whole-document pass. |
||
559 | * |
||
560 | * @param string $text |
||
561 | * @return string |
||
562 | */ |
||
563 | 107 | protected function runBasicBlockGamut($text) { |
|
574 | |||
575 | /** |
||
576 | * Convert horizontal rules |
||
577 | * @param string $text |
||
578 | * @return string |
||
579 | */ |
||
580 | 107 | protected function doHorizontalRules($text) { |
|
596 | |||
597 | /** |
||
598 | * These are all the transformations that occur *within* block-level |
||
599 | * tags like paragraphs, headers, and list items. |
||
600 | * @var array |
||
601 | */ |
||
602 | protected $span_gamut = array( |
||
603 | // Process character escapes, code spans, and inline HTML |
||
604 | // in one shot. |
||
605 | "parseSpan" => -30, |
||
606 | // Process anchor and image tags. Images must come first, |
||
607 | // because ![foo][f] looks like an anchor. |
||
608 | "doImages" => 10, |
||
609 | "doAnchors" => 20, |
||
610 | // Make links out of things like `<https://example.com/>` |
||
611 | // Must come after doAnchors, because you can use < and > |
||
612 | // delimiters in inline links like [this](<url>). |
||
613 | "doAutoLinks" => 30, |
||
614 | "encodeAmpsAndAngles" => 40, |
||
615 | "doItalicsAndBold" => 50, |
||
616 | "doHardBreaks" => 60, |
||
617 | ); |
||
618 | |||
619 | /** |
||
620 | * Run span gamut transformations |
||
621 | * @param string $text |
||
622 | * @return string |
||
623 | */ |
||
624 | 106 | protected function runSpanGamut($text) { |
|
631 | |||
632 | /** |
||
633 | * Do hard breaks |
||
634 | * @param string $text |
||
635 | * @return string |
||
636 | */ |
||
637 | 106 | protected function doHardBreaks($text) { |
|
646 | |||
647 | /** |
||
648 | * Trigger part hashing for the hard break (callback method) |
||
649 | * @param array $matches |
||
650 | * @return string |
||
651 | */ |
||
652 | 3 | protected function _doHardBreaks_callback($matches) { |
|
655 | |||
656 | /** |
||
657 | * Turn Markdown link shortcuts into XHTML <a> tags. |
||
658 | * @param string $text |
||
659 | * @return string |
||
660 | */ |
||
661 | 47 | View Code Duplication | protected function doAnchors($text) { |
724 | |||
725 | /** |
||
726 | * Callback method to parse referenced anchors |
||
727 | * @param string $matches |
||
728 | * @return string |
||
729 | */ |
||
730 | 9 | protected function _doAnchors_reference_callback($matches) { |
|
763 | |||
764 | /** |
||
765 | * Callback method to parse inline anchors |
||
766 | * @param string $matches |
||
767 | * @return string |
||
768 | */ |
||
769 | 10 | protected function _doAnchors_inline_callback($matches) { |
|
795 | |||
796 | /** |
||
797 | * Turn Markdown image shortcuts into <img> tags. |
||
798 | * @param string $text |
||
799 | * @return string |
||
800 | */ |
||
801 | 47 | View Code Duplication | protected function doImages($text) { |
849 | |||
850 | /** |
||
851 | * Callback to parse references image tags |
||
852 | * @param array $matches |
||
853 | * @return string |
||
854 | */ |
||
855 | 1 | protected function _doImages_reference_callback($matches) { |
|
882 | |||
883 | /** |
||
884 | * Callback to parse inline image tags |
||
885 | * @param array $matches |
||
886 | * @return string |
||
887 | */ |
||
888 | 2 | protected function _doImages_inline_callback($matches) { |
|
905 | |||
906 | /** |
||
907 | * Parse Markdown heading elements to HTML |
||
908 | * @param string $text |
||
909 | * @return string |
||
910 | */ |
||
911 | 48 | protected function doHeaders($text) { |
|
943 | |||
944 | /** |
||
945 | * Setext header parsing callback |
||
946 | * @param array $matches |
||
947 | * @return string |
||
948 | */ |
||
949 | 5 | protected function _doHeaders_callback_setext($matches) { |
|
963 | |||
964 | /** |
||
965 | * ATX header parsing callback |
||
966 | * @param array $matches |
||
967 | * @return string |
||
968 | */ |
||
969 | 8 | protected function _doHeaders_callback_atx($matches) { |
|
977 | |||
978 | /** |
||
979 | * If a header_id_func property is set, we can use it to automatically |
||
980 | * generate an id attribute. |
||
981 | * |
||
982 | * This method returns a string in the form id="foo", or an empty string |
||
983 | * otherwise. |
||
984 | * @param string $headerValue |
||
985 | * @return string |
||
986 | */ |
||
987 | 9 | protected function _generateIdFromHeaderValue($headerValue) { |
|
999 | |||
1000 | /** |
||
1001 | * Form HTML ordered (numbered) and unordered (bulleted) lists. |
||
1002 | * @param string $text |
||
1003 | * @return string |
||
1004 | */ |
||
1005 | 107 | protected function doLists($text) { |
|
1066 | |||
1067 | /** |
||
1068 | * List parsing callback |
||
1069 | * @param array $matches |
||
1070 | * @return string |
||
1071 | */ |
||
1072 | 24 | protected function _doLists_callback($matches) { |
|
1106 | |||
1107 | /** |
||
1108 | * Nesting tracker for list levels |
||
1109 | * @var integer |
||
1110 | */ |
||
1111 | protected $list_level = 0; |
||
1112 | |||
1113 | /** |
||
1114 | * Process the contents of a single ordered or unordered list, splitting it |
||
1115 | * into individual list items. |
||
1116 | * @param string $list_str |
||
1117 | * @param string $marker_any_re |
||
1118 | * @return string |
||
1119 | */ |
||
1120 | 24 | protected function processListItems($list_str, $marker_any_re) { |
|
1163 | |||
1164 | /** |
||
1165 | * List item parsing callback |
||
1166 | * @param array $matches |
||
1167 | * @return string |
||
1168 | */ |
||
1169 | 24 | protected function _processListItems_callback($matches) { |
|
1190 | |||
1191 | /** |
||
1192 | * Process Markdown `<pre><code>` blocks. |
||
1193 | * @param string $text |
||
1194 | * @return string |
||
1195 | */ |
||
1196 | 107 | protected function doCodeBlocks($text) { |
|
1211 | |||
1212 | /** |
||
1213 | * Code block parsing callback |
||
1214 | * @param array $matches |
||
1215 | * @return string |
||
1216 | */ |
||
1217 | 35 | protected function _doCodeBlocks_callback($matches) { |
|
1233 | |||
1234 | /** |
||
1235 | * Create a code span markup for $code. Called from handleSpanToken. |
||
1236 | * @param string $code |
||
1237 | * @return string |
||
1238 | */ |
||
1239 | 21 | protected function makeCodeSpan($code) { |
|
1247 | |||
1248 | /** |
||
1249 | * Define the emphasis operators with their regex matches |
||
1250 | * @var array |
||
1251 | */ |
||
1252 | protected $em_relist = array( |
||
1253 | '' => '(?:(?<!\*)\*(?!\*)|(?<!_)_(?!_))(?![\.,:;]?\s)', |
||
1254 | '*' => '(?<![\s*])\*(?!\*)', |
||
1255 | '_' => '(?<![\s_])_(?!_)', |
||
1256 | ); |
||
1257 | |||
1258 | /** |
||
1259 | * Define the strong operators with their regex matches |
||
1260 | * @var array |
||
1261 | */ |
||
1262 | protected $strong_relist = array( |
||
1263 | '' => '(?:(?<!\*)\*\*(?!\*)|(?<!_)__(?!_))(?![\.,:;]?\s)', |
||
1264 | '**' => '(?<![\s*])\*\*(?!\*)', |
||
1265 | '__' => '(?<![\s_])__(?!_)', |
||
1266 | ); |
||
1267 | |||
1268 | /** |
||
1269 | * Define the emphasis + strong operators with their regex matches |
||
1270 | * @var array |
||
1271 | */ |
||
1272 | protected $em_strong_relist = array( |
||
1273 | '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<!_)___(?!_))(?![\.,:;]?\s)', |
||
1274 | '***' => '(?<![\s*])\*\*\*(?!\*)', |
||
1275 | '___' => '(?<![\s_])___(?!_)', |
||
1276 | ); |
||
1277 | |||
1278 | /** |
||
1279 | * Container for prepared regular expressions |
||
1280 | * @var array |
||
1281 | */ |
||
1282 | protected $em_strong_prepared_relist; |
||
1283 | |||
1284 | /** |
||
1285 | * Prepare regular expressions for searching emphasis tokens in any |
||
1286 | * context. |
||
1287 | * @return void |
||
1288 | */ |
||
1289 | 2 | protected function prepareItalicsAndBold() { |
|
1306 | |||
1307 | /** |
||
1308 | * Convert Markdown italics (emphasis) and bold (strong) to HTML |
||
1309 | * @param string $text |
||
1310 | * @return string |
||
1311 | */ |
||
1312 | 106 | protected function doItalicsAndBold($text) { |
|
1436 | |||
1437 | /** |
||
1438 | * Parse Markdown blockquotes to HTML |
||
1439 | * @param string $text |
||
1440 | * @return string |
||
1441 | */ |
||
1442 | 107 | protected function doBlockQuotes($text) { |
|
1457 | |||
1458 | /** |
||
1459 | * Blockquote parsing callback |
||
1460 | * @param array $matches |
||
1461 | * @return string |
||
1462 | */ |
||
1463 | 11 | protected function _doBlockQuotes_callback($matches) { |
|
1477 | |||
1478 | /** |
||
1479 | * Blockquote parsing callback |
||
1480 | * @param array $matches |
||
1481 | * @return string |
||
1482 | */ |
||
1483 | 2 | protected function _doBlockQuotes_callback2($matches) { |
|
1488 | |||
1489 | /** |
||
1490 | * Parse paragraphs |
||
1491 | * |
||
1492 | * @param string $text String to process in paragraphs |
||
1493 | * @param boolean $wrap_in_p Whether paragraphs should be wrapped in <p> tags |
||
1494 | * @return string |
||
1495 | */ |
||
1496 | 48 | protected function formParagraphs($text, $wrap_in_p = true) { |
|
1559 | |||
1560 | /** |
||
1561 | * Encode text for a double-quoted HTML attribute. This function |
||
1562 | * is *not* suitable for attributes enclosed in single quotes. |
||
1563 | * @param string $text |
||
1564 | * @return string |
||
1565 | */ |
||
1566 | 34 | protected function encodeAttribute($text) { |
|
1571 | |||
1572 | /** |
||
1573 | * Encode text for a double-quoted HTML attribute containing a URL, |
||
1574 | * applying the URL filter if set. Also generates the textual |
||
1575 | * representation for the URL (removing mailto: or tel:) storing it in $text. |
||
1576 | * This function is *not* suitable for attributes enclosed in single quotes. |
||
1577 | * |
||
1578 | * @param string $url |
||
1579 | * @param string &$text Passed by reference |
||
1580 | * @return string URL |
||
1581 | */ |
||
1582 | 33 | protected function encodeURLAttribute($url, &$text = null) { |
|
1599 | |||
1600 | /** |
||
1601 | * Smart processing for ampersands and angle brackets that need to |
||
1602 | * be encoded. Valid character entities are left alone unless the |
||
1603 | * no-entities mode is set. |
||
1604 | * @param string $text |
||
1605 | * @return string |
||
1606 | */ |
||
1607 | 106 | protected function encodeAmpsAndAngles($text) { |
|
1621 | |||
1622 | /** |
||
1623 | * Parse Markdown automatic links to anchor HTML tags |
||
1624 | * @param string $text |
||
1625 | * @return string |
||
1626 | */ |
||
1627 | 106 | protected function doAutoLinks($text) { |
|
1654 | |||
1655 | /** |
||
1656 | * Parse URL callback |
||
1657 | * @param array $matches |
||
1658 | * @return string |
||
1659 | */ |
||
1660 | 4 | protected function _doAutoLinks_url_callback($matches) { |
|
1665 | |||
1666 | /** |
||
1667 | * Parse email address callback |
||
1668 | * @param array $matches |
||
1669 | * @return string |
||
1670 | */ |
||
1671 | 4 | protected function _doAutoLinks_email_callback($matches) { |
|
1677 | |||
1678 | /** |
||
1679 | * Input: some text to obfuscate, e.g. "mailto:[email protected]" |
||
1680 | * |
||
1681 | * Output: the same text but with most characters encoded as either a |
||
1682 | * decimal or hex entity, in the hopes of foiling most address |
||
1683 | * harvesting spam bots. E.g.: |
||
1684 | * |
||
1685 | * mailto:foo |
||
1686 | * @example.co |
||
1687 | * m |
||
1688 | * |
||
1689 | * Note: the additional output $tail is assigned the same value as the |
||
1690 | * ouput, minus the number of characters specified by $head_length. |
||
1691 | * |
||
1692 | * Based by a filter by Matthew Wickline, posted to BBEdit-Talk. |
||
1693 | * With some optimizations by Milian Wolff. Forced encoding of HTML |
||
1694 | * attribute special characters by Allan Odgaard. |
||
1695 | * |
||
1696 | * @param string $text |
||
1697 | * @param string &$tail |
||
1698 | * @param integer $head_length |
||
1699 | * @return string |
||
1700 | */ |
||
1701 | 4 | protected function encodeEntityObfuscatedAttribute($text, &$tail = null, $head_length = 0) { |
|
1732 | |||
1733 | /** |
||
1734 | * Take the string $str and parse it into tokens, hashing embeded HTML, |
||
1735 | * escaped characters and handling code spans. |
||
1736 | * @param string $str |
||
1737 | * @return string |
||
1738 | */ |
||
1739 | 106 | protected function parseSpan($str) { |
|
1790 | |||
1791 | /** |
||
1792 | * Handle $token provided by parseSpan by determining its nature and |
||
1793 | * returning the corresponding value that should replace it. |
||
1794 | * @param string $token |
||
1795 | * @param string &$str |
||
1796 | * @return string |
||
1797 | */ |
||
1798 | 37 | protected function handleSpanToken($token, &$str) { |
|
1816 | |||
1817 | /** |
||
1818 | * Remove one level of line-leading tabs or spaces |
||
1819 | * @param string $text |
||
1820 | * @return string |
||
1821 | */ |
||
1822 | 47 | protected function outdent($text) { |
|
1825 | |||
1826 | |||
1827 | /** |
||
1828 | * String length function for detab. `_initDetab` will create a function to |
||
1829 | * handle UTF-8 if the default function does not exist. |
||
1830 | * @var string |
||
1831 | */ |
||
1832 | protected $utf8_strlen = 'mb_strlen'; |
||
1833 | |||
1834 | /** |
||
1835 | * Replace tabs with the appropriate amount of spaces. |
||
1836 | * |
||
1837 | * For each line we separate the line in blocks delemited by tab characters. |
||
1838 | * Then we reconstruct every line by adding the appropriate number of space |
||
1839 | * between each blocks. |
||
1840 | * |
||
1841 | * @param string $text |
||
1842 | * @return string |
||
1843 | */ |
||
1844 | 107 | protected function detab($text) { |
|
1850 | |||
1851 | /** |
||
1852 | * Replace tabs callback |
||
1853 | * @param string $matches |
||
1854 | * @return string |
||
1855 | */ |
||
1856 | 34 | protected function _detab_callback($matches) { |
|
1873 | |||
1874 | /** |
||
1875 | * Check for the availability of the function in the `utf8_strlen` property |
||
1876 | * (initially `mb_strlen`). If the function is not available, create a |
||
1877 | * function that will loosely count the number of UTF-8 characters with a |
||
1878 | * regular expression. |
||
1879 | * @return void |
||
1880 | */ |
||
1881 | 2 | protected function _initDetab() { |
|
1891 | |||
1892 | /** |
||
1893 | * Swap back in all the tags hashed by _HashHTMLBlocks. |
||
1894 | * @param string $text |
||
1895 | * @return string |
||
1896 | */ |
||
1897 | 107 | protected function unhash($text) { |
|
1901 | |||
1902 | /** |
||
1903 | * Unhashing callback |
||
1904 | * @param array $matches |
||
1905 | * @return string |
||
1906 | */ |
||
1907 | 85 | protected function _unhash_callback($matches) { |
|
1910 | } |
||
1911 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.