Storage::getPath()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Helpers\Storage;
6
7
use Minepic\Minecraft\MinecraftDefaults;
8
9
class Storage
10
{
11
    /**
12
     * Storage folder type.
13
     */
14
    protected static string $folder;
15
16
    public static function getPath(string $uuid): string
17
    {
18
        if ($uuid === '') {
19
            $uuid = MinecraftDefaults::getRandomDefaultSkin();
20
        }
21
22
        return sprintf(storage_path(static::$folder.'/%s.png'), $uuid);
23
    }
24
25
    public static function exists(string $uuid): bool
26
    {
27
        return file_exists(static::getPath($uuid));
28
    }
29
30
    /**
31
     * Save the skin to file.
32
     *
33
     * @param mixed  $rawData
34
     */
35
    public static function save(string $uuid, $rawData): bool
36
    {
37
        $fp = fopen(static::getPath($uuid), 'wb');
38
        if (\is_resource($fp)) {
39
            fwrite($fp, $rawData);
40
            fclose($fp);
41
42
            return true;
43
        }
44
45
        return false;
46
    }
47
48
    /**
49
     * Use Steve file for given uuid.
50
     */
51
    public static function copyAsSteve(string $name): bool
52
    {
53
        if ($name !== '') {
54
            return copy(
55
                static::getPath(MinecraftDefaults::getRandomDefaultSkin()),
56
                static::getPath($name)
57
            );
58
        }
59
60
        return false;
61
    }
62
}
63