IssueFixer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fixIssuesForFile() 0 11 3
A __construct() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Pluswerk\TypoScriptAutoFixer\Fixer;
5
6
use Pluswerk\TypoScriptAutoFixer\FileBuilder;
7
8
final class IssueFixer
9
{
10
    /**
11
     * @var FileBuilder
12
     */
13
    private $fileBuilder;
14
15
    /**
16
     * @var FixerFactory
17
     */
18
    private $fixerFactory;
19
20
    public function __construct(FileBuilder $fileBuilder = null, FixerFactory $fixerFactory = null)
21
    {
22
        $this->fileBuilder = $fileBuilder ?? new FileBuilder();
23
        $this->fixerFactory = $fixerFactory ?? new FixerFactory();
24
    }
25
26
    /**
27
     * @param string $filePath
28
     */
29
    public function fixIssuesForFile(string $filePath): void
30
    {
31
        $file = $this->fileBuilder->buildFile($filePath);
32
        $count = 0;
33
        while ($file->issues()->count() > 0 && $count < 50) {
34
            $issue = $file->issues()->current();
35
            $fixer = $this->fixerFactory->getFixerByIssue($issue);
36
            $file = $fixer->fixIssue($file, $issue);
37
            $count++;
38
        }
39
        $file->removeNeedlessEmptyLines();
40
    }
41
}
42