Skip to content

Commit 84dfdfb

Browse files
committed
implement hasSpace() method
1 parent 5c7dab6 commit 84dfdfb

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ StrUtility::after(string $string, string $search): string
375375
StrUtility::before(string $string, string $search): string
376376
```
377377

378+
```php
379+
StrUtility::hasSpace(string $string): bool
380+
```
381+
378382
## StrUtility usage as helper functions
379383

380384
String helper functions are global so usage like the following:

src/PhpStringHelpers.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,10 @@ function before(string $string, string $search): string
412412
return strHelpers::before($string, $search);
413413
}
414414
}
415+
416+
if (!function_exists('hasSpace')) {
417+
function hasSpace(string $string): string
418+
{
419+
return strHelpers::hasSpace($string);
420+
}
421+
}

src/utility/StrUtility.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,17 @@ public function before(string $string, string $search): string
871871
return $this->rmExtraBlank(strstr($string, $search, true));
872872
}
873873

874+
/**
875+
* Check String For Any Spaces
876+
*
877+
* @param string $string
878+
* @return bool
879+
*/
880+
public function hasSpace(string $string)
881+
{
882+
return preg_match_all('/\s/', $string) ? true : false;
883+
}
884+
874885
private function checkStringForRemoveOperation(string $string, string $word): bool
875886
{
876887
$string = strtolower(trim($string));

tests/StrUtilityTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,4 +947,16 @@ public function testBeforeCanRemoveTheWordsAfterTheSearchParam()
947947
$string = strHelpersTest::before('foo bar baz', 'foo');
948948
$this->assertEquals('', $string);
949949
}
950+
951+
public function testHasSpaceCanReturnTrueValue()
952+
{
953+
$string = strHelpersTest::hasSpace('foo bar baz');
954+
$this->assertTrue($string);
955+
}
956+
957+
public function testHasSpaceCanReturnFalseValue()
958+
{
959+
$string = strHelpersTest::hasSpace('foo');
960+
$this->assertFalse($string);
961+
}
950962
}

0 commit comments

Comments
 (0)