Skip to content

Commit

Permalink
PSR2 checking on Models.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-unwin committed Apr 18, 2024
1 parent 9f88010 commit b65ecb9
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 57 deletions.
4 changes: 2 additions & 2 deletions app/Models/BaselinesPoliciesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ public function create($data = null): ?int
if ($data->table === 'software') {
$columns = array('name', 'version', 'version_padded');
$sql = "SELECT name, version, version_padded FROM software WHERE software.device_id = ? and current = 'y' and name != 'kernel' and name != 'kernel-devel' GROUP BY name, version, version_padded";
} else if ($data->table === 'netstat') {
} elseif ($data->table === 'netstat') {
$columns = array('protocol', 'program', 'port');
$sql = "SELECT protocol, program, port, CONCAT(`program`, ' on ', `port`, ' using ', `protocol`) AS `name` FROM netstat WHERE netstat.device_id = ? and current = 'y' GROUP BY protocol, program, port";
} else if ($data->table === 'user') {
} elseif ($data->table === 'user') {
$columns = array('name', 'status', 'type', 'password_expires', 'password_changeable', 'password_required');
$sql = "SELECT name, status, type, password_expires, password_changeable, password_required FROM user WHERE user.device_id = ? and current = 'y' GROUP BY name, status, type, password_expires, password_changeable, password_required";
}
Expand Down
6 changes: 3 additions & 3 deletions app/Models/ComponentsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function create($data = null): ?int
$device_ids = array();
if (!empty($data->device_id)) {
$device_ids[] = $data->device_id;
} else if (!empty($data->ids)) {
} elseif (!empty($data->ids)) {
$device_ids = explode(',', $data->ids);
}
if (empty($device_ids)) {
Expand Down Expand Up @@ -303,7 +303,7 @@ public function create($data = null): ?int
\Config\Services::session()->setFlashdata('warning', "Cannot move the uploaded image file to $target.");
return null;
}
} else if (!empty($data->filename)) {
} elseif (!empty($data->filename)) {
$sql = 'INSERT INTO `image` VALUES (NULL, ?, ?, ?, ?, ?, NOW())';
$this->db->query($sql, [$data->device_id, $data->name, $data->filename, $data->orientation, $instance->user->full_name]);
return true;
Expand Down Expand Up @@ -495,7 +495,7 @@ public function upsert(string $table = '', object $device = null, array $data =
$name = @$device->name;
if (empty($name) and !empty($device->hostname)) {
$name = $device->hostname;
} else if (!empty($device->ip)) {
} elseif (!empty($device->ip)) {
$name = $device->ip;
}
if (!$this->db->tableExists($table)) {
Expand Down
26 changes: 13 additions & 13 deletions app/Models/DevicesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,31 @@ public function collection(object $resp): array
$result[$i]->audit_class = 'fa fa-times text-danger';
$result[$i]->audit_text = 'Nmap discovered, data retrieval will be very limited.';
# NOT GOOD
} else if ($result[$i]->last_seen_by === 'nmap' and $result[$i]->type !== 'unclassified' and $result[$i]->type !== 'unknown') {
} elseif ($result[$i]->last_seen_by === 'nmap' and $result[$i]->type !== 'unclassified' and $result[$i]->type !== 'unknown') {
$result[$i]->audit_class = 'fa fa-exclamation-triangle text-warning';
$result[$i]->audit_text = 'Last discovery only Nmap worked. This may be an issue, or it may be a device of a type we cannot audit.';
} else if ($result[$i]->last_seen_by === 'cloud') {
} elseif ($result[$i]->last_seen_by === 'cloud') {
#$result[$i]->audit_class = 'fa fa-times text-info';
$result[$i]->audit_class = 'fa fa-exclamation-triangle text-warning';
$result[$i]->audit_text = 'Cloud import, data retrieval will be very limited.';
} else if ($result[$i]->last_seen_by === 'integrations') {
} elseif ($result[$i]->last_seen_by === 'integrations') {
#$result[$i]->audit_class = 'fa fa-times text-info';
$result[$i]->audit_class = 'fa fa-exclamation-triangle text-warning';
$result[$i]->audit_text = 'Integration import, data retrieval will be very limited.';
} else if ($result[$i]->type === 'computer' and ($result[$i]->last_seen_by === 'ssh' or $result[$i]->last_seen_by === 'windows' or $result[$i]->last_seen_by === 'wmi' or $result[$i]->last_seen_by === 'snmp')) {
} elseif ($result[$i]->type === 'computer' and ($result[$i]->last_seen_by === 'ssh' or $result[$i]->last_seen_by === 'windows' or $result[$i]->last_seen_by === 'wmi' or $result[$i]->last_seen_by === 'snmp')) {
$result[$i]->audit_class = 'fa fa-exclamation-triangle text-warning';
$result[$i]->audit_text = 'Partially discovered computer. Data retrieval limited.';
} else if ($result[$i]->last_seen_by === 'web form') {
} elseif ($result[$i]->last_seen_by === 'web form') {
$result[$i]->audit_class = 'fa fa-exclamation-triangle text-warning';
$result[$i]->audit_text = 'Manually created ' . $result[$i]->type . '. Data retrieval limited.';
# GOOD
} else if ($result[$i]->type === 'computer' and ($result[$i]->last_seen_by === 'audit_wmi' or $result[$i]->last_seen_by === 'audit_ssh')) {
} elseif ($result[$i]->type === 'computer' and ($result[$i]->last_seen_by === 'audit_wmi' or $result[$i]->last_seen_by === 'audit_ssh')) {
$result[$i]->audit_class = 'fa fa-check text-success';
$result[$i]->audit_text = 'Discovered and audited computer.';
} else if ($result[$i]->type === 'computer' and $result[$i]->last_seen_by === 'audit') {
} elseif ($result[$i]->type === 'computer' and $result[$i]->last_seen_by === 'audit') {
$result[$i]->audit_class = 'fa fa-check text-success';
$result[$i]->audit_text = 'Audited computer.';
} else if ($result[$i]->type !== 'computer' and !empty($result[$i]->snmp_oid)) {
} elseif ($result[$i]->type !== 'computer' and !empty($result[$i]->snmp_oid)) {
$result[$i]->audit_class = 'fa fa-check text-success';
$result[$i]->audit_text = 'Discovered and audited ' . $result[$i]->type . '.';
# BAD - FALLBACK
Expand Down Expand Up @@ -162,19 +162,19 @@ public function create($data = null): ?int
$temp = explode('.', $data->hostname);
$data->name = $temp[0];
}
} else if (!empty($data->sysName)) {
} elseif (!empty($data->sysName)) {
$data->name = strtolower($data->sysName);
if (strpos($data->sysName, '.') !== false) {
$temp = explode('.', $data->sysName);
$data->name = $temp[0];
}
} else if (!empty($data->dns_hostname)) {
} elseif (!empty($data->dns_hostname)) {
$data->name = strtolower($data->dns_hostname);
if (strpos($data->dns_hostname, '.') !== false) {
$temp = explode('.', $data->dns_hostname);
$data->name = $temp[0];
}
} else if (!empty($data->ip)) {
} elseif (!empty($data->ip)) {
$data->name = ip_address_from_db($data->ip);
} else {
$data->name = '';
Expand Down Expand Up @@ -260,7 +260,7 @@ public function setIdentification(int $id = 0): bool
if ($device->type !== 'unknown' && $device->type !== 'unclassified') {
if ($device->type === 'computer' && $device->class !== '') {
$identification = ucfirst($device->class);
} else if ($device->type === 'computer' && $device->os_group !== '') {
} elseif ($device->type === 'computer' && $device->os_group !== '') {
$identification = 'Computer running ' . $device->os_group;
} else {
if ($device->type !== 'iphone' && $device->type !== 'ipod' && $device->type !== 'ipad') {
Expand Down Expand Up @@ -796,7 +796,7 @@ public function update($id = null, $data = null): bool
if (!empty($data->discovery_id)) {
$log->discovery_id = $data->discovery_id;
$GLOBALS['discovery_id'] = $data->discovery_id;
} else if (!empty($GLOBALS['discovery_id'])) {
} elseif (!empty($GLOBALS['discovery_id'])) {
$log->discovery_id = $GLOBALS['discovery_id'];
} else {
$log->discovery_id = '';
Expand Down
Loading

0 comments on commit b65ecb9

Please sign in to comment.