| Total Complexity | 6 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Coverage | 93.33% |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php # -*- coding: utf-8 -*- |
||
| 6 | class Paragraph implements ElementRuleInterface |
||
| 7 | { |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Store the strings, there we exclude on set paragraph. |
||
| 11 | * |
||
| 12 | * @var array |
||
| 13 | */ |
||
| 14 | protected static $paragraphExcludes = [ |
||
| 15 | '<', // HTML. |
||
| 16 | ' ', // Code. |
||
| 17 | "\t", // Tab. |
||
| 18 | '---', // hr |
||
| 19 | ]; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * {@inheritdoc} |
||
| 23 | */ |
||
| 24 | 2 | public function parse(string $content): string |
|
| 25 | 2 | { |
|
| 26 | // Split for each line to exclude. |
||
| 27 | 2 | $content = explode("\n", $content); |
|
| 28 | 2 | $pContent = ''; |
|
| 29 | 2 | foreach ($content as $line) { |
|
| 30 | 2 | if (!$this->strposa($line, self::$paragraphExcludes)) { |
|
| 31 | 2 | $line = sprintf('<p>%s</p>', trim($line)); |
|
| 32 | } |
||
| 33 | 2 | $pContent .= $line; |
|
| 34 | } |
||
| 35 | |||
| 36 | 2 | return $pContent; |
|
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Find the position of the first occurrence of a substring in a string. |
||
| 41 | * Get only true, if is on the first position (0). |
||
| 42 | * |
||
| 43 | * @param string $haystack The string to search in. |
||
| 44 | * @param array $needle An array with strings for search. |
||
| 45 | * @param int $offset If specified, search will start this number of characters counted |
||
| 46 | * from the beginning of the string. |
||
| 47 | * |
||
| 48 | * @return bool |
||
| 49 | */ |
||
| 50 | 2 | protected function strposa(string $haystack, array $needle, int $offset = 0): bool |
|
| 60 | } |
||
| 61 | } |
||
| 62 |