FileFixes::addLineToFileIfItDoesNotExist()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 15
rs 9.9332
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Sunnysideup\UpgradeToSilverstripe4\Api;
4
5
use Sunnysideup\UpgradeToSilverstripe4\Traits\HelperInst;
6
7
class FileFixes
8
{
9
    use HelperInst;
10
11
    public function addLineToFileIfItDoesNotExist(string $fileFromRoot, string $line): FileFixes
12
    {
13
        $file = $this->mu()->getWebRootDirLocation() . '/' . $fileFromRoot;
0 ignored issues
show
Bug introduced by
The method getWebRootDirLocation() does not exist on Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

13
        $file = $this->mu()->/** @scrutinizer ignore-call */ getWebRootDirLocation() . '/' . $fileFromRoot;
Loading history...
Bug introduced by
Are you sure $this->mu()->getWebRootDirLocation() of type Sunnysideup\UpgradeToSil...duleUpgrader|mixed|null can be used in concatenation? ( Ignorable by Annotation )

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

13
        $file = /** @scrutinizer ignore-type */ $this->mu()->getWebRootDirLocation() . '/' . $fileFromRoot;
Loading history...
14
        if (! file_exists($file)) {
15
            user_error('Can not find ' . $file);
16
        }
17
        $line = addslashes($line);
18
        $this->mu()->execMe(
19
            dirname($fileFromRoot),
20
            'grep -qxF \'' . $line . '\' ' . $file . ' || echo \'' . $line . '\' >>' . $file,
21
            'Add line ' . $line . ' to ' . $file,
22
            false
23
        );
24
25
        return $this;
26
    }
27
}
28