@@ -93,7 +93,7 @@ |
||
| 93 | 93 | { |
| 94 | 94 | $this->range[$this->index]; |
| 95 | 95 | } |
| 96 | - catch(\Exception $e) |
|
| 96 | + catch (\Exception $e) |
|
| 97 | 97 | { |
| 98 | 98 | return false; |
| 99 | 99 | } |
@@ -92,8 +92,7 @@ |
||
| 92 | 92 | try |
| 93 | 93 | { |
| 94 | 94 | $this->range[$this->index]; |
| 95 | - } |
|
| 96 | - catch(\Exception $e) |
|
| 95 | + } catch(\Exception $e) |
|
| 97 | 96 | { |
| 98 | 97 | return false; |
| 99 | 98 | } |
@@ -94,7 +94,7 @@ |
||
| 94 | 94 | { |
| 95 | 95 | $this->subnet[$this->index]; |
| 96 | 96 | } |
| 97 | - catch(\Exception $e) |
|
| 97 | + catch (\Exception $e) |
|
| 98 | 98 | { |
| 99 | 99 | return false; |
| 100 | 100 | } |
@@ -93,8 +93,7 @@ |
||
| 93 | 93 | try |
| 94 | 94 | { |
| 95 | 95 | $this->subnet[$this->index]; |
| 96 | - } |
|
| 97 | - catch(\Exception $e) |
|
| 96 | + } catch(\Exception $e) |
|
| 98 | 97 | { |
| 99 | 98 | return false; |
| 100 | 99 | } |
@@ -23,7 +23,6 @@ discard block |
||
| 23 | 23 | * * Countable : number of addresses |
| 24 | 24 | * * ArrayAccess : Address can be acceesed by offset (ex : $range[10]) |
| 25 | 25 | * * IteratorAggregate : range can be itrated (foreach) |
| 26 | - |
|
| 27 | 26 | * @package IPTools |
| 28 | 27 | */ |
| 29 | 28 | class Subnet implements IP, \Countable, \ArrayAccess, \IteratorAggregate |
@@ -37,7 +36,6 @@ discard block |
||
| 37 | 36 | * Netmask of the subnet |
| 38 | 37 | * |
| 39 | 38 | * Stored as a 32 bits integer |
| 40 | - |
|
| 41 | 39 | * /24 => 255.255.255.0 => 0xffffff00 |
| 42 | 40 | * |
| 43 | 41 | * @var int nemask |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | // Ensure CIDR is valid, use Address::fromCidr to have validation logic in only one place |
| 58 | 58 | $netmask = Address::fromCidr($cidr)->int(); |
| 59 | 59 | $address = $network->int(); |
| 60 | - if( ($address & $netmask) != $address) |
|
| 60 | + if (($address & $netmask)!=$address) |
|
| 61 | 61 | { |
| 62 | 62 | throw new RangeException(sprintf("Invalid network adress %s, this address is not usable with the CIDR %d", (string)$network, $cidr)); |
| 63 | 63 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | public function getBroadcastAddress() |
| 153 | 153 | { |
| 154 | 154 | $netmask_inverted = (0xffffffff & ~$this->netmask); |
| 155 | - $intBroadcast = ($this->network->int() | $netmask_inverted); |
|
| 155 | + $intBroadcast = ($this->network->int() | $netmask_inverted); |
|
| 156 | 156 | return Address::fromInteger($intBroadcast); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | public function contains(Address $ip) |
| 166 | 166 | { |
| 167 | - return (($this->network->int() & $this->netmask) == ($ip->int() & $this->netmask)); |
|
| 167 | + return (($this->network->int() & $this->netmask)==($ip->int() & $this->netmask)); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public function count() |
| 189 | 189 | { |
| 190 | - return (~$this->netmask & 0xffffffff)+1; |
|
| 190 | + return (~$this->netmask & 0xffffffff) + 1; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | public function shift(int $offset) |
| 214 | 214 | { |
| 215 | 215 | // On décale l'adresse de réseau en fonction de la taille du subnet |
| 216 | - $newNetwork = Address::fromInteger($this->getNetworkAddress()->int() + ($offset*count($this))); |
|
| 216 | + $newNetwork = Address::fromInteger($this->getNetworkAddress()->int() + ($offset * count($this))); |
|
| 217 | 217 | |
| 218 | 218 | // On évite de manipuler directement les propriétés network d'un nouvek objet |
| 219 | 219 | // pour profiter de la validation en cas de dépassement des bornes. |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @throws BadMethodCallException always |
| 323 | 323 | */ |
| 324 | 324 | |
| 325 | - public function offsetSet($offset, $value) |
|
| 325 | + public function offsetSet($offset, $value) |
|
| 326 | 326 | { |
| 327 | 327 | throw new BadMethodCallException(sprintf("class %s is immutable, cannot modify an address value in a Subnet", self::class)); |
| 328 | 328 | } |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | * @see https://en.wikipedia.org/wiki/Classful_network |
| 37 | 37 | */ |
| 38 | 38 | const CLASS_A = "A", |
| 39 | - CLASS_B = "B", |
|
| 40 | - CLASS_C = "C", |
|
| 41 | - CLASS_D = "D", |
|
| 42 | - CLASS_E = "E"; |
|
| 39 | + CLASS_B = "B", |
|
| 40 | + CLASS_C = "C", |
|
| 41 | + CLASS_D = "D", |
|
| 42 | + CLASS_E = "E"; |
|
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * IPv4 addresses are stored as a 32 bits integer |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | * @param self $address |
| 405 | 405 | * @return bool |
| 406 | 406 | */ |
| 407 | - public function match(Address $address) |
|
| 407 | + public function match(Address $address) |
|
| 408 | 408 | { |
| 409 | 409 | return $this->int() == $address->int(); |
| 410 | 410 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $this->address = $address; |
|
| 70 | + $this->address = $address; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -104,22 +104,22 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | public static function fromArray(Array $address) |
| 106 | 106 | { |
| 107 | - if( count($address) != 4) |
|
| 107 | + if (count($address)!=4) |
|
| 108 | 108 | { |
| 109 | 109 | throw new InvalidArgumentException(sprintf("Array must contain 4 digits, %d found", count($address))); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $buffer = 0; |
| 113 | - foreach($address as $digit) |
|
| 113 | + foreach ($address as $digit) |
|
| 114 | 114 | { |
| 115 | - if (is_string($digit) ) |
|
| 115 | + if (is_string($digit)) |
|
| 116 | 116 | { |
| 117 | 117 | $digit = trim($digit); |
| 118 | 118 | if (strlen($digit)==0) |
| 119 | 119 | { |
| 120 | 120 | throw new InvalidArgumentException(sprintf("The array must contains only integers or strings with integer content , string found with empty value")); |
| 121 | 121 | } |
| 122 | - if ( $digit[0] == '-' && ctype_digit(ltrim($digit, '-')) ) |
|
| 122 | + if ($digit[0]=='-' && ctype_digit(ltrim($digit, '-'))) |
|
| 123 | 123 | { |
| 124 | 124 | // string type : "-123" |
| 125 | 125 | throw new OutOfBoundsException(sprintf("Cannot convert %d to Ipv4 addresss digit", $digit)); |
@@ -132,12 +132,12 @@ discard block |
||
| 132 | 132 | $digit = (int)$digit; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if (!is_integer($digit) ) |
|
| 135 | + if (!is_integer($digit)) |
|
| 136 | 136 | { |
| 137 | 137 | throw new InvalidArgumentException(sprintf("The array must contains only integers or strings with integer content , %s found", gettype($digit))); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if($digit<0 || $digit>0xff) |
|
| 140 | + if ($digit<0 || $digit>0xff) |
|
| 141 | 141 | { |
| 142 | 142 | throw new OutOfBoundsException(sprintf("Cannot convert %d to Ipv4 addresss digit", $digit)); |
| 143 | 143 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public static function fromCidr(int $cidr) |
| 177 | 177 | { |
| 178 | - if ($cidr<0 || $cidr>32 ) |
|
| 178 | + if ($cidr<0 || $cidr>32) |
|
| 179 | 179 | { |
| 180 | 180 | throw new OutOfBoundsException(sprintf("Invalid CIDR value %d", $cidr)); |
| 181 | 181 | } |
@@ -235,10 +235,10 @@ discard block |
||
| 235 | 235 | { |
| 236 | 236 | // Pas très élégant.... |
| 237 | 237 | $cidr = 32; |
| 238 | - for ($cidr=32 ; $cidr>=0 ; $cidr--) |
|
| 238 | + for ($cidr = 32; $cidr>=0; $cidr--) |
|
| 239 | 239 | { |
| 240 | 240 | $n = (0xffffffff << (32 - $cidr)) & 0xffffffff; |
| 241 | - if( $n == $this->address ) |
|
| 241 | + if ($n==$this->address) |
|
| 242 | 242 | { |
| 243 | 243 | return $cidr; |
| 244 | 244 | } |
@@ -271,23 +271,23 @@ discard block |
||
| 271 | 271 | { |
| 272 | 272 | $higherOctet = $this->address >> 24; |
| 273 | 273 | |
| 274 | - if (($higherOctet & 0x80) == 0) { |
|
| 274 | + if (($higherOctet & 0x80)==0) { |
|
| 275 | 275 | return self::CLASS_A; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if (($higherOctet & 0xC0) == 0x80) { |
|
| 278 | + if (($higherOctet & 0xC0)==0x80) { |
|
| 279 | 279 | return self::CLASS_B; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if (($higherOctet & 0xE0) == 0xC0) { |
|
| 282 | + if (($higherOctet & 0xE0)==0xC0) { |
|
| 283 | 283 | return self::CLASS_C; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - if (($higherOctet & 0xF0) == 0xE0) { |
|
| 286 | + if (($higherOctet & 0xF0)==0xE0) { |
|
| 287 | 287 | return self::CLASS_D; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - if (($higherOctet & 0xF0) == 0xF0) { |
|
| 290 | + if (($higherOctet & 0xF0)==0xF0) { |
|
| 291 | 291 | return self::CLASS_E; |
| 292 | 292 | } |
| 293 | 293 | |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | { |
| 326 | 326 | $this->asCidr(); |
| 327 | 327 | } |
| 328 | - catch(DomainException $e) |
|
| 328 | + catch (DomainException $e) |
|
| 329 | 329 | { |
| 330 | 330 | return false; |
| 331 | 331 | } |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | Subnet::fromCidr(Address::fromString("172.16.0.0"), 12), |
| 354 | 354 | Subnet::fromCidr(Address::fromString("192.168.0.0"), 16), |
| 355 | 355 | ); |
| 356 | - foreach($subnets as $subnet) { |
|
| 357 | - if($subnet->contains($this)) { |
|
| 356 | + foreach ($subnets as $subnet) { |
|
| 357 | + if ($subnet->contains($this)) { |
|
| 358 | 358 | return true; |
| 359 | 359 | } |
| 360 | 360 | } |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | public function isPrivate() |
| 387 | 387 | { |
| 388 | - return ($this->isRFC1918() || $this->isRFC6598()); |
|
| 388 | + return ($this->isRFC1918() || $this->isRFC6598()); |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | /** |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | */ |
| 396 | 396 | public function isMulticast() |
| 397 | 397 | { |
| 398 | - return $this->getClass() === self::CLASS_D; |
|
| 398 | + return $this->getClass()===self::CLASS_D; |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | /** |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | */ |
| 407 | 407 | public function match(Address $address) |
| 408 | 408 | { |
| 409 | - return $this->int() == $address->int(); |
|
| 409 | + return $this->int()==$address->int(); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | */ |
| 421 | 421 | public function shift(int $offset) |
| 422 | 422 | { |
| 423 | - return self::fromInteger($this->address+$offset); |
|
| 423 | + return self::fromInteger($this->address + $offset); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -324,8 +324,7 @@ |
||
| 324 | 324 | try |
| 325 | 325 | { |
| 326 | 326 | $this->asCidr(); |
| 327 | - } |
|
| 328 | - catch(DomainException $e) |
|
| 327 | + } catch(DomainException $e) |
|
| 329 | 328 | { |
| 330 | 329 | return false; |
| 331 | 330 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function offsetExists($offset) |
| 150 | 150 | { |
| 151 | - if (is_string($offset)) |
|
| 151 | + if (is_string($offset)) |
|
| 152 | 152 | { |
| 153 | 153 | if (!preg_match('/^-?[0-9]+$/', $offset)) |
| 154 | 154 | { |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | } |
| 157 | 157 | $offset = (int)$offset; |
| 158 | 158 | } |
| 159 | - if (!is_int($offset)) |
|
| 159 | + if (!is_int($offset)) |
|
| 160 | 160 | { |
| 161 | 161 | throw new InvalidArgumentException(sprintf('Invalid key type (%s), only integers or strings representing integers can be used to acces address in a Range', gettype($offset))); |
| 162 | 162 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function __construct(Address $ip1, Address $ip2) |
| 52 | 52 | { |
| 53 | - if ($ip1->int() < $ip2->int()) |
|
| 53 | + if ($ip1->int()<$ip2->int()) |
|
| 54 | 54 | { |
| 55 | 55 | $this->lowerBound = clone($ip1); |
| 56 | 56 | $this->upperBound = clone($ip2); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | { |
| 99 | 99 | $ipVal = $ip->int(); |
| 100 | 100 | |
| 101 | - return ($ipVal>=$this->lowerBound->int()) && ($ipVal<=$this->upperBound->int() ); |
|
| 101 | + return ($ipVal>=$this->lowerBound->int()) && ($ipVal<=$this->upperBound->int()); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public function match(Range $range) |
| 114 | 114 | { |
| 115 | - return ( ($this->getLowerBound()->int()==$range->getLowerBound()->int()) && ($this->getUpperBound()->int()==$range->getUpperBound()->int())); |
|
| 115 | + return (($this->getLowerBound()->int()==$range->getLowerBound()->int()) && ($this->getUpperBound()->int()==$range->getUpperBound()->int())); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * @param Address $value |
| 197 | 197 | * @throws BadMethodCallException always |
| 198 | 198 | */ |
| 199 | - public function offsetSet($offset, $value) |
|
| 199 | + public function offsetSet($offset, $value) |
|
| 200 | 200 | { |
| 201 | 201 | throw new BadMethodCallException(sprintf("class %s is immutable, cannot modify an address value in a Range", self::class)); |
| 202 | 202 | } |
@@ -54,8 +54,7 @@ |
||
| 54 | 54 | { |
| 55 | 55 | $this->lowerBound = clone($ip1); |
| 56 | 56 | $this->upperBound = clone($ip2); |
| 57 | - } |
|
| 58 | - else |
|
| 57 | + } else |
|
| 59 | 58 | { |
| 60 | 59 | $this->lowerBound = clone($ip2); |
| 61 | 60 | $this->upperBound = clone($ip1); |