Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikuolan committed Oct 17, 2017
1 parent c845552 commit 89451f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A stand-alone class implementation of the IPv4+IPv6 IP+CIDR aggregator from CIDR

### How to install:

As a stand-alone PHP class, installing it is exceptionally easy. You can download the file containing the class, [aggregator.php](src/Aggregator.php), directly from this repository, and copy it to any projects that need it, or, if you'd prefer, you can install it using Composer:
As a stand-alone PHP class, installing it is exceptionally easy. You can download the file containing the class, [Aggregator.php](src/Aggregator.php), directly from this repository, and copy it to any projects that need it, or, if you'd prefer, you can install it using Composer:

`composer require cidram/aggregator`

Expand Down
29 changes: 7 additions & 22 deletions src/Aggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace CIDRAM\Aggregator;

/**
* Aggregator v1.1.0-DEV (last modified: 2017.10.12).
* Aggregator v1.1.0-DEV (last modified: 2017.10.17).
*
* Description: A stand-alone class implementation of the IPv4+IPv6 IP+CIDR
* aggregator from CIDRAM.
Expand Down Expand Up @@ -85,7 +85,6 @@ public function ExpandIPv4($Addr, $ValidateOnly = false, $FactorLimit = 32)
}
}
}

return $CIDRs;
}

Expand Down Expand Up @@ -150,14 +149,9 @@ public function ExpandIPv6($Addr, $ValidateOnly = false, $FactorLimit = 128)
if (count($NAddr) !== 8) {
return false;
}
$NAddr[0] = hexdec($NAddr[0]);
$NAddr[1] = hexdec($NAddr[1]);
$NAddr[2] = hexdec($NAddr[2]);
$NAddr[3] = hexdec($NAddr[3]);
$NAddr[4] = hexdec($NAddr[4]);
$NAddr[5] = hexdec($NAddr[5]);
$NAddr[6] = hexdec($NAddr[6]);
$NAddr[7] = hexdec($NAddr[7]);
for ($i = 0; $i < 8; $i++) {
$NAddr[$i] = hexdec($NAddr[$i]);
}
$CIDRs = [];
$Base = [0, 0, 0, 0, 0, 0, 0, 0];
for ($Cycle = 0; $Cycle < 8; $Cycle++) {
Expand Down Expand Up @@ -189,7 +183,6 @@ public function ExpandIPv6($Addr, $ValidateOnly = false, $FactorLimit = 128)
continue;
}
}

return $CIDRs;
}

Expand All @@ -203,7 +196,6 @@ public function aggregate($In)
$this->stripInvalidRangesAndSubs($this->Output);
$this->mergeRanges($this->Output);
$this->ProcessingTime = microtime(true) - $Begin;

return $this->Output;
}

Expand All @@ -216,7 +208,6 @@ private function stripInvalidCharactersAndSort(&$In)
}
$In = array_filter(array_unique(array_map(function ($Line) {
$Line = preg_replace(['~^[^0-9a-f:./]*~i', '~[ \t].*$~', '~[^0-9a-f:./]*$~i'], '', $Line);

return (!$Line || !preg_match('~[0-9a-f:./]+~i', $Line) || preg_match('~[^0-9a-f:./]+~i', $Line)) ? '' : $Line;
}, $In)));
usort($In, function ($A, $B) {
Expand All @@ -239,11 +230,7 @@ private function stripInvalidCharactersAndSort(&$In)
!$this->ExpandIPv4($B, true) && !$this->ExpandIPv6($B, true)
) ? '' : inet_pton($B);
if ($A === false) {
if ($B === false) {
return 0;
}

return 1;
return $B === false ? 0 : 1;
}
if ($B === false) {
return -1;
Expand All @@ -253,11 +240,9 @@ private function stripInvalidCharactersAndSort(&$In)
if ($ASize === $BSize) {
return 0;
}

return ($ASize > $BSize) ? 1 : -1;
return $ASize > $BSize ? 1 : -1;
}

return ($Compare < 0) ? -1 : 1;
return $Compare < 0 ? -1 : 1;
});
$In = implode("\n", $In);
}
Expand Down

0 comments on commit 89451f8

Please sign in to comment.