Completed
Push — 1.x ( fd0c91...cdd807 )
by Akihito
03:35
created

FilePutContents   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Compiler;
6
7
use ArrayObject;
8
9
use function file_exists;
10
use function file_put_contents;
11
12
class FilePutContents
13
{
14
    /** @var ArrayObject<int, string> */
15
    private $overwritten;
16
17
    /**
18
     * @param ArrayObject<int, string> $overwritten
19
     */
20
    public function __construct(ArrayObject $overwritten)
21
    {
22
        $this->overwritten = $overwritten;
23
    }
24
25
    public function __invoke(string $fileName, string $content): void
26
    {
27
        if (file_exists($fileName)) {
28
            /** @psalm-suppress NullArgument */
29
            $this->overwritten[] = $fileName;
30
        }
31
32
        file_put_contents($fileName, $content);
33
    }
34
}
35