Filesystem::put()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
declare(strict_types=1);
8
9
namespace Tebru\Retrofit\Internal;
10
11
/**
12
 * A light wrapper around filesystem commands
13
 *
14
 * @author Nate Brunette <[email protected]>
15
 */
16
class Filesystem
17
{
18
    /**
19
     * Wraps the php mkdir() function, but defaults to recursive directory creation
20
     *
21
     * @param string $pathname
22
     * @param int $mode
23
     * @param bool $recursive
24
     * @return bool
25
     */
26 3
    public function makeDirectory(string $pathname, int $mode = 0777, bool $recursive = true): bool
27
    {
28 3
        return !(!@mkdir($pathname, $mode, $recursive) && !is_dir($pathname));
29
    }
30
31
    /**
32
     * Write contents to file
33
     *
34
     * @param string $filename
35
     * @param string $contents
36
     * @return bool
37
     */
38 2
    public function put(string $filename, string $contents): bool
39
    {
40 2
        $written = file_put_contents($filename, $contents);
41
42 2
        return !($written === 0);
43
    }
44
}
45