ObjectValidation   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 14
lcom 0
cbo 0
dl 0
loc 88
rs 10
c 3
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A isObject() 0 4 1
A isInstanceOf() 0 4 1
A hasProperty() 0 4 2
A hasMethod() 0 4 2
A hasParentClass() 0 4 2
A isChildOf() 0 4 2
A inheritsFrom() 0 4 2
A hasInterface() 0 4 2
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 9/16/14
5
 * Time: 10:19 PM
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Validator\Validation\Object;
12
13
/**
14
 * Class ObjectValidation
15
 * @package NilPortugues\Validator\Validation\ObjectAttribute
16
 */
17
class ObjectValidation
18
{
19
    /**
20
     * @param $value
21
     *
22
     * @return bool
23
     */
24
    public static function isObject($value)
25
    {
26
        return \is_object($value);
27
    }
28
29
    /**
30
     * @param mixed  $value
31
     * @param string $instanceOf
32
     *
33
     * @return bool
34
     */
35
    public static function isInstanceOf($value, $instanceOf)
36
    {
37
        return $value instanceof $instanceOf;
38
    }
39
40
    /**
41
     * @param \Tests\NilPortugues\Validator\Resources\Dummy $value
42
     * @param string                                        $property
43
     *
44
     * @return bool
45
     */
46
    public static function hasProperty($value, $property)
47
    {
48
        return \is_object($value) && \property_exists(\get_class($value), $property);
49
    }
50
51
    /**
52
     * @param \Tests\NilPortugues\Validator\Resources\Dummy $value
53
     * @param string                                        $method
54
     *
55
     * @return bool
56
     */
57
    public static function hasMethod($value, $method)
58
    {
59
        return \is_object($value) && \method_exists(\get_class($value), $method);
60
    }
61
62
    /**
63
     * @param $value
64
     *
65
     * @return bool
66
     */
67
    public static function hasParentClass($value)
68
    {
69
        return \is_object($value) && \get_parent_class($value) !== false;
70
    }
71
72
    /**
73
     * @param \Tests\NilPortugues\Validator\Resources\Dummy $value
74
     * @param string                                        $parentClass
75
     *
76
     * @return bool
77
     */
78
    public static function isChildOf($value, $parentClass)
79
    {
80
        return \is_object($value) && \get_parent_class($value) === $parentClass;
81
    }
82
83
    /**
84
     * @param \Tests\NilPortugues\Validator\Resources\Dummy $value
85
     * @param string                                        $inheritsClass
86
     *
87
     * @return bool
88
     */
89
    public static function inheritsFrom($value, $inheritsClass)
90
    {
91
        return \is_object($value) && \is_subclass_of($value, $inheritsClass);
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if $inheritsClass can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
92
    }
93
94
    /**
95
     * @param \Tests\NilPortugues\Validator\Resources\Dummy $value
96
     * @param string                                        $interface
97
     *
98
     * @return bool
99
     */
100
    public static function hasInterface($value, $interface)
101
    {
102
        return \is_object($value) && \in_array($interface, \class_implements($value));
103
    }
104
}
105