These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * /classes/DomainMOD/CustomField.php |
||
4 | * |
||
5 | * This file is part of DomainMOD, an open source domain and internet asset manager. |
||
6 | * Copyright (c) 2010-2017 Greg Chetcuti <[email protected]> |
||
7 | * |
||
8 | * Project: http://domainmod.org Author: http://chetcuti.com |
||
9 | * |
||
10 | * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public |
||
11 | * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later |
||
12 | * version. |
||
13 | * |
||
14 | * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
||
15 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see |
||
18 | * http://www.gnu.org/licenses/. |
||
19 | * |
||
20 | */ |
||
21 | //@formatter:off |
||
22 | namespace DomainMOD; |
||
23 | |||
24 | class CustomField |
||
25 | { |
||
26 | public $system; |
||
27 | |||
28 | public function __construct() |
||
29 | { |
||
30 | $this->system = new System(); |
||
31 | } |
||
32 | |||
33 | public function checkFieldFormat($input_field) |
||
34 | { |
||
35 | if (preg_match('/^[a-zA-Z_]+$/i', $input_field, $output_field)) { |
||
36 | |||
37 | return $output_field; |
||
38 | |||
39 | } else { |
||
40 | |||
41 | return false; |
||
42 | |||
43 | } |
||
44 | } |
||
45 | |||
46 | public function getCustomFields($table_name) |
||
47 | { |
||
48 | $result = $this->queryCustomFields($table_name); |
||
49 | |||
50 | $columns_array = array(); |
||
51 | $count = 0; |
||
52 | |||
53 | if ($result) { |
||
1 ignored issue
–
show
|
|||
54 | |||
55 | foreach ($result as $row) { |
||
56 | |||
57 | $columns_array[$count++] = $row->field_name; |
||
58 | |||
59 | } |
||
60 | |||
61 | } |
||
62 | |||
63 | return $columns_array; |
||
64 | } |
||
65 | |||
66 | public function queryCustomFields($table_name) |
||
67 | { |
||
68 | $tmpq = $this->system->db()->query(" |
||
69 | SELECT field_name |
||
70 | FROM " . $table_name . " |
||
71 | ORDER BY `name` ASC"); |
||
72 | return $tmpq->fetchAll(); |
||
73 | } |
||
74 | |||
75 | public function getCustomFieldsSql($table_name, $column_prefix) |
||
76 | { |
||
77 | $result = $this->queryCustomFields($table_name); |
||
78 | |||
79 | $columns = ''; |
||
80 | |||
81 | if ($result) { |
||
1 ignored issue
–
show
The expression
$result of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using
Loading history...
|
|||
82 | |||
83 | foreach ($result as $row) { |
||
84 | |||
85 | $columns .= ", " . $column_prefix . "." . $row->field_name; |
||
86 | |||
87 | } |
||
88 | |||
89 | } |
||
90 | |||
91 | return $columns; |
||
92 | } |
||
93 | |||
94 | } //@formatter:on |
||
95 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.