FileManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
c 2
b 1
f 0
lcom 0
cbo 0
dl 0
loc 36
ccs 12
cts 15
cp 0.8
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A writeFile() 0 12 3
A replaceFile() 0 12 3
1
<?php
2
3
namespace Matks\PHPMakeUp\File;
4
5
use Exception;
6
7
/**
8
 * File Manager
9
 */
10
class FileManager implements FileManagerInterface
11
{
12
    /**
13
     * @param string $filepath
14
     * @param array  $lines
15
     */
16
    public function writeFile($filepath, array $lines)
17
    {
18 1
        if (file_exists($filepath)) {
19
            throw new Exception("File $filepath does exist");
20
        }
21
22 1
        $file = fopen($filepath, 'w');
23 1
        foreach ($lines as $line) {
24 1
            fwrite($file, $line);
25 1
        }
26 1
        fclose($file);
27 1
    }
28
29
    /**
30
     * @param string $oldFilepath
31
     * @param string $newFilepath
32
     */
33
    public function replaceFile($oldFilepath, $newFilepath)
34
    {
35 1
        if (!file_exists($oldFilepath)) {
36
            throw new Exception("File $oldFilepath does not exist");
37
        }
38 1
        if (!file_exists($newFilepath)) {
39
            throw new Exception("File $newFilepath does not exist");
40
        }
41
42 1
        unlink($oldFilepath);
43 1
        rename($newFilepath, $oldFilepath);
44 1
    }
45
}
46