Util   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 30
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A trimEmptyLines() 0 10 3
A normalizeLineEndings() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of SebastianFeldmann\Cli.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace SebastianFeldmann\Cli\Output;
13
14
/**
15
 * Class Util
16
 *
17
 * @package SebastianFeldmann\Cli
18
 * @author  Sebastian Feldmann <[email protected]>
19
 * @link    https://github.com/sebastianfeldmann/cli
20
 * @since   Class available since Release 2.1.0
21
 */
22
class Util
23
{
24
    /**
25
     * Remove empty entries at the end of an array.
26
     *
27
     * @param  array $lines
28 8
     * @return array
29
     */
30 8
    public static function trimEmptyLines(array $lines): array
31 8
    {
32 6
        for ($last = count($lines) - 1; $last > -1; $last--) {
33
            if (!empty($lines[$last])) {
34 4
                return $lines;
35
            }
36 2
            unset($lines[$last]);
37
        }
38
        return $lines;
39
    }
40
41
    /**
42
     * Replaces all 'known' line endings with unix \n line endings
43
     *
44
     * @param  string $text
45 5
     * @return string
46
     */
47 5
    public static function normalizeLineEndings(string $text): string
48
    {
49
        return preg_replace('~(BSR_ANYCRLF)*\R~', "\n", $text);
50
    }
51
}
52