getPermissionPublicDirectory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Filesystem\Adapter\Local\Configuration\Adapter;
15
16
use League\Flysystem\Local\LocalFilesystemAdapter;
17
use Micro\Framework\Kernel\Configuration\Exception\InvalidConfigurationException;
18
use Micro\Plugin\Filesystem\Configuration\Adapter\AbstractFilesystemAdapterConfiguration;
19
20
class LocalAdapterConfiguration extends AbstractFilesystemAdapterConfiguration implements LocalAdapterConfigurationInterface
21
{
22
    public const CFG_ROOT_DIRECTORY = 'MICRO_FS_%s_ROOT_PATH';
23
    public const CFG_LINKS_HANDLING = 'MICRO_FS_%s_LINK_HANDLING';
24
    public const CFG_WRITE_FLAGS = 'MICRO_FS_%s_WRITE_FLAGS';
25
    public const CFG_IS_LAZY_ROOT_CREATION = 'MICRO_FS_%s_LAZY_ROOT_CREATION';
26
    public const CFG_PERMISSION_FILE_PUBLIC = 'MICRO_FS_%s_PERMISSION_FILE_PUBLIC';
27
    public const CFG_PERMISSION_DIR_PUBLIC = 'MICRO_FS_%s_PERMISSION_DIR_PUBLIC';
28
    public const CFG_PERMISSION_FILE_PRIVATE = 'MICRO_FS_%s_PERMISSION_FILE_PRIVATE';
29
    public const CFG_PERMISSION_DIR_PRIVATE = 'MICRO_FS_%s_PERMISSION_DIR_PRIVATE';
30
31
    /**
32
     * {@inheritDoc}
33
     */
34 1
    public function getRootDirectory(): string
35
    {
36 1
        return $this->get(self::CFG_ROOT_DIRECTORY, null, false);
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 1
    public function getWriteFlags(): int
43
    {
44 1
        return (int) $this->get(self::CFG_WRITE_FLAGS);
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 2
    public function getLinkHeading(): int
51
    {
52 2
        $allowed = [
53 2
            LocalFilesystemAdapter::DISALLOW_LINKS,
54 2
            LocalFilesystemAdapter::SKIP_LINKS,
55 2
        ];
56
57 2
        $value = $this->get(self::CFG_LINKS_HANDLING, LocalFilesystemAdapter::DISALLOW_LINKS);
58
59 2
        $_value = (int) $value;
60 2
        if (\in_array($_value, $allowed)) {
61 1
            return $_value;
62
        }
63
64 1
        throw new InvalidConfigurationException(sprintf('Configuration key "%s" has invalid value `%s`. Allowed values: `%s`', $this->cfg(self::CFG_LINKS_HANDLING), (string) $value, implode(', ', $allowed)));
65
    }
66
67
    /**
68
     * {@inheritDoc}
69
     */
70 1
    public function isLazyRootCreation(): bool
71
    {
72 1
        return $this->get(self::CFG_IS_LAZY_ROOT_CREATION, false);
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78 1
    public function getPermissionPublicFile(): int
79
    {
80 1
        return (int) $this->get(self::CFG_PERMISSION_FILE_PUBLIC, 0640);
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     */
86 1
    public function getPermissionPublicDirectory(): int
87
    {
88 1
        return (int) $this->get(self::CFG_PERMISSION_DIR_PUBLIC, 0604);
89
    }
90
91
    /**
92
     * {@inheritDoc}
93
     */
94 1
    public function getPermissionPrivateDirectory(): int
95
    {
96 1
        return (int) $this->get(self::CFG_PERMISSION_DIR_PRIVATE, 0740);
97
    }
98
99
    /**
100
     * {@inheritDoc}
101
     */
102 1
    public function getPermissionPrivateFile(): int
103
    {
104 1
        return (int) $this->get(self::CFG_PERMISSION_FILE_PRIVATE, 7604);
105
    }
106
}
107