Passed
Push — master ( da7684...88d58f )
by BruceScrutinizer
02:01
created

createJsonTemplateVisibility()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
declare(strict_types=1);
3
4
namespace NamespaceProtector\Config;
5
6
use NamespaceProtector\Common\PathInterface;
7
8
final class ConfigTemplateCreator implements ConfigTemplateCreatorInterface
9
{
10
    /** @var string */
11
    private $templateName;
12
13
    public function __construct(string $templateName)
14
    {
15
        $this->templateName = $templateName;
16
    }
17
18
    public function create(PathInterface $destinationPathFileJson): void
19
    {
20
        $this->createFileWithBackup($destinationPathFileJson->get(), $this->templateName);
21
    }
22
23
    private function createFileWithBackup(string $fileName, string $templateFile): void
24
    {
25
        @\rename($fileName, $fileName . '_backup.json');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for rename(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

25
        /** @scrutinizer ignore-unhandled */ @\rename($fileName, $fileName . '_backup.json');

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
26
27
        $content = \safe\file_get_contents(__DIR__ . '/' . $templateFile);
28
        \safe\file_put_contents($fileName, $content);
29
    }
30
}
31