Page MenuHomeDevCentral

No OneTemporary

diff --git a/src/Debug/_register_to_global_space.php b/src/Debug/_register_to_global_space.php
index a63ee58..e0ebd55 100644
--- a/src/Debug/_register_to_global_space.php
+++ b/src/Debug/_register_to_global_space.php
@@ -1,17 +1,17 @@
<?php
-/* This code is intentionnally left in the global namespace. */
+/* This code is intentionally left in the global namespace. */
use Keruald\OmniTools\Debug\Debugger;
if (!function_exists("dprint_r")) {
function dprint_r ($variable) {
Debugger::printVariable($variable);
}
}
if (!function_exists("dieprint_r")) {
function dieprint_r ($variable) {
Debugger::printVariableAndDie($variable);
}
}
diff --git a/src/Network/IPv6Range.php b/src/Network/IPv6Range.php
index 8979818..2838c09 100644
--- a/src/Network/IPv6Range.php
+++ b/src/Network/IPv6Range.php
@@ -1,118 +1,118 @@
<?php
namespace Keruald\OmniTools\Network;
use InvalidArgumentException;
class IPv6Range extends IPRange {
/**
* @var string
*/
private $base;
/**
* @var int
*/
private $networkBits;
///
/// Constructors
///
public function __construct (string $base, int $networkBits) {
$this->setBase($base);
$this->setNetworkBits($networkBits);
}
///
/// Getters and setters
///
/**
* @return string
*/
public function getBase () : string {
return $this->base;
}
/**
* @param string $base
*/
public function setBase (string $base) : void {
if (!IP::isIPv6($base)) {
throw new InvalidArgumentException;
}
$this->base = $base;
}
/**
* @return int
*/
public function getNetworkBits () : int {
return $this->networkBits;
}
/**
* @param int $networkBits
*/
public function setNetworkBits (int $networkBits) : void {
if ($networkBits < 0 || $networkBits > 128) {
throw new InvalidArgumentException;
}
$this->networkBits = $networkBits;
}
///
/// Helper methods
///
public function getFirst () : string {
return $this->base;
}
public function getLast () : string {
if ($this->count() === 0) {
return $this->base;
}
$base = inet_pton($this->getFirst());
- $mask = inet_pton($this->getInversedMask());
+ $mask = inet_pton($this->getInverseMask());
return inet_ntop($base | $mask);
}
- private function getInversedMask () : string {
+ private function getInverseMask () : string {
$bits = array_fill(0, $this->networkBits, 0) + array_fill(0, 128, 1);
return (string)IPv6::fromBinaryBits($bits);
}
public function contains (string $ip) : bool {
if (!IP::isIP($ip)) {
throw new InvalidArgumentException;
}
if (IP::isIPv4($ip)) {
$ip = "::ffff:" . $ip; // IPv4-mapped IPv6 address
}
$baseAsNumericBinary = inet_pton($this->getFirst());
$lastAsNumericBinary = inet_pton($this->getLast());
$ipAsNumericBinary = inet_pton($ip);
return strlen($ipAsNumericBinary) == strlen($baseAsNumericBinary)
&& $ipAsNumericBinary >= $baseAsNumericBinary
&& $ipAsNumericBinary <= $lastAsNumericBinary;
}
///
/// Countable interface
///
public function count () : int {
return 128 - $this->networkBits;
}
}
diff --git a/src/Registration/PSR4/Solver.php b/src/Registration/PSR4/Solver.php
index c3dc87b..a3d98fa 100644
--- a/src/Registration/PSR4/Solver.php
+++ b/src/Registration/PSR4/Solver.php
@@ -1,66 +1,66 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Registration\PSR4;
use Keruald\OmniTools\Strings\Multibyte\StringUtilities;
final class Solver {
/**
* @var string
*/
private $namespace;
/**
* @var string The base path for the namespace
*/
private $path;
/**
- * @var string The fully qualif class name
+ * @var string The fully qualified class name
*/
private $class;
///
/// Constructors
///
public function __construct (string $namespace, string $path, string $class) {
$this->namespace = $namespace;
$this->path = $path;
$this->class = $class;
}
///
/// Resolve methods
///
public function resolve () : string {
return $this->path
. '/'
. $this->getRelativePath();
}
public function canResolve () : bool {
return StringUtilities::startsWith($this->class, $this->namespace);
}
public static function getPathFor (string $name) : string {
return str_replace("\\", "/", $name) . '.php';
}
///
/// Helper methods
///
private function getRelativePath () : string {
return self::getPathFor($this->getLocalClassName());
}
private function getLocalClassName () : string {
$len = strlen($this->namespace);
return substr($this->class, $len);
}
}
diff --git a/tests/Collections/WeightedValueTest.php b/tests/Collections/WeightedValueTest.php
index e56747d..06daca2 100644
--- a/tests/Collections/WeightedValueTest.php
+++ b/tests/Collections/WeightedValueTest.php
@@ -1,101 +1,101 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\Collections;
use Keruald\OmniTools\Collections\WeightedValue;
use PHPUnit\Framework\TestCase;
class WeightedValueTest extends TestCase {
/**
* @var WeightedValue
*/
private $lowValue;
/**
* @var WeightedValue
*/
private $highValue;
///
/// Fixtures
///
protected function setUp () : void {
$this->lowValue = new WeightedValue("LOW", 0.1);
$this->highValue = new WeightedValue("HIGH");
}
///
/// Tests
///
public function testGetWeight () : void {
$this->assertSame(0.1, $this->lowValue->getWeight());
$this->assertSame(
WeightedValue::DEFAULT_WEIGHT,
$this->highValue->getWeight()
);
}
public function testSetWeight () : void {
$this->lowValue->setWeight(0.2);
$this->assertSame(0.2, $this->lowValue->getWeight());
}
public function testGetValue () : void {
$this->assertEquals("LOW", $this->lowValue->getValue());
$this->assertEquals("HIGH", $this->highValue->getValue());
}
public function testSetValue () : void {
$this->lowValue->setValue("FOO");
$this->assertEquals("FOO", $this->lowValue->getValue());
}
public function testCompareTo () : void {
$this->assertEquals(
0,
$this->lowValue->compareTo($this->lowValue)
);
$this->assertEquals(
-1,
$this->lowValue->compareTo($this->highValue)
);
$this->assertEquals(
1,
$this->highValue->compareTo($this->lowValue)
);
}
public function testCompareToWithApplesAndPears () : void {
$this->expectException("TypeError");
$this->highValue->compareTo(new \stdClass);
}
/**
- * @dataProvider provideExpressionstoParse
+ * @dataProvider provideExpressionsToParse
*/
public function testParse ($expression, $expectedValue, $expectedWeight) : void {
$value = WeightedValue::Parse($expression);
$this->assertEquals($expectedValue, $value->getValue());
$this->assertEquals($expectedWeight, $value->getWeight());
}
///
/// Data providers
///
- public function provideExpressionstoParse () : iterable {
+ public function provideExpressionsToParse () : iterable {
yield ["", "", 1.0];
yield ["de", "de", 1.0];
yield ["de;q=1.0", "de", 1.0];
yield ["de;q=0.7", "de", 0.7];
yield [";;q=0.7", ";", 0.7];
}
}
diff --git a/tests/Network/IPTest.php b/tests/Network/IPTest.php
index e169a29..bc88636 100644
--- a/tests/Network/IPTest.php
+++ b/tests/Network/IPTest.php
@@ -1,148 +1,148 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\Network;
use Keruald\OmniTools\Network\IP;
use PHPUnit\Framework\TestCase;
class IPTest extends TestCase {
///
/// Data providers for IP addresses
///
/// These data providers methods allow to provide IP addresses
/// to validate or invalidate.
///
/// The advanced IPv6 tests have been curated by Stephen Ryan
/// Source: https://web.archive.org/web/20110515134717/http://forums.dartware.com/viewtopic.php?t=452
///
public function provideValidIP () : iterable {
yield ["0.0.0.0"];
yield ["17.17.17.17"];
yield ["fe80:0000:0000:0000:0204:61ff:fe9d:f156"];
}
public function provideInvalidIP () : iterable {
yield [""];
yield ["1"];
yield ["17.17"];
yield ["17.17.17.256"];
}
public function provideValidIPv4 () : iterable {
return [["0.0.0.0"], ["17.17.17.17"]];
}
public function provideInvalidIPv4 () : iterable {
yield [""];
yield ["1"];
yield ["17.17"];
yield ["17.17.17.256"];
yield ["fe80:0000:0000:0000:0204:61ff:fe9d:f156"];
}
public function provideValidIPv6 () : iterable {
yield ["::1"];
yield ["::ffff:192.0.2.128"];
yield ["fe80:0000:0000:0000:0204:61ff:fe9d:f156"];
yield ["::ffff:192.0.2.128", "IPv4 represented as dotted-quads"];
}
public function provideInvalidIPv6 () : iterable {
yield ["0.0.0.0"];
yield [""];
yield ["1"];
yield ["17.17"];
yield ["17.17.17.17"];
yield ["::fg", "Valid IPv6 digits are 0-f, ie 0-9 and a-f"];
yield ["02001:0000:1234:0000:0000:C1C0:ABCD:0876", "Extra 0"];
yield ["2001:0000:1234:0000:00001:C1C0:ABCD:0876", "Extra 0"];
yield ["1.2.3.4:1111:2222:3333:4444::5555"];
}
- public function provideValidLoopblackIP () : iterable {
+ public function provideValidLoopbackIP () : iterable {
yield ["127.0.0.1"];
yield ["127.0.0.3"];
yield ["::1"];
}
- public function provideInvalidLoopblackIP () : iterable {
+ public function provideInvalidLoopbackIP () : iterable {
yield ["0.0.0.0"];
yield ["1.2.3.4"];
yield ["192.168.1.1"];
yield ["::2"];
}
///
/// Test cases
///
/**
* @covers \Keruald\OmniTools\Network\IP::isIP
* @dataProvider provideValidIP
*/
public function testIsIP ($ip) {
$this->assertTrue(IP::isIP($ip));
}
/**
* @covers \Keruald\OmniTools\Network\IP::isIP
* @dataProvider provideInvalidIP
*/
public function testIsIPWhenItIsNot ($ip) {
$this->assertFalse(IP::isIP($ip));
}
/**
* @covers \Keruald\OmniTools\Network\IP::isIPv4
* @dataProvider provideValidIPv4
*/
public function testIsIPv4 ($ip) {
$this->assertTrue(IP::isIPv4($ip));
}
/**
* @covers \Keruald\OmniTools\Network\IP::isIPv4
* @dataProvider provideInvalidIPv4
*/
public function testIsIPv4WhenItIsNot ($ip) {
$this->assertFalse(IP::isIPv4($ip));
}
/**
* @covers \Keruald\OmniTools\Network\IP::isIPv6
* @dataProvider provideValidIPv6
*/
public function testIsIPv6 (string $ip, string $message = "") {
$this->assertTrue(IP::isIPv6($ip), $message);
}
/**
* @covers \Keruald\OmniTools\Network\IP::isIPv6
* @dataProvider provideInvalidIPv6
*/
public function testIsIPv6WhenItIsNot (string $ip, string $message = "") : void {
$this->assertFalse(IP::isIPv6($ip), $message);
}
/**
* @covers \Keruald\OmniTools\Network\IP::isLoopback
- * @dataProvider provideValidLoopblackIP
+ * @dataProvider provideValidLoopbackIP
*/
public function testIsLoopback (string $ip) : void {
$this->assertTrue(IP::isLoopback($ip));
}
/**
* @covers \Keruald\OmniTools\Network\IP::isLoopback
- * @dataProvider provideInvalidLoopblackIP
+ * @dataProvider provideInvalidLoopbackIP
*/
public function testIsLoopbackWhenItIsNot (string $ip) : void {
$this->assertFalse(IP::isLoopback($ip));
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Sep 19, 00:34 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2990639
Default Alt Text
(12 KB)

Event Timeline