LineFixer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 19
c 1
b 0
f 0
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fixOperatorWhitespace() 0 10 2
A detectOperator() 0 18 6
1
<?php
2
declare(strict_types=1);
3
4
namespace Pluswerk\TypoScriptAutoFixer\Fixer\OperatorWhitespace;
5
6
class LineFixer
7
{
8
    /**
9
     * @param string $line
10
     *
11
     * @return string
12
     */
13
    public function fixOperatorWhitespace(string $line): string
14
    {
15
        $operator = $this->detectOperator($line);
16
        if ($operator === null) {
17
            return $line;
18
        }
19
        $parts = explode($operator, $line);
20
        $parts[0] = rtrim($parts[0]) . ' ';
21
        $parts[1] = ' ' . ltrim($parts[1]);
22
        return rtrim(implode($operator, $parts));
23
    }
24
25
    /**
26
     * @param string $line
27
     *
28
     * @return string|null
29
     */
30
    private function detectOperator(string $line): ?string
31
    {
32
        if (strpos($line, '=<') !== false) {
33
            return '=<';
34
        }
35
        if (strpos($line, ':=') !== false) {
36
            return ':=';
37
        }
38
        if (strpos($line, '=') !== false) {
39
            return '=';
40
        }
41
        if (strpos($line, '<') !== false) {
42
            return '<';
43
        }
44
        if (strpos($line, '>') !== false) {
45
            return '>';
46
        }
47
        return null;
48
    }
49
}
50