Passed
Pull Request — master (#7)
by Max
04:39
created

Utils   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 27
rs 10
wmc 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Tests;
6
7
use function array_slice;
8
use function count;
9
use function implode;
10
use function preg_match;
11
use function preg_split;
12
use function str_replace;
13
14
class Utils
15
{
16
    public static function nowdoc(string $str) : string
17
    {
18
        $lines = preg_split('/\\n/', $str);
19
20
        if ($lines === false) {
21
            return '';
22
        }
23
24
        if (count($lines) <= 2) {
25
            return '';
26
        }
27
28
        // Toss out the first and last lines.
29
        $lines = array_slice($lines, 1, count($lines) - 2);
30
31
        // take the tabs from the first line, and subtract them from all lines
32
        $matches = [];
33
        preg_match('/(^[ \t]+)/', $lines[0], $matches);
34
35
        $numLines = count($lines);
36
        for ($i = 0; $i < $numLines; $i++) {
37
            $lines[$i] = str_replace($matches[0], '', $lines[$i]);
38
        }
39
40
        return implode("\n", $lines);
41
    }
42
}
43