Skip to content

Commit

Permalink
Strings::contains null support
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Atroshchenko committed Feb 28, 2020
1 parent 60231b4 commit f779603
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Util/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,16 @@ public static function trimEnd(string $str, string $end) : string
/**
* Checks if the string contains the mask.
*
* @param string $str
* @param string|null $str
* @param string $mask
* @return boolean
*/
public static function contains(string $str, string $mask) : bool
public static function contains(?string $str, string $mask) : bool
{
if (is_null($str)) {
return false;
}

return strpos($str, $mask) !== false;
}
}
9 changes: 7 additions & 2 deletions tests/Util/StringsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ public function trimEndProvider() : array
/**
* @dataProvider containsProvider
*
* @param string $original
* @param string|null $original
* @param string $mask
* @param boolean $expected
* @return void
*/
public function testContains(string $original, string $mask, bool $expected) : void
public function testContains(?string $original, string $mask, bool $expected) : void
{
$this->assertEquals(
$expected,
Expand All @@ -243,6 +243,11 @@ public function containsProvider() : array
'sux',
false
],
[
null,
'sux',
false
],
];
}
}

0 comments on commit f779603

Please sign in to comment.