Conditions | 30 |
Paths | 26 |
Total Lines | 61 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
89 | public function checkType($type, $value, $allow_array_for_obj = true) { |
||
90 | if ($value === null || $type === null || $type === "Object") { |
||
91 | return true; |
||
92 | } else if (array_key_exists($type, $this->enum_data)) { |
||
93 | return in_array($value, $this->enum_data[$type]); |
||
94 | } else if ($type === "file") { |
||
95 | return file_exists($value); |
||
96 | } else if ($type === "list" || $type === "map") { |
||
97 | return is_array($value); |
||
98 | } else if ($type === "bool") { |
||
99 | return is_bool($value); |
||
100 | } else if ($type === "int" || $type === "unsigned int" || $type === "float") { |
||
101 | return is_numeric($value); |
||
102 | } else if ($type === "string" || $type === "datetime") { |
||
103 | return is_string($value) || is_numeric($value) || is_bool($value); |
||
104 | } else if ($this->isTypeCollection($type, "list")) { |
||
105 | $sub_types = $this->getTypeFromCollection($type, "list"); |
||
106 | $sub_type = $sub_types[0]; |
||
107 | if (is_array($value)) { |
||
108 | if (empty($value)) { |
||
109 | return true; |
||
110 | } |
||
111 | $all_object_same_type = true; |
||
112 | foreach ($value as $key => $sub_value) { |
||
113 | $all_object_same_type = ($all_object_same_type && |
||
114 | $this->checkType($sub_type, $sub_value)); |
||
115 | } |
||
116 | return $all_object_same_type; |
||
117 | } else { |
||
118 | return $this->checkType($sub_type, $value); |
||
119 | } |
||
120 | } else if ($this->isTypeCollection($type, "map")) { |
||
121 | if (is_array($value)) { |
||
122 | $sub_types = $this->getTypeFromCollection($type, "map"); |
||
123 | if (count($sub_types) === 1) { |
||
124 | $sub_key_type = 'string'; |
||
125 | $sub_value_type = $sub_types[0]; |
||
126 | } else { |
||
127 | $sub_key_type = $sub_types[0]; |
||
128 | $sub_value_type = $sub_types[1]; |
||
129 | } |
||
130 | $all_object_same_type = true; |
||
131 | foreach ($value as $key => $sub_value) { |
||
132 | $all_object_same_type = ($all_object_same_type && |
||
133 | $this->checkType($sub_key_type, $key) && |
||
134 | $this->checkType($sub_value_type, $sub_value)); |
||
135 | } |
||
136 | return $all_object_same_type; |
||
137 | } |
||
138 | } else { |
||
139 | // the type is an object |
||
140 | if ($allow_array_for_obj && is_array($value)) { |
||
141 | return true; |
||
142 | } |
||
143 | if (!$this->startsWith($type, self::ABSTRACT_OBJECT_PREFIX)) { |
||
144 | $type = self::ABSTRACT_OBJECT_PREFIX.$type; |
||
145 | } |
||
146 | return is_a($value, $type); |
||
147 | } |
||
148 | return false; |
||
149 | } |
||
150 | |||
195 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.