Writable::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 4
nc 3
nop 3
1
<?php
2
/**
3
 * Jaeger
4
 *
5
 * @copyright	Copyright (c) 2015-2016, mithra62
6
 * @link		http://jaeger-app.com
7
 * @version		1.0
8
 * @filesource 	./Validate/Filesystem/Writable.php
9
 */
10
namespace JaegerApp\Validate\Rules\Filesystem;
11
12
use JaegerApp\Validate\AbstractRule;
13
14
if (! class_exists('\\JaegerApp\\Validate\\Filesystem\\Writable')) {
15
16
    /**
17
     * Jaeger - Writable Validation Rule
18
     *
19
     * Validates that a given input is a writable file or directory
20
     *
21
     * @package Validate\Rules\Filesystem
22
     * @author Eric Lamb <[email protected]>
23
     */
24
    class Writable extends AbstractRule
25
    {
26
27
        /**
28
         * The Rule shortname
29
         * 
30
         * @var string
31
         */
32
        protected $name = 'writable';
33
34
        /**
35
         * The error template
36
         * 
37
         * @var string
38
         */
39
        protected $error_message = '{field} has to be writable';
40
41
        /**
42
         * (non-PHPdoc)
43
         * 
44
         * @see \mithra62\Validate\RuleInterface::validate()
45
         * @ignore
46
         *
47
         */
48
        public function validate($field, $input, array $params = array())
49
        {
50
            if ($input instanceof \SplFileInfo) {
51
                return $input->isWritable();
52
            }
53
            
54
            return (is_string($input) && is_writable($input));
55
        }
56
    }
57
}