Completed
Push — master ( 913bce...ed0758 )
by Matthieu
03:23
created
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.