File::write()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 12
rs 10
c 1
b 0
f 1
1
<?php
2
/**
3
 * Changelog keeper
4
 *
5
 * @link      https://github.com/hiqdev/chkipper
6
 * @package   chkipper
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\chkipper\helpers;
12
13
use yii\helpers\Console;
14
15
/**
16
 * File helper class.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class File
21
{
22
    public static function write($path, $content)
23
    {
24
        if (file_exists($path)) {
25
            $old = file_get_contents($path);
26
            if ($old === $content) {
27
                return;
28
            }
29
        }
30
        file_put_contents($path, $content);
31
        Console::stdout(Console::ansiFormat("written file: $path\n", [Console::FG_YELLOW]));
32
    }
33
}
34