Completed
Push — develop ( 7befb7...50d370 )
by Stuart
02:47
created

class-object-functions.php ➔ has_class_properties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * Copyright (c) 2016-present Ganbaro Digital Ltd
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 *   * Redistributions of source code must retain the above copyright
12
 *     notice, this list of conditions and the following disclaimer.
13
 *
14
 *   * Redistributions in binary form must reproduce the above copyright
15
 *     notice, this list of conditions and the following disclaimer in
16
 *     the documentation and/or other materials provided with the
17
 *     distribution.
18
 *
19
 *   * Neither the names of the copyright holders nor the names of his
20
 *     contributors may be used to endorse or promote products derived
21
 *     from this software without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
 * POSSIBILITY OF SUCH DAMAGE.
35
 *
36
 * @category  Libraries
37
 * @package   MissingBits/ClassesAndObjects
38
 * @author    Stuart Herbert <[email protected]>
39
 * @copyright 2016-present Ganbaro Digital Ltd www.ganbarodigital.com
40
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
41
 * @link      http://ganbarodigital.github.io/php-the-missing-bits
42
 */
43
44
use GanbaroDigital\MissingBits\ClassesAndObjects\FilterClassProperties;
45
use GanbaroDigital\MissingBits\ClassesAndObjects\FilterObjectProperties;
46
use GanbaroDigital\MissingBits\ClassesAndObjects\HasClassProperties;
47
use GanbaroDigital\MissingBits\ClassesAndObjects\HasObjectProperties;
48
49
/**
50
 * get a class's static properties
51
 *
52
 * @param  string $target
53
 *         the class to examine
54
 * @param  int $propTypes
55
 *         the kind of properties to look for
56
 *         default is to look for public properties only
57
 * @return array
58
 *         a (possibly empty) read-only list of the class's static properties
59
 * @throws InvalidArgumentException
60
 *         if $target is not a valid class name
61
 */
62
function get_class_properties($target, $propTypes = ReflectionProperty::IS_PUBLIC)
63
{
64
    // our helper class has all the answers
65
    return FilterClassProperties::from($target, $propTypes);
66
}
67
68
/**
69
 * does a class have static properties?
70
 *
71
 * @param  string $target
72
 *         the class to examine
73
 * @param  int $propTypes
74
 *         the kind of properties to look for
75
 *         default is to look for public properties only
76
 * @return boolean
77
 *         TRUE if $target is a class with static properties
78
 *         FALSE otherwise
79
 */
80
function has_class_properties($target, $propTypes = ReflectionProperty::IS_PUBLIC)
81
{
82
    return HasClassProperties::check($target, $propTypes);
83
}
84
85
/**
86
 * get an object's properties
87
 *
88
 * @param  object $target
89
 *         the object to examine
90
 * @param  int $propTypes
91
 *         the kind of properties to look for
92
 *         default is to look for public properties only
93
 * @return array
94
 *         a (possibly empty) read-only list of the class's static properties
95
 * @throws InvalidArgumentException
96
 *         if $target is not an object
97
 */
98
function get_object_properties($target, $propTypes = ReflectionProperty::IS_PUBLIC)
99
{
100
    // our helper class has all the answers
101
    return FilterObjectProperties::from($target, $propTypes);
102
}
103
104
/**
105
 * does an object have properties?
106
 *
107
 * @param  object  $target
108
 *         the object to examine
109
 * @param  int $propTypes
110
 *         the kind of properties to look for
111
 *         default is to look for public properties only
112
 * @return boolean
113
 *         TRUE if $target is an object with properties
114
 *         FALSE otherwise
115
 */
116
function has_object_properties($target, $propTypes = ReflectionProperty::IS_PUBLIC)
117
{
118
    return HasObjectProperties::check($target, $propTypes);
119
}
120