These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace AlgoWeb\ODataMetadata; |
||
3 | |||
4 | abstract class IsOK |
||
5 | { |
||
6 | protected function isStringNotNullOrEmpty($str) |
||
7 | { |
||
8 | if (!$this->isStringNotNull($str)) { |
||
9 | return false; |
||
10 | } |
||
11 | if (empty(trim($str))) { |
||
12 | return false; |
||
13 | } |
||
14 | return true; |
||
15 | } |
||
16 | |||
17 | protected function isStringNotNull($str) |
||
18 | { |
||
19 | if (null == $str) { |
||
20 | return false; |
||
21 | } |
||
22 | if (!is_string($str)) { |
||
23 | return false; |
||
24 | } |
||
25 | return true; |
||
26 | } |
||
27 | |||
28 | View Code Duplication | protected function isNotNullInstanceOf($var, $instanceOf) |
|
0 ignored issues
–
show
|
|||
29 | { |
||
30 | if (null == $var) { |
||
31 | return false; |
||
32 | } |
||
33 | if (!($var instanceof $instanceOf)) { |
||
34 | return false; |
||
35 | } |
||
36 | return true; |
||
37 | } |
||
38 | |||
39 | View Code Duplication | protected function isNullInstanceOf($var, $instanceOf) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
40 | { |
||
41 | if (null == $var) { |
||
42 | return true; |
||
43 | } |
||
44 | if (!($var instanceof $instanceOf)) { |
||
45 | return false; |
||
46 | } |
||
47 | return false; |
||
48 | } |
||
49 | |||
50 | protected function isValidArray($arr, $instanceOf, $minCount = -1, $maxCount = -1) |
||
51 | { |
||
52 | if (null == $arr) { |
||
53 | return false; |
||
54 | } |
||
55 | if (!is_array($arr)) { |
||
56 | return false; |
||
57 | } |
||
58 | $numberOfItem = count($arr); |
||
59 | if (-1 != $minCount && $numberOfItem < $minCount) { |
||
60 | return false; |
||
61 | } |
||
62 | if (-1 != $maxCount && $numberOfItem > $maxCount) { |
||
63 | return false; |
||
64 | } |
||
65 | foreach ($arr as $item) { |
||
66 | if (!($item instanceof $instanceOf)) { |
||
67 | return false; |
||
68 | } |
||
69 | } |
||
70 | return true; |
||
71 | } |
||
72 | |||
73 | protected function isChildArrayOK(array $arr, &$msg) |
||
74 | { |
||
75 | foreach ($arr as $item) { |
||
76 | if (!($item instanceof IsOK)) { |
||
77 | $msg = "Child item is not an instance of IsOK"; |
||
78 | return false; |
||
79 | } |
||
80 | if (!$item->isOK($msg)) { |
||
81 | return false; |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
86 | abstract protected function isOK(&$msg = null); |
||
87 | |||
88 | protected function isURLValid($url) |
||
89 | { |
||
90 | if (!isStringNotNull($url)) { |
||
91 | return false; |
||
92 | } |
||
93 | if (false === filter_var($url, FILTER_VALIDATE_URL)) { |
||
94 | return false; |
||
95 | } |
||
96 | return true; |
||
97 | } |
||
98 | } |
||
99 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.