OperatorWhitespaceFixer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fixIssue() 0 10 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Pluswerk\TypoScriptAutoFixer\Fixer\OperatorWhitespace;
5
6
use Pluswerk\TypoScriptAutoFixer\Exception\NoOperatorFoundException;
7
use Pluswerk\TypoScriptAutoFixer\Fixer\AbstractFixer;
8
use Pluswerk\TypoScriptAutoFixer\File;
9
use Pluswerk\TypoScriptAutoFixer\FileBuilder;
10
use Pluswerk\TypoScriptAutoFixer\Fixer\FixerInterface;
11
use Pluswerk\TypoScriptAutoFixer\Issue\AbstractIssue;
12
use Pluswerk\TypoScriptAutoFixer\Issue\OperatorWhitespaceIssue;
13
14
final class OperatorWhitespaceFixer extends AbstractFixer
15
{
16
    /**
17
     * @var LineFixer|null
18
     */
19
    private $lineFixer;
20
21
    /**
22
     * OperatorWhitespaceFixer constructor.
23
     *
24
     * @param FileBuilder    $fileBuilder
25
     * @param LineFixer|null $lineFixer
26
     */
27
    public function __construct(FileBuilder $fileBuilder = null, LineFixer $lineFixer = null)
28
    {
29
        parent::__construct($fileBuilder);
30
        $this->lineFixer = $lineFixer ?? new LineFixer();
31
    }
32
33
    /**
34
     * @param File          $file
35
     * @param AbstractIssue $issue
36
     *
37
     * @return File
38
     */
39
    public function fixIssue(File $file, AbstractIssue $issue): File
40
    {
41
        $line = $file->readLine($issue->line());
42
        try {
43
            $line = $this->lineFixer->fixOperatorWhitespace($line);
0 ignored issues
show
Bug introduced by
The method fixOperatorWhitespace() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
            /** @scrutinizer ignore-call */ 
44
            $line = $this->lineFixer->fixOperatorWhitespace($line);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
        } catch (NoOperatorFoundException $e) {
45
            return $file;
46
        }
47
        $file->replaceLine($line, $issue->line());
48
        return $this->fileBuilder->buildFile($file->getPathname());
49
    }
50
}
51