@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function __construct(Address $network, Address $netmask) |
| 47 | 47 | { |
| 48 | - if (!($netmask instanceof Netmask)) |
|
| 48 | + if(!($netmask instanceof Netmask)) |
|
| 49 | 49 | { |
| 50 | 50 | /** |
| 51 | 51 | * @todo implement |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | throw new InvalidArgumentException("Not implemented"); |
| 54 | 54 | } |
| 55 | 55 | // Verify parameters validity |
| 56 | - if( ($network->int() & $netmask->int()) != $network->int()) |
|
| 56 | + if(($network->int() & $netmask->int())!=$network->int()) |
|
| 57 | 57 | { |
| 58 | 58 | throw new RangeException(sprintf("Invalid network adress %s, this address is not usable with the netmask %s", (string)$network, (string)$netmask)); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | |
| 63 | - parent::__construct($network, $network->shift(count($netmask)-1)); |
|
| 63 | + parent::__construct($network, $network->shift(count($netmask) - 1)); |
|
| 64 | 64 | $this->netmask = $netmask; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | public function shift(int $offset) |
| 152 | 152 | { |
| 153 | 153 | return static::fromCidr( |
| 154 | - $this->getNetworkAddress()->shift($offset*count($this)), |
|
| 154 | + $this->getNetworkAddress()->shift($offset * count($this)), |
|
| 155 | 155 | $this->getNetmaskAddress()->asCidr() |
| 156 | 156 | ); |
| 157 | 157 | } |
@@ -38,22 +38,22 @@ discard block |
||
| 38 | 38 | public function __construct(int $netmask) |
| 39 | 39 | { |
| 40 | 40 | parent::__construct($netmask); |
| 41 | - if (0==$netmask) |
|
| 41 | + if(0==$netmask) |
|
| 42 | 42 | { |
| 43 | 43 | return; |
| 44 | 44 | } |
| 45 | 45 | // Netamsk validation |
| 46 | 46 | $mask = 0xffffffff; |
| 47 | 47 | do { |
| 48 | - if ($mask == $netmask) |
|
| 48 | + if($mask==$netmask) |
|
| 49 | 49 | { |
| 50 | 50 | // valid netmask |
| 51 | 51 | return; |
| 52 | 52 | } |
| 53 | 53 | $mask = ($mask << 1) & 0xffffffff; |
| 54 | - } while ($mask>0); |
|
| 54 | + } while($mask>0); |
|
| 55 | 55 | |
| 56 | - if ($netmask!=0) |
|
| 56 | + if($netmask!=0) |
|
| 57 | 57 | { |
| 58 | 58 | throw new DomainException(sprintf("Cannot convert 0x%x (%s) to netmask", $netmask, (string)$this)); |
| 59 | 59 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public static function fromCidr(int $cidr) |
| 76 | 76 | { |
| 77 | - if ($cidr<0 || $cidr>32 ) |
|
| 77 | + if($cidr<0 || $cidr>32) |
|
| 78 | 78 | { |
| 79 | 79 | throw new OutOfBoundsException(sprintf("Invalid CIDR value %d", $cidr)); |
| 80 | 80 | } |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | public function asCidr() |
| 105 | 105 | { |
| 106 | 106 | // Pas très élégant.... |
| 107 | - for ($cidr=32 ; $cidr>=0 ; $cidr--) |
|
| 107 | + for($cidr = 32; $cidr>=0; $cidr--) |
|
| 108 | 108 | { |
| 109 | 109 | $n = (0xffffffff << (32 - $cidr)) & 0xffffffff; |
| 110 | - if( $n == $this->int() ) |
|
| 110 | + if($n==$this->int()) |
|
| 111 | 111 | { |
| 112 | 112 | return $cidr; |
| 113 | 113 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function count() |
| 123 | 123 | { |
| 124 | - return (~($this->int()) & 0xffffffff)+1; |
|
| 124 | + return (~($this->int()) & 0xffffffff) + 1; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | public function shift(int $offset) |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | $lower = $lowerBound->int(); |
| 64 | 64 | $upper = $upperBound->int(); |
| 65 | - if ($lower > $upper) |
|
| 65 | + if($lower>$upper) |
|
| 66 | 66 | { |
| 67 | 67 | $temp = $lower; |
| 68 | 68 | $lower = $upper; |
@@ -82,17 +82,17 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public static function fromCount(Address $baseAddress, int $count) |
| 84 | 84 | { |
| 85 | - if ($count == 0) |
|
| 85 | + if($count==0) |
|
| 86 | 86 | { |
| 87 | 87 | throw new InvalidArgumentException("Cannot assign a range of 0 addresses"); |
| 88 | 88 | } |
| 89 | - if ($count<0) |
|
| 89 | + if($count<0) |
|
| 90 | 90 | { |
| 91 | - $delta = $count+1; |
|
| 91 | + $delta = $count + 1; |
|
| 92 | 92 | } |
| 93 | 93 | else |
| 94 | 94 | { |
| 95 | - $delta = $count-1; |
|
| 95 | + $delta = $count - 1; |
|
| 96 | 96 | } |
| 97 | 97 | $upperBound = $baseAddress->shift($delta); |
| 98 | 98 | return new static($baseAddress, $upperBound); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function getUpperBound() |
| 122 | 122 | { |
| 123 | - return new Address($this->getLowerBound()->int()+$this->count-1); |
|
| 123 | + return new Address($this->getLowerBound()->int() + $this->count - 1); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | public function match(Range $range) |
| 151 | 151 | { |
| 152 | - return ( ($this->getLowerBound()->int()==$range->getLowerBound()->int()) && ($this->getUpperBound()->int()==$range->getUpperBound()->int())); |
|
| 152 | + return (($this->getLowerBound()->int()==$range->getLowerBound()->int()) && ($this->getUpperBound()->int()==$range->getUpperBound()->int())); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | public function shift(int $offset) |
| 175 | 175 | { |
| 176 | - return static::fromCount($this->getLowerBound()->shift($offset*count($this)), count($this)); |
|
| 176 | + return static::fromCount($this->getLowerBound()->shift($offset * count($this)), count($this)); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -217,19 +217,19 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | public function offsetExists($offset) |
| 219 | 219 | { |
| 220 | - if (is_string($offset)) |
|
| 220 | + if(is_string($offset)) |
|
| 221 | 221 | { |
| 222 | - if (!preg_match('/^-?[0-9]+$/', $offset)) |
|
| 222 | + if(!preg_match('/^-?[0-9]+$/', $offset)) |
|
| 223 | 223 | { |
| 224 | 224 | 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))); |
| 225 | 225 | } |
| 226 | 226 | $offset = (int)$offset; |
| 227 | 227 | } |
| 228 | - if (!is_int($offset)) |
|
| 228 | + if(!is_int($offset)) |
|
| 229 | 229 | { |
| 230 | 230 | 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))); |
| 231 | 231 | } |
| 232 | - if ($offset<0 || $offset>=count($this)) |
|
| 232 | + if($offset<0 || $offset>=count($this)) |
|
| 233 | 233 | { |
| 234 | 234 | return false; |
| 235 | 235 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function offsetGet($offset) |
| 250 | 250 | { |
| 251 | - if (!$this->offsetExists($offset)) |
|
| 251 | + if(!$this->offsetExists($offset)) |
|
| 252 | 252 | { |
| 253 | 253 | throw new OutOfBoundsException(); |
| 254 | 254 | } |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @param Address $value |
| 266 | 266 | * @throws BadMethodCallException always |
| 267 | 267 | */ |
| 268 | - public function offsetSet($offset, $value) |
|
| 268 | + public function offsetSet($offset, $value) |
|
| 269 | 269 | { |
| 270 | 270 | throw new BadMethodCallException(sprintf("class %s is immutable, cannot modify an address value in a Range", self::class)); |
| 271 | 271 | } |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public function __construct(int $address) |
| 65 | 65 | { |
| 66 | - if ($address<0 || $address>0xffffffff) |
|
| 66 | + if($address<0 || $address>0xffffffff) |
|
| 67 | 67 | { |
| 68 | 68 | throw new OutOfBoundsException(sprintf("Cannot convert 0x%x to an IPv4 address", $address)); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - $this->address = $address; |
|
| 71 | + $this->address = $address; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | public static function fromArray(Array $address) |
| 107 | 107 | { |
| 108 | - if( count($address) != 4) |
|
| 108 | + if(count($address)!=4) |
|
| 109 | 109 | { |
| 110 | 110 | throw new InvalidArgumentException(sprintf("Array must contain 4 digits, %d found", count($address))); |
| 111 | 111 | } |
@@ -113,19 +113,19 @@ discard block |
||
| 113 | 113 | $buffer = 0; |
| 114 | 114 | foreach($address as $digit) |
| 115 | 115 | { |
| 116 | - if (is_string($digit) ) |
|
| 116 | + if(is_string($digit)) |
|
| 117 | 117 | { |
| 118 | 118 | $digit = trim($digit); |
| 119 | - if (strlen($digit)==0) |
|
| 119 | + if(strlen($digit)==0) |
|
| 120 | 120 | { |
| 121 | 121 | throw new InvalidArgumentException(sprintf("The array must contains only integers or strings with integer content , string found with empty value")); |
| 122 | 122 | } |
| 123 | - if ( $digit[0] == '-' && ctype_digit(ltrim($digit, '-')) ) |
|
| 123 | + if($digit[0]=='-' && ctype_digit(ltrim($digit, '-'))) |
|
| 124 | 124 | { |
| 125 | 125 | // string type : "-123" |
| 126 | 126 | throw new OutOfBoundsException(sprintf("Cannot convert %d to Ipv4 addresss digit", $digit)); |
| 127 | 127 | } |
| 128 | - if (!ctype_digit($digit)) |
|
| 128 | + if(!ctype_digit($digit)) |
|
| 129 | 129 | { |
| 130 | 130 | throw new InvalidArgumentException(sprintf("The array must contains only integers or strings with integer content , string found with bad value %s", $digit)); |
| 131 | 131 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $digit = (int)$digit; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if (!is_integer($digit) ) |
|
| 136 | + if(!is_integer($digit)) |
|
| 137 | 137 | { |
| 138 | 138 | throw new InvalidArgumentException(sprintf("The array must contains only integers or strings with integer content , %s found", gettype($digit))); |
| 139 | 139 | } |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | */ |
| 246 | 246 | public function match(Address $address) |
| 247 | 247 | { |
| 248 | - return $this->int() == $address->int(); |
|
| 248 | + return $this->int()==$address->int(); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -257,23 +257,23 @@ discard block |
||
| 257 | 257 | { |
| 258 | 258 | $higherOctet = $this->address >> 24; |
| 259 | 259 | |
| 260 | - if (($higherOctet & 0x80) == 0) { |
|
| 260 | + if(($higherOctet & 0x80)==0) { |
|
| 261 | 261 | return self::CLASS_A; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - if (($higherOctet & 0xC0) == 0x80) { |
|
| 264 | + if(($higherOctet & 0xC0)==0x80) { |
|
| 265 | 265 | return self::CLASS_B; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - if (($higherOctet & 0xE0) == 0xC0) { |
|
| 268 | + if(($higherOctet & 0xE0)==0xC0) { |
|
| 269 | 269 | return self::CLASS_C; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - if (($higherOctet & 0xF0) == 0xE0) { |
|
| 272 | + if(($higherOctet & 0xF0)==0xE0) { |
|
| 273 | 273 | return self::CLASS_D; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - if (($higherOctet & 0xF0) == 0xF0) { |
|
| 276 | + if(($higherOctet & 0xF0)==0xF0) { |
|
| 277 | 277 | return self::CLASS_E; |
| 278 | 278 | } |
| 279 | 279 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | */ |
| 291 | 291 | public function isMulticast() |
| 292 | 292 | { |
| 293 | - return $this->getClass() === self::CLASS_D; |
|
| 293 | + return $this->getClass()===self::CLASS_D; |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | */ |
| 382 | 382 | public function isPrivate() |
| 383 | 383 | { |
| 384 | - return ($this->isRFC1918() || $this->isRFC6598()); |
|
| 384 | + return ($this->isRFC1918() || $this->isRFC6598()); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | */ |
| 396 | 396 | public function shift(int $offset) |
| 397 | 397 | { |
| 398 | - return new static($this->address+$offset); |
|
| 398 | + return new static($this->address + $offset); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | /** |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | $a = 0xffffffff; |
| 3 | -printf ("%d\n",$a); |
|
| 3 | +printf("%d\n", $a); |
|
| 4 | 4 | |
| 5 | -$a = -(0xffffffff)-1; |
|
| 6 | -printf ("%d\n",$a); |
|
| 5 | +$a = -(0xffffffff) - 1; |
|
| 6 | +printf("%d\n", $a); |
|