GitignoreHelper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Paysera\PhpStormHelper\Service;
5
6
use Paysera\PhpStormHelper\Service\Gitignore\ExtendedWriter;
7
use Symfony\Component\Filesystem\Filesystem;
8
9
class GitignoreHelper
10
{
11
    private $filesystem;
12
    private $gitignoreRules;
13
14 10
    public function __construct(Filesystem $filesystem, array $gitignoreRules)
15
    {
16 10
        $this->filesystem = $filesystem;
17 10
        $this->gitignoreRules = $gitignoreRules;
18 10
    }
19
20 5
    public function setupGitignore(string $gitignorePath)
21
    {
22 5
        if (!$this->filesystem->exists($gitignorePath)) {
23
            return;
24
        }
25
26 5
        $writer = new ExtendedWriter($gitignorePath);
27
        $writer
28 5
            ->delete('.idea')
29 5
            ->delete('.idea/')
30 5
            ->delete('.idea/*')
31 5
            ->delete('/.idea')
32 5
            ->delete('/.idea/')
33 5
            ->delete('/.idea/*')
34 5
            ->add($this->gitignoreRules)
35 5
            ->save()
36
        ;
37 5
    }
38
}
39