Skip to content

Commit

Permalink
Change method names.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelwilliams authored and rlanvin committed Apr 13, 2019
1 parent f1a17cb commit cb9eee8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
20 changes: 17 additions & 3 deletions src/IPBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function getBroadcastAddress(): IP
*
* @return string
*/
public function getGivenIpWithPrefixlen(): string
public function getGivenIpWithPrefixLen(): string
{
return $this->given_ip.'/'.$this->prefix;
}
Expand Down Expand Up @@ -340,7 +340,7 @@ protected function checkPrefix($prefix)
*
* @return IPBlockIterator
*/
public function getSubblocks($prefix): IPBlockIterator
public function getSubBlocks($prefix): IPBlockIterator
{
$prefix = ltrim($prefix, '/');
$this->checkPrefix($prefix);
Expand All @@ -356,13 +356,27 @@ public function getSubblocks($prefix): IPBlockIterator
}

/**
* Return the superblock containing the current block.
* @deprecated since version 2.0 and will be removed in 3.0. Use IPBlock::getSuperBlock() instead.
*
* @param mixed $prefix
*
* @return IPBlock
*/
public function getSuper($prefix): IPBlock
{
@trigger_error('IPBlock::getSuper() is deprecated since version 2.0 and will be removed in 3.0. Use IPBlock::getSuperBlock() instead.', E_USER_DEPRECATED);

return $this->getSuperBlock($prefix);
}

/**
* Return the super block containing the current block.
*
* @param mixed $prefix
*
* @return IPBlock
*/
public function getSuperBlock($prefix): IPBlock
{
$prefix = ltrim($prefix, '/');
$this->checkPrefix($prefix);
Expand Down
14 changes: 7 additions & 7 deletions tests/IPBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ public function testArrayAccess()
}
}

public function testGetSubblocks()
public function testGetSubBlocks()
{
$block = IPBlock::create('192.168.8.0/24');
$subnets = $block->getSubblocks('/28');
$subnets = $block->getSubBlocks('/28');

$this->assertCount(16, $subnets);
$this->assertEquals('192.168.8.0', $subnets->current()->getFirstIp()->humanReadable());
Expand All @@ -255,22 +255,22 @@ public function testGetSubblocks()
$subnets->next();
$subnets->next();

$this->assertEquals('192.168.8.32/28', $subnets->current()->getGivenIpWithPrefixlen());
$this->assertEquals('192.168.8.32/28', $subnets->current()->getGivenIpWithPrefixLen());
}

public function testGetSuper()
public function testGetSuperBlock()
{
$block = IPBlock::create('192.168.42.0/24');
$this->assertEquals('192.168.0.0/16', (string) $block->getSuper('/16'));
$this->assertEquals('192.168.0.0/16', (string) $block->getSuperBlock('/16'));

try {
$block->getSuper('');
$block->getSuperBlock('');
$this->fail('Expected InvalidArgumentException has not be thrown');
} catch (\InvalidArgumentException $e) {
}

try {
$block->getSuper('/32');
$block->getSuperBlock('/32');
$this->fail('Expected InvalidArgumentException has not be thrown');
} catch (\InvalidArgumentException $e) {
}
Expand Down

0 comments on commit cb9eee8

Please sign in to comment.