Completed
Push — master ( 01798b...15f6ef )
by Anton
08:29
created

Writable::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 1
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/bluzman
5
 */
6
7
namespace Bluzman\Validator\Rule;
8
9
use Bluz\Validator\Rule\AbstractRule;
10
11
/**
12
 * @package Bluzman\Validation\Rules
13
 */
14
class Writable extends AbstractRule
15
{
16
    /**
17
     * @var string error template
18
     */
19
    protected $template = '{{name}} must be writable';
20
21
    /**
22
     * @param mixed $input
23
     * @return bool
24
     */
25
    public function validate($input) : bool
26
    {
27
        if ($input instanceof \SplFileInfo) {
28
            return $input->isWritable();
29
        }
30
        return is_string($input) && is_writable($input);
31
    }
32
}
33