Passed
Push — master ( 0771d8...cccc01 )
by Peter
02:29
created

StringHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A plainToHtml() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Helper;
6
7
class StringHelper
8
{
9
    /**
10
     * @param string $plainText
11
     * @param string $prefix
12
     * @param string $postfix
13
     *
14
     * @return string
15
     */
16
    public static function plainToHtml(string $plainText, string $prefix = '', string $postfix = ''): string
17
    {
18
        if (empty($plainText)) {
19
            return '';
20
        }
21
22
        $paragraphs = explode("\n", $plainText);
23
24
        $lines = [];
25
        foreach ($paragraphs as $paragraph) {
26
            if (empty($paragraph)) {
27
                continue;
28
            }
29
            $lines[] = "$prefix$paragraph$postfix";
30
        }
31
32
        return implode("\n", $lines);
33
    }
34
}
35