Completed
Pull Request — master (#72)
by Nate
03:35
created

Filesystem::put()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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
    public function makeDirectory(string $pathname, int $mode = 0777, bool $recursive = true): bool
27
    {
28
        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
    public function put(string $filename, string $contents): bool
39
    {
40
        $written = file_put_contents($filename, $contents);
41
42
        return !((int)$written === 0);
43
    }
44
}
45