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.9.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|null |
||
89 | */ |
||
90 | public $url_filter_func = null; |
||
91 | |||
92 | /** |
||
93 | * Optional header id="" generation callback function. |
||
94 | * @var callable|null |
||
95 | */ |
||
96 | public $header_id_func = null; |
||
97 | |||
98 | /** |
||
99 | * Optional function for converting code block content to HTML |
||
100 | * @var callable|null |
||
101 | */ |
||
102 | public $code_block_content_func = null; |
||
103 | |||
104 | /** |
||
105 | * Optional function for converting code span content to HTML. |
||
106 | * @var callable|null |
||
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 | 5 | 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 | 110 | 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 | 110 | 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 | 110 | 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 | 110 | 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 | 110 | 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 | 110 | protected function runBasicBlockGamut($text) { |
|
574 | |||
575 | /** |
||
576 | * Convert horizontal rules |
||
577 | * @param string $text |
||
578 | * @return string |
||
579 | */ |
||
580 | 110 | 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 | 109 | protected function runSpanGamut($text) { |
|
631 | |||
632 | /** |
||
633 | * Do hard breaks |
||
634 | * @param string $text |
||
635 | * @return string |
||
636 | */ |
||
637 | 109 | 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) { |
|
794 | |||
795 | /** |
||
796 | * Turn Markdown image shortcuts into <img> tags. |
||
797 | * @param string $text |
||
798 | * @return string |
||
799 | */ |
||
800 | 47 | View Code Duplication | protected function doImages($text) { |
848 | |||
849 | /** |
||
850 | * Callback to parse references image tags |
||
851 | * @param array $matches |
||
852 | * @return string |
||
853 | */ |
||
854 | 1 | protected function _doImages_reference_callback($matches) { |
|
888 | |||
889 | /** |
||
890 | * Callback to parse inline image tags |
||
891 | * @param array $matches |
||
892 | * @return string |
||
893 | */ |
||
894 | 2 | protected function _doImages_inline_callback($matches) { |
|
918 | |||
919 | /** |
||
920 | * Parse Markdown heading elements to HTML |
||
921 | * @param string $text |
||
922 | * @return string |
||
923 | */ |
||
924 | 48 | protected function doHeaders($text) { |
|
956 | |||
957 | /** |
||
958 | * Setext header parsing callback |
||
959 | * @param array $matches |
||
960 | * @return string |
||
961 | */ |
||
962 | 5 | protected function _doHeaders_callback_setext($matches) { |
|
976 | |||
977 | /** |
||
978 | * ATX header parsing callback |
||
979 | * @param array $matches |
||
980 | * @return string |
||
981 | */ |
||
982 | 8 | protected function _doHeaders_callback_atx($matches) { |
|
990 | |||
991 | /** |
||
992 | * If a header_id_func property is set, we can use it to automatically |
||
993 | * generate an id attribute. |
||
994 | * |
||
995 | * This method returns a string in the form id="foo", or an empty string |
||
996 | * otherwise. |
||
997 | * @param string $headerValue |
||
998 | * @return string |
||
999 | */ |
||
1000 | 9 | protected function _generateIdFromHeaderValue($headerValue) { |
|
1012 | |||
1013 | /** |
||
1014 | * Form HTML ordered (numbered) and unordered (bulleted) lists. |
||
1015 | * @param string $text |
||
1016 | * @return string |
||
1017 | */ |
||
1018 | 110 | protected function doLists($text) { |
|
1079 | |||
1080 | /** |
||
1081 | * List parsing callback |
||
1082 | * @param array $matches |
||
1083 | * @return string |
||
1084 | */ |
||
1085 | 24 | protected function _doLists_callback($matches) { |
|
1119 | |||
1120 | /** |
||
1121 | * Nesting tracker for list levels |
||
1122 | * @var integer |
||
1123 | */ |
||
1124 | protected $list_level = 0; |
||
1125 | |||
1126 | /** |
||
1127 | * Process the contents of a single ordered or unordered list, splitting it |
||
1128 | * into individual list items. |
||
1129 | * @param string $list_str |
||
1130 | * @param string $marker_any_re |
||
1131 | * @return string |
||
1132 | */ |
||
1133 | 24 | protected function processListItems($list_str, $marker_any_re) { |
|
1176 | |||
1177 | /** |
||
1178 | * List item parsing callback |
||
1179 | * @param array $matches |
||
1180 | * @return string |
||
1181 | */ |
||
1182 | 24 | protected function _processListItems_callback($matches) { |
|
1203 | |||
1204 | /** |
||
1205 | * Process Markdown `<pre><code>` blocks. |
||
1206 | * @param string $text |
||
1207 | * @return string |
||
1208 | */ |
||
1209 | 110 | protected function doCodeBlocks($text) { |
|
1224 | |||
1225 | /** |
||
1226 | * Code block parsing callback |
||
1227 | * @param array $matches |
||
1228 | * @return string |
||
1229 | */ |
||
1230 | 35 | protected function _doCodeBlocks_callback($matches) { |
|
1246 | |||
1247 | /** |
||
1248 | * Create a code span markup for $code. Called from handleSpanToken. |
||
1249 | * @param string $code |
||
1250 | * @return string |
||
1251 | */ |
||
1252 | 21 | protected function makeCodeSpan($code) { |
|
1260 | |||
1261 | /** |
||
1262 | * Define the emphasis operators with their regex matches |
||
1263 | * @var array |
||
1264 | */ |
||
1265 | protected $em_relist = array( |
||
1266 | '' => '(?:(?<!\*)\*(?!\*)|(?<!_)_(?!_))(?![\.,:;]?\s)', |
||
1267 | '*' => '(?<![\s*])\*(?!\*)', |
||
1268 | '_' => '(?<![\s_])_(?!_)', |
||
1269 | ); |
||
1270 | |||
1271 | /** |
||
1272 | * Define the strong operators with their regex matches |
||
1273 | * @var array |
||
1274 | */ |
||
1275 | protected $strong_relist = array( |
||
1276 | '' => '(?:(?<!\*)\*\*(?!\*)|(?<!_)__(?!_))(?![\.,:;]?\s)', |
||
1277 | '**' => '(?<![\s*])\*\*(?!\*)', |
||
1278 | '__' => '(?<![\s_])__(?!_)', |
||
1279 | ); |
||
1280 | |||
1281 | /** |
||
1282 | * Define the emphasis + strong operators with their regex matches |
||
1283 | * @var array |
||
1284 | */ |
||
1285 | protected $em_strong_relist = array( |
||
1286 | '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<!_)___(?!_))(?![\.,:;]?\s)', |
||
1287 | '***' => '(?<![\s*])\*\*\*(?!\*)', |
||
1288 | '___' => '(?<![\s_])___(?!_)', |
||
1289 | ); |
||
1290 | |||
1291 | /** |
||
1292 | * Container for prepared regular expressions |
||
1293 | * @var array |
||
1294 | */ |
||
1295 | protected $em_strong_prepared_relist; |
||
1296 | |||
1297 | /** |
||
1298 | * Prepare regular expressions for searching emphasis tokens in any |
||
1299 | * context. |
||
1300 | * @return void |
||
1301 | */ |
||
1302 | 5 | protected function prepareItalicsAndBold() { |
|
1319 | |||
1320 | /** |
||
1321 | * Convert Markdown italics (emphasis) and bold (strong) to HTML |
||
1322 | * @param string $text |
||
1323 | * @return string |
||
1324 | */ |
||
1325 | 109 | protected function doItalicsAndBold($text) { |
|
1449 | |||
1450 | /** |
||
1451 | * Parse Markdown blockquotes to HTML |
||
1452 | * @param string $text |
||
1453 | * @return string |
||
1454 | */ |
||
1455 | 110 | protected function doBlockQuotes($text) { |
|
1470 | |||
1471 | /** |
||
1472 | * Blockquote parsing callback |
||
1473 | * @param array $matches |
||
1474 | * @return string |
||
1475 | */ |
||
1476 | 11 | protected function _doBlockQuotes_callback($matches) { |
|
1490 | |||
1491 | /** |
||
1492 | * Blockquote parsing callback |
||
1493 | * @param array $matches |
||
1494 | * @return string |
||
1495 | */ |
||
1496 | 2 | protected function _doBlockQuotes_callback2($matches) { |
|
1501 | |||
1502 | /** |
||
1503 | * Parse paragraphs |
||
1504 | * |
||
1505 | * @param string $text String to process in paragraphs |
||
1506 | * @param boolean $wrap_in_p Whether paragraphs should be wrapped in <p> tags |
||
1507 | * @return string |
||
1508 | */ |
||
1509 | 48 | protected function formParagraphs($text, $wrap_in_p = true) { |
|
1572 | |||
1573 | /** |
||
1574 | * Encode text for a double-quoted HTML attribute. This function |
||
1575 | * is *not* suitable for attributes enclosed in single quotes. |
||
1576 | * @param string $text |
||
1577 | * @return string |
||
1578 | */ |
||
1579 | 36 | protected function encodeAttribute($text) { |
|
1584 | |||
1585 | /** |
||
1586 | * Encode text for a double-quoted HTML attribute containing a URL, |
||
1587 | * applying the URL filter if set. Also generates the textual |
||
1588 | * representation for the URL (removing mailto: or tel:) storing it in $text. |
||
1589 | * This function is *not* suitable for attributes enclosed in single quotes. |
||
1590 | * |
||
1591 | * @param string $url |
||
1592 | * @param string $text Passed by reference |
||
1593 | * @return string URL |
||
1594 | */ |
||
1595 | 33 | protected function encodeURLAttribute($url, &$text = null) { |
|
1612 | |||
1613 | /** |
||
1614 | * Smart processing for ampersands and angle brackets that need to |
||
1615 | * be encoded. Valid character entities are left alone unless the |
||
1616 | * no-entities mode is set. |
||
1617 | * @param string $text |
||
1618 | * @return string |
||
1619 | */ |
||
1620 | 109 | protected function encodeAmpsAndAngles($text) { |
|
1634 | |||
1635 | /** |
||
1636 | * Parse Markdown automatic links to anchor HTML tags |
||
1637 | * @param string $text |
||
1638 | * @return string |
||
1639 | */ |
||
1640 | 109 | protected function doAutoLinks($text) { |
|
1667 | |||
1668 | /** |
||
1669 | * Parse URL callback |
||
1670 | * @param array $matches |
||
1671 | * @return string |
||
1672 | */ |
||
1673 | 4 | protected function _doAutoLinks_url_callback($matches) { |
|
1678 | |||
1679 | /** |
||
1680 | * Parse email address callback |
||
1681 | * @param array $matches |
||
1682 | * @return string |
||
1683 | */ |
||
1684 | 4 | protected function _doAutoLinks_email_callback($matches) { |
|
1690 | |||
1691 | /** |
||
1692 | * Input: some text to obfuscate, e.g. "mailto:[email protected]" |
||
1693 | * |
||
1694 | * Output: the same text but with most characters encoded as either a |
||
1695 | * decimal or hex entity, in the hopes of foiling most address |
||
1696 | * harvesting spam bots. E.g.: |
||
1697 | * |
||
1698 | * mailto:foo |
||
1699 | * @example.co |
||
1700 | * m |
||
1701 | * |
||
1702 | * Note: the additional output $tail is assigned the same value as the |
||
1703 | * ouput, minus the number of characters specified by $head_length. |
||
1704 | * |
||
1705 | * Based by a filter by Matthew Wickline, posted to BBEdit-Talk. |
||
1706 | * With some optimizations by Milian Wolff. Forced encoding of HTML |
||
1707 | * attribute special characters by Allan Odgaard. |
||
1708 | * |
||
1709 | * @param string $text |
||
1710 | * @param string $tail Passed by reference |
||
1711 | * @param integer $head_length |
||
1712 | * @return string |
||
1713 | */ |
||
1714 | 4 | protected function encodeEntityObfuscatedAttribute($text, &$tail = null, $head_length = 0) { |
|
1745 | |||
1746 | /** |
||
1747 | * Take the string $str and parse it into tokens, hashing embeded HTML, |
||
1748 | * escaped characters and handling code spans. |
||
1749 | * @param string $str |
||
1750 | * @return string |
||
1751 | */ |
||
1752 | 109 | protected function parseSpan($str) { |
|
1803 | |||
1804 | /** |
||
1805 | * Handle $token provided by parseSpan by determining its nature and |
||
1806 | * returning the corresponding value that should replace it. |
||
1807 | * @param string $token |
||
1808 | * @param string $str Passed by reference |
||
1809 | * @return string |
||
1810 | */ |
||
1811 | 37 | protected function handleSpanToken($token, &$str) { |
|
1829 | |||
1830 | /** |
||
1831 | * Remove one level of line-leading tabs or spaces |
||
1832 | * @param string $text |
||
1833 | * @return string |
||
1834 | */ |
||
1835 | 47 | protected function outdent($text) { |
|
1838 | |||
1839 | |||
1840 | /** |
||
1841 | * String length function for detab. `_initDetab` will create a function to |
||
1842 | * handle UTF-8 if the default function does not exist. |
||
1843 | * @var string |
||
1844 | */ |
||
1845 | protected $utf8_strlen = 'mb_strlen'; |
||
1846 | |||
1847 | /** |
||
1848 | * Replace tabs with the appropriate amount of spaces. |
||
1849 | * |
||
1850 | * For each line we separate the line in blocks delemited by tab characters. |
||
1851 | * Then we reconstruct every line by adding the appropriate number of space |
||
1852 | * between each blocks. |
||
1853 | * |
||
1854 | * @param string $text |
||
1855 | * @return string |
||
1856 | */ |
||
1857 | 110 | protected function detab($text) { |
|
1863 | |||
1864 | /** |
||
1865 | * Replace tabs callback |
||
1866 | * @param string $matches |
||
1867 | * @return string |
||
1868 | */ |
||
1869 | 34 | protected function _detab_callback($matches) { |
|
1886 | |||
1887 | /** |
||
1888 | * Check for the availability of the function in the `utf8_strlen` property |
||
1889 | * (initially `mb_strlen`). If the function is not available, create a |
||
1890 | * function that will loosely count the number of UTF-8 characters with a |
||
1891 | * regular expression. |
||
1892 | * @return void |
||
1893 | */ |
||
1894 | 5 | protected function _initDetab() { |
|
1904 | |||
1905 | /** |
||
1906 | * Swap back in all the tags hashed by _HashHTMLBlocks. |
||
1907 | * @param string $text |
||
1908 | * @return string |
||
1909 | */ |
||
1910 | 110 | protected function unhash($text) { |
|
1914 | |||
1915 | /** |
||
1916 | * Unhashing callback |
||
1917 | * @param array $matches |
||
1918 | * @return string |
||
1919 | */ |
||
1920 | 87 | protected function _unhash_callback($matches) { |
|
1923 | } |
||
1924 |
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.