Passed
Push — master ( 2fe5ea...055735 )
by Matthieu
02:04
created
src/Iterators/RangeIterator.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -92,8 +92,7 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
src/Iterators/SubnetIterator.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -93,8 +93,7 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
src/IPv4/Address.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
      * @return self
103 103
      */
104 104
 
105
-    public static function fromArray(Array $address)
105
+    public static function fromArray(array $address)
106 106
     {
107 107
         if( count($address) != 4)
108 108
         {
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
src/IPv4/Range.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -89,8 +89,7 @@
 block discarded – undo
89 89
         if ($count<0)
90 90
         {
91 91
             $delta = $count+1;
92
-        }
93
-        else
92
+        } else
94 93
         {
95 94
             $delta = $count-1;
96 95
         }
Please login to merge, or discard this patch.
src/IPv4/Netmask.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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)
Please login to merge, or discard this patch.
test.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
src/IPv4/Subnet.php 2 patches
Indentation   +9 added lines, -10 removed lines patch added patch discarded remove patch
@@ -24,7 +24,6 @@  discard block
 block discarded – undo
24 24
  *  * Countable : number of addresses
25 25
  *  * ArrayAccess : Address can be acceesed by offset (ex : $range[10])
26 26
  *  * IteratorAggregate :   range can be itrated (foreach)
27
-
28 27
  * @package IPTools
29 28
  */
30 29
 class Subnet extends Range
@@ -34,13 +33,13 @@  discard block
 block discarded – undo
34 33
      */
35 34
     protected $netmask;
36 35
 
37
-     /**
38
-     * Creates an IP Subnet from a an IP network addresses and a netamsk
39
-     *
40
-     * @param Address $baseAddress the first address of the range
41
-     * @param int $count the number  other bound
42
-     * @param bool $strict if true $network
43
-     */
36
+        /**
37
+         * Creates an IP Subnet from a an IP network addresses and a netamsk
38
+         *
39
+         * @param Address $baseAddress the first address of the range
40
+         * @param int $count the number  other bound
41
+         * @param bool $strict if true $network
42
+         */
44 43
     public function __construct(Address $network, Address $netmask, bool $strict=true)
45 44
     {
46 45
         $finalNetmask = clone($netmask);
@@ -61,7 +60,7 @@  discard block
 block discarded – undo
61 60
         $this->netmask = $finalNetmask;
62 61
     }
63 62
 
64
-   /**
63
+    /**
65 64
      * Construct an IPv4 Subnet from a CIDR notation (#.#.#.#/#)
66 65
      *
67 66
      * @param Address $network the network base address  of the subnet
@@ -168,7 +167,7 @@  discard block
 block discarded – undo
168 167
         return static::fromCidr(
169 168
             $this->getNetworkAddress()->shift($offset*count($this)),
170 169
             $this->getNetmaskAddress()->asCidr()
171
-         );
170
+            );
172 171
     }
173 172
 
174 173
     /*
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,23 +41,23 @@  discard block
 block discarded – undo
41 41
      * @param int $count the number  other bound
42 42
      * @param bool $strict if true $network
43 43
      */
44
-    public function __construct(Address $network, Address $netmask, bool $strict=true)
44
+    public function __construct(Address $network, Address $netmask, bool $strict = true)
45 45
     {
46 46
         $finalNetmask = clone($netmask);
47
-        if (!($netmask instanceof Netmask))
47
+        if(!($netmask instanceof Netmask))
48 48
         {
49 49
             $finalNetmask = Netmask::fromAddress($netmask);  
50 50
         }
51 51
         
52 52
         // Verify parameters validity
53
-        if( (($network->int() & $finalNetmask->int()) != $network->int()) && $strict)
53
+        if((($network->int() & $finalNetmask->int())!=$network->int()) && $strict)
54 54
         {
55 55
             throw new RangeException(sprintf("Invalid network adress %s, this address is not usable with the netmask %s", (string)$network, (string)$finalNetmask));
56 56
         }
57 57
 
58 58
         $finalNetwork = new Address($network->int() & $finalNetmask->int());
59 59
 
60
-        parent::__construct($finalNetwork, $finalNetwork->shift(count($finalNetmask)-1));
60
+        parent::__construct($finalNetwork, $finalNetwork->shift(count($finalNetmask) - 1));
61 61
         $this->netmask = $finalNetmask;
62 62
     }
63 63
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      * @throws RangeException when network address and netmask does not form a valid subnet 
72 72
      * @return Subnet
73 73
      */
74
-    public static function fromCidr(Address $network, int $cidr, bool $strict=true)
74
+    public static function fromCidr(Address $network, int $cidr, bool $strict = true)
75 75
     {
76 76
         // Ensure CIDR is valid, use Address::fromCidr to have validation logic in only one place 
77 77
         $netmask = Netmask::fromCidr($cidr);
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
      * @throws InvaidArgumentException when provided sting cannot be converted to a valid subnet
109 109
      * @return Subnet
110 110
      */
111
-    public static function fromString(string $subnet, bool $strict=true)
111
+    public static function fromString(string $subnet, bool $strict = true)
112 112
     {
113 113
         @list($address, $netmask, $trash) = explode('/', $subnet);
114
-        if (!is_null($trash) || is_null($netmask))
114
+        if(!is_null($trash) || is_null($netmask))
115 115
         {
116 116
             throw new InvalidArgumentException(sprintf("%s cannot be converted to subnet. Valid formats are : x.x.x.x/cidr or x.x.x.x/y.y.y.y", $subnet));
117 117
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     public function shift(int $offset)
167 167
     {
168 168
         return static::fromCidr(
169
-            $this->getNetworkAddress()->shift($offset*count($this)),
169
+            $this->getNetworkAddress()->shift($offset * count($this)),
170 170
             $this->getNetmaskAddress()->asCidr()
171 171
          );
172 172
     }
Please login to merge, or discard this patch.
src/IPv4/IPv4.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
  */
7 7
 namespace mracine\IPTools\IPv4;
8 8
 
9
-use mracine\IPTools\IPVersion;;
9
+use mracine\IPTools\IPVersion; ;
10 10
 
11 11
 trait IPv4
12 12
 {
Please login to merge, or discard this patch.