Skip to content

Commit

Permalink
Codacy cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
oyeaussie committed Sep 12, 2024
1 parent 5e79230 commit 12ad2c2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
6 changes: 1 addition & 5 deletions src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,7 @@ public function downloadData($url, $sink)
[
'progress' => function(
$downloadTotal,
$downloadedBytes,
$uploadTotal,
$uploadedBytes
$downloadedBytes
) {
if ($downloadTotal === 0 || $downloadedBytes === 0) {
return;
Expand Down Expand Up @@ -698,8 +696,6 @@ public function importFilters($fileName)

$csv->setHeaderOffset(0);

$header = $csv->getHeader();

$records = $csv->getRecords();

$totalCount = $csv->count();
Expand Down
21 changes: 9 additions & 12 deletions src/Firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function getFilters($defaultStore = false)
if (count($ip2locationSortArr) > 0) {
ksort($ip2locationSortArr);

foreach ($ip2locationSortArr as $ip2locationSortKey => $ip2locationSort) {
foreach (array_keys($ip2locationSortArr) as $ip2locationSortKey) {
$filters = array_merge($filters, $ip2locationSortArr[$ip2locationSortKey]);
}
}
Expand Down Expand Up @@ -390,7 +390,6 @@ public function addFilter(array $data, $defaultStore = false)

if (isset($data['address'])) {
if ($data['address_type'] === 'host' || $data['address_type'] === 'network') {

if ($data['address_type'] === 'network' &&
!str_contains($data['address'], '/')
) {
Expand All @@ -408,13 +407,13 @@ public function addFilter(array $data, $defaultStore = false)
}

if ($data['address_type'] === 'network') {
try {
if (str_contains($data['address'], ':')) {
$range = $this->ip2location->ipTools->cidrToIpv6($data['address']);
} else {
$range = $this->ip2location->ipTools->cidrToIpv4($data['address']);
}
} catch (\throwable $e) {
if (str_contains($data['address'], ':')) {
$range = $this->ip2location->ipTools->cidrToIpv6($data['address']);
} else {
$range = $this->ip2location->ipTools->cidrToIpv4($data['address']);
}

if (!isset($range['ip_start']) && !isset($range['ip_end'])) {
$this->addResponse('Please type correct network address. Format is CIDR - network address/network mask', 1);

return false;
Expand Down Expand Up @@ -622,8 +621,6 @@ public function moveFilter($id)//Move filter from default store to main store
return false;
}

$oldFilterId = $filter['id'];

unset($filter['id']);

$newFilter = $this->addFilter($filter);
Expand Down Expand Up @@ -695,7 +692,7 @@ public function validateIP($address)
$allow_reserved_range = false;
}

if (!$allow_private_range) {
if (!$allow_reserved_range) {
if (!filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) {
$this->addResponse('Please enter correct ip address, reserved range is not allowed.', 1);

Expand Down
2 changes: 2 additions & 0 deletions src/Indexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ public function removeFromIndex($ip)
protected function cleanupPath(array $pathArr)
{
foreach ($pathArr as $path) {
$path = null;//We dont need path as we will be popping it in the end.

$checkPath = join('/', $pathArr);

$folders = $this->firewall->localContent->listContents($checkPath)->toArray() ;
Expand Down
2 changes: 1 addition & 1 deletion src/Ip2location.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function processDownloadedBinFile($download, $trackCounter = null, $proxy

$renamedFile = false;

foreach ($folderContents as $key => $content) {
foreach ($folderContents as $content) {
if ($content instanceof FileAttributes) {
if ($proxy &&
str_contains($content->path(), '.BIN') &&
Expand Down

0 comments on commit 12ad2c2

Please sign in to comment.