Completed
Push — master ( 6ab9da...3a5a90 )
by Hong
02:05
created

FilesystemAwareTrait::isFilesystemWritable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Storage
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Storage\Traits;
16
17
use Phossa2\Storage\Interfaces\FilesystemInterface;
18
use Phossa2\Storage\Interfaces\FilesystemAwareInterface;
19
use Phossa2\Storage\Message\Message;
20
21
/**
22
 * FilesystemAwareTrait
23
 *
24
 * Implementation of FilesystemAwareInterface
25
 *
26
 * @package Phossa2\Storage
27
 * @author  Hong Zhang <[email protected]>
28
 * @see     FilesystemAwareInterface
29
 * @version 2.0.0
30
 * @since   2.0.0 added
31
 */
32
trait FilesystemAwareTrait
33
{
34
    /**
35
     * @var    FilesystemInterface
36
     * @access protected
37
     */
38
    protected $filesystem;
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function setFilesystem(FilesystemInterface $filesystem)
44
    {
45
        $this->filesystem = $filesystem;
46
        return $this;
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52
    public function getFilesystem()/*# : FilesystemInterface */
53
    {
54
        return $this->filesystem;
55
    }
56
57
    /**
58
     * Check filesystem readable or not
59
     *
60
     * @return bool
61
     * @access protected
62
     */
63
    protected function isFilesystemReadable()/*# : bool */
64
    {
65
        if ($this->getFilesystem()->isReadable()) {
66
            return true;
67
        } else {
68
            return $this->setError(
69
                Message::get(Message::STR_FS_NONREADABLE, $this->full),
0 ignored issues
show
Bug introduced by
The property full does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
70
                Message::STR_FS_NONREADABLE
71
            );
72
        }
73
    }
74
75
    /**
76
     * Check filesystem writable or not
77
     *
78
     * @return bool
79
     * @access protected
80
     */
81
    protected function isFilesystemWritable()/*# : bool */
82
    {
83
        if ($this->getFilesystem()->isWritable()) {
84
            return true;
85
        } else {
86
            return $this->setError(
87
                Message::get(Message::STR_FS_NONWRITABLE, $this->full),
88
                Message::STR_FS_NONWRITABLE
89
            );
90
        }
91
    }
92
93
    /**
94
     * Check filesystem file deletable or not
95
     *
96
     * @return bool
97
     * @access protected
98
     */
99
    protected function isFilesystemDeletable()/*# : bool */
100
    {
101
        if ($this->getFilesystem()->isDeletable()) {
102
            return true;
103
        } else {
104
            return $this->setError(
105
                Message::get(Message::STR_FS_NONDELETABLE, $this->full),
106
                Message::STR_FS_NONDELETABLE
107
            );
108
        }
109
    }
110
111
    abstract public function setError(
112
        /*# string */ $message = '',
113
        /*# string */ $code = ''
114
    )/*# : bool */;
115
}
116