Check for implicit conversion of array to boolean.
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/DwClean.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 DwClean |
||
25 | { |
||
26 | public $system; |
||
27 | |||
28 | public function __construct() |
||
29 | { |
||
30 | $this->system = new System(); |
||
31 | } |
||
32 | |||
33 | public function all() |
||
34 | { |
||
35 | $this->prep(); |
||
36 | $wrap_at = 75; |
||
37 | $this->wrapLine('raw', $wrap_at); |
||
38 | $this->wrapLine('txtdata', $wrap_at); |
||
39 | $this->lines(); |
||
40 | $this->types(); |
||
41 | $this->content(); |
||
42 | $this->reorderRecords(); |
||
43 | } |
||
44 | |||
45 | View Code Duplication | public function prep() |
|
46 | { |
||
47 | $this->system->db()->query(" |
||
48 | DELETE FROM dw_dns_records |
||
49 | WHERE type = ':RAW' |
||
50 | AND raw = ''"); |
||
51 | |||
52 | $this->system->db()->query(" |
||
53 | UPDATE dw_dns_records |
||
54 | SET type = 'COMMENT' |
||
55 | WHERE type = ':RAW'"); |
||
56 | |||
57 | $this->system->db()->query(" |
||
58 | UPDATE dw_dns_records |
||
59 | SET type = 'ZONE TTL' |
||
60 | WHERE type = '\$TTL'"); |
||
61 | |||
62 | $this->system->db()->query(" |
||
63 | UPDATE dw_dns_records |
||
64 | SET nlines = '1' |
||
65 | WHERE nlines = '0'"); |
||
66 | |||
67 | $this->system->db()->query(" |
||
68 | UPDATE dw_dns_records AS r, dw_dns_zones AS z |
||
69 | SET r.zonefile = z.zonefile |
||
70 | WHERE r.dns_zone_id = z.id"); |
||
71 | } |
||
72 | |||
73 | public function wrapLine($field, $wrap_at) |
||
74 | { |
||
75 | $tmpq = $this->system->db()->query(" |
||
76 | SELECT id, " . $field . " |
||
77 | FROM dw_dns_records |
||
78 | WHERE " . $field . " != ''"); |
||
79 | $result = $tmpq->fetchAll(); |
||
80 | |||
81 | if ($result) { |
||
1 ignored issue
–
show
|
|||
82 | |||
83 | $tmpq = $this->system->db()->prepare(" |
||
84 | UPDATE dw_dns_records |
||
85 | SET formatted_output = :wrapped |
||
86 | WHERE id = :id"); |
||
87 | |||
88 | foreach ($result as $row) { |
||
89 | |||
90 | $wrapped = wordwrap($row->{$field}, $wrap_at, "<BR>", true); |
||
91 | |||
92 | $tmpq->execute(array( |
||
93 | 'wrapped' => $wrapped, |
||
94 | 'id' => $row->id)); |
||
95 | |||
96 | } |
||
97 | |||
98 | } |
||
99 | } |
||
100 | |||
101 | public function lines() |
||
102 | { |
||
103 | $this->system->db()->query(" |
||
104 | UPDATE dw_dns_records |
||
105 | SET `formatted_line` = concat(' | ', `line`, ' | ') |
||
106 | WHERE line >= 10"); |
||
107 | |||
108 | $this->system->db()->query(" |
||
109 | UPDATE dw_dns_records |
||
110 | SET `formatted_line` = concat(' | 0', `line`, ' | ') |
||
111 | WHERE line < 10"); |
||
112 | } |
||
113 | |||
114 | public function types() |
||
115 | { |
||
116 | $this->system->db()->query(" |
||
117 | UPDATE dw_dns_records |
||
118 | SET `formatted_type` = concat('<strong" . ">" . "', `type`, '</strong" . ">" . "')"); |
||
119 | } |
||
120 | |||
121 | public function content() |
||
122 | { |
||
123 | $this->system->db()->query(" |
||
124 | UPDATE dw_dns_records |
||
125 | SET formatted_output = concat(`name`, ' | ', `address`, ' | ', `ttl`) |
||
126 | WHERE type = 'A'"); |
||
127 | |||
128 | $this->system->db()->query(" |
||
129 | UPDATE dw_dns_records |
||
130 | SET formatted_output = concat(`formatted_output`, ' | ', ttl) |
||
131 | WHERE type = 'COMMENT'"); |
||
132 | |||
133 | $this->system->db()->query(" |
||
134 | UPDATE dw_dns_records |
||
135 | SET formatted_output = concat(`name`, ' | ', `cname`, ' |', `ttl`) |
||
136 | WHERE type = 'CNAME'"); |
||
137 | |||
138 | $this->system->db()->query(" |
||
139 | UPDATE dw_dns_records |
||
140 | SET formatted_output = concat(`preference`, ' | ', `exchange`, ' | ', `ttl`) |
||
141 | WHERE type = 'MX'"); |
||
142 | |||
143 | $this->system->db()->query(" |
||
144 | UPDATE dw_dns_records |
||
145 | SET formatted_output = concat(`nsdname`, ' | ', `ttl`) |
||
146 | WHERE type = 'NS'"); |
||
147 | |||
148 | $this->system->db()->query(" |
||
149 | UPDATE dw_dns_records |
||
150 | SET formatted_output = concat(`name`, ' | ', `mname`, ' | ', `rname`, ' | ', `ttl`, '<BR" . ">" . "', |
||
151 | '<strong" . ">" . "Serial:</strong" . ">" . " ', `serial`, ' | |
||
152 | <strong" . ">" . "Refresh:</strong" . ">" . " ', `refresh`, ' | |
||
153 | <strong" . ">" . "Retry:</strong" . ">" . " ', `retry`, ' | |
||
154 | <strong" . ">" . "Expire:</strong" . ">" . " ', `expire`, ' | |
||
155 | <strong" . ">" . "Minimum TTL:</strong" . ">" . " ', `minimum`) |
||
156 | WHERE type = 'SOA'"); |
||
157 | |||
158 | $this->system->db()->query(" |
||
159 | UPDATE dw_dns_records |
||
160 | SET formatted_output = concat(`name`, ' | ', `ttl`) |
||
161 | WHERE type = 'SRV'"); |
||
162 | |||
163 | $this->system->db()->query(" |
||
164 | UPDATE dw_dns_records |
||
165 | SET formatted_output = concat(`name`, ' | ', `formatted_output`, ' | ', `ttl`) |
||
166 | WHERE type = 'TXT'"); |
||
167 | |||
168 | $this->system->db()->query(" |
||
169 | UPDATE dw_dns_records |
||
170 | SET formatted_output = ttl |
||
171 | WHERE type = 'ZONE TTL'"); |
||
172 | } |
||
173 | |||
174 | public function reorderRecords() |
||
175 | { |
||
176 | $type_order = array(); |
||
177 | $count = 0; |
||
178 | $new_order = 1; |
||
179 | $type_order[$count++] = 'COMMENT'; |
||
180 | $type_order[$count++] = 'ZONE TTL'; |
||
181 | $type_order[$count++] = 'SOA'; |
||
182 | $type_order[$count++] = 'NS'; |
||
183 | $type_order[$count++] = 'MX'; |
||
184 | $type_order[$count++] = 'A'; |
||
185 | $type_order[$count++] = 'CNAME'; |
||
186 | $type_order[$count++] = 'TXT'; |
||
187 | $type_order[$count++] = 'SRV'; |
||
188 | |||
189 | $tmpq = $this->system->db()->prepare(" |
||
190 | UPDATE dw_dns_records |
||
191 | SET new_order = :new_order |
||
192 | WHERE type = :key"); |
||
193 | |||
194 | foreach ($type_order as $key) { |
||
195 | |||
196 | $tmpq->execute(array( |
||
197 | 'new_order' => $new_order, |
||
198 | 'key' => $key)); |
||
199 | $new_order++; |
||
200 | } |
||
201 | } |
||
202 | |||
203 | } //@formatter:on |
||
204 |
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.