Skip to content

Commit

Permalink
Strings 4.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed May 8, 2022
1 parent d250a7d commit 7299b51
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<a name="4.3.0"></a>
# [4.3.0](https://github.com/glowyphp/strings) (2022-05-08)
* Added isNull() method.
* Added isInteger() method.
* Added isFloat() method.
* Added isUuid() method.
* Added toNull() method.
* Method pipe() returns a new instance of the class.

<a name="4.2.0"></a>
# [4.2.0](https://github.com/glowyphp/strings) (2022-01-01)
* Added isHexColor() method.
Expand Down
40 changes: 40 additions & 0 deletions src/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,36 @@ public function isHTML(): bool
return $this->toString() !== strip_tags($this->toString());
}

/**
* Determine whether the string is integer.
*
* @return bool Returns TRUE on success or FALSE otherwise.
*/
public function isInteger(): bool
{
return (bool) filter_var($this->toString(), FILTER_VALIDATE_INT);
}

/**
* Determine whether the string is float.
*
* @return bool Returns TRUE on success or FALSE otherwise.
*/
public function isFloat(): bool
{
return ((bool) filter_var($this->toString(), FILTER_VALIDATE_FLOAT) !== $this->isInteger());
}

/**
* Determine whether the string is null.
*
* @return bool Returns TRUE on success or FALSE otherwise.
*/
public function isNull(): bool
{
return $this->toString() === null || $this->toString() === 'null';
}

/**
* Determine whether the string is Boolean.
*
Expand Down Expand Up @@ -2105,6 +2135,16 @@ public function toFloat(): float
return floatval($this->string);
}

/**
* Return Strings object as null.
*
* @return float Return Strings object as null.
*/
public function toNull(): float
{
return null;
}

/**
* Returns a boolean representation of the given logical string value.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/StringsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,24 @@
$this->assertFalse(Strings::create('fòôbàřs')->isIP());
});

test('test isInteger() method', function (): void {
$this->assertTrue(Strings::create('1')->isInteger());
$this->assertFalse(Strings::create('1.0')->isInteger());
$this->assertFalse(Strings::create('Foo')->isInteger());
});

test('test isFloat() method', function (): void {
$this->assertFalse(Strings::create('1')->isFloat());
$this->assertTrue(Strings::create('0.1')->isFloat());
$this->assertTrue(Strings::create('1.0')->isFloat());
$this->assertTrue(Strings::create('0.1')->isFloat());
$this->assertFalse(Strings::create('Foo')->isFloat());
});

test('test isNull() method', function (): void {
$this->assertTrue(Strings::create('null')->isNull());
});

test('test isMAC() method', function (): void {
$this->assertTrue(Strings::create('00:11:22:33:44:55')->isMAC());
$this->assertFalse(Strings::create('127.0.0.1')->isMAC());
Expand Down

0 comments on commit 7299b51

Please sign in to comment.