diff --git a/README.md b/README.md
index 1a3bed7..00dfe6e 100644
--- a/README.md
+++ b/README.md
@@ -45,7 +45,7 @@ documentation.
[endsWith](#endswithstring-substring--boolean-casesensitive--true-) |
- [endsWithAny](#endsWithAnystring-substrings--boolean-casesensitive--true-) |
+ [endsWithAny](#endswithanystring-substrings--boolean-casesensitive--true-) |
[ensureLeft](#ensureleftstring-substring) |
[ensureRight](#ensurerightstring-substring) |
@@ -77,7 +77,7 @@ documentation.
[isLowerCase](#islowercase) |
[isSerialized](#isserialized) |
[isUpperCase](#isuppercase) |
- [last](#last) |
+ [last](#lastint-n) |
[length](#length) |
@@ -100,7 +100,7 @@ documentation.
[removeLeft](#removeleftstring-substring) |
[removeRight](#removerightstring-substring) |
- [repeat](#repeatmultiplier) |
+ [repeat](#repeatint-multiplier) |
[replace](#replacestring-search-string-replacement) |
@@ -110,10 +110,10 @@ documentation.
[slugify](#slugify-string-replacement----) |
- [startsWith](#startswithstring-substring--boolean-casesensitive--true-) |
- [startsWithAny](#startswithanystring-substrings--boolean-casesensitive--true-) |
[slice](#sliceint-start--int-end-) |
[split](#splitstring-pattern--int-limit-) |
+ [startsWith](#startswithstring-substring--boolean-casesensitive--true-) |
+ [startsWithAny](#startswithanystring-substrings--boolean-casesensitive--true-) |
[stripWhitespace](#stripwhitespace) |
@@ -821,26 +821,6 @@ is also converted to lowercase.
s('Using strings like fòô bàř')->slugify(); // 'using-strings-like-foo-bar'
```
-##### startsWith(string $substring [, boolean $caseSensitive = true ])
-
-Returns true if the string begins with $substring, false otherwise.
-By default, the comparison is case-sensitive, but can be made insensitive
-by setting $caseSensitive to false.
-
-```php
-s('FÒÔbàřbaz')->startsWith('fòôbàř', false); // true
-```
-
-##### startsWithAny(string[] $substrings [, boolean $caseSensitive = true ])
-
-Returns true if the string begins with any of $substrings, false
-otherwise. By default the comparison is case-sensitive, but can be made
-insensitive by setting $caseSensitive to false.
-
-```php
-s('FÒÔbàřbaz')->startsWith(['fòô', 'bàř'], false); // true
-```
-
##### slice(int $start [, int $end ])
Returns the substring beginning at $start, and up to, but not including
@@ -862,6 +842,26 @@ results.
s('foo,bar,baz')->split(',', 2); // ['foo', 'bar']
```
+##### startsWith(string $substring [, boolean $caseSensitive = true ])
+
+Returns true if the string begins with $substring, false otherwise.
+By default, the comparison is case-sensitive, but can be made insensitive
+by setting $caseSensitive to false.
+
+```php
+s('FÒÔbàřbaz')->startsWith('fòôbàř', false); // true
+```
+
+##### startsWithAny(string[] $substrings [, boolean $caseSensitive = true ])
+
+Returns true if the string begins with any of $substrings, false
+otherwise. By default the comparison is case-sensitive, but can be made
+insensitive by setting $caseSensitive to false.
+
+```php
+s('FÒÔbàřbaz')->startsWith(['fòô', 'bàř'], false); // true
+```
+
##### stripWhitespace()
Strip all whitespace characters. This includes tabs and newline
diff --git a/src/StaticStringy.php b/src/StaticStringy.php
index 66f75aa..648546b 100644
--- a/src/StaticStringy.php
+++ b/src/StaticStringy.php
@@ -16,13 +16,14 @@ use ReflectionMethod;
* @method static string chars(string $str, string $encoding = null)
* @method static string collapseWhitespace(string $str, string $encoding = null)
* @method static bool contains(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
- * @method static bool containsAll(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
- * @method static bool containsAny(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
+ * @method static bool containsAll(string $str, string[] $needle, bool $caseSensitive = true, string $encoding = null)
+ * @method static bool containsAny(string $str, string[] $needle, bool $caseSensitive = true, string $encoding = null)
* @method static int count(string $str, string $encoding = null)
* @method static int countSubstr(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
* @method static string dasherize(string $str, string $encoding = null)
* @method static string delimit(string $str, string $delimiter, string $encoding = null)
* @method static bool endsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
+ * @method static bool endsWithAny(string $str, string[] $substrings, bool $caseSensitive = true, string $encoding = null)
* @method static string ensureLeft(string $str, string $substring, string $encoding = null)
* @method static string ensureRight(string $str, string $substring, string $encoding = null)
* @method static string first(string $str, int $n, string $encoding = null)
@@ -45,7 +46,7 @@ use ReflectionMethod;
* @method static bool isUpperCase(string $str, string $encoding = null)
* @method static string last(string $str, string $encoding = null)
* @method static int length(string $str, string $encoding = null)
- * @method static Stringy[] lines(string $str, string $encoding = null)
+ * @method static string[] lines(string $str, string $encoding = null)
* @method static string longestCommonPrefix(string $str, string $otherStr, string $encoding = null)
* @method static string longestCommonSuffix(string $str, string $otherStr, string $encoding = null)
* @method static string longestCommonSubstring(string $str, string $otherStr, string $encoding = null)
@@ -64,9 +65,11 @@ use ReflectionMethod;
* @method static string safeTruncate(string $str, int $length, string $substring = '', string $encoding = null)
* @method static string shuffle(string $str, string $encoding = null)
* @method static string slugify(string $str, string $replacement = '-', string $encoding = null)
- * @method static bool startsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
* @method static string slice(string $str, int $start, int $end = null, string $encoding = null)
* @method static string split(string $str, string $pattern, int $limit = null, string $encoding = null)
+ * @method static bool startsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
+ * @method static bool startsWithAny(string $str, string[] $substrings, bool $caseSensitive = true, string $encoding = null)
+ * @method static string stripWhitespace(string $str, string $encoding = null)
* @method static string substr(string $str, int $start, int $length = null, string $encoding = null)
* @method static string surround(string $str, string $substring, string $encoding = null)
* @method static string swapCase(string $str, string $encoding = null)
@@ -145,10 +148,14 @@ class StaticStringy
$result = call_user_func_array([$stringy, $name], $args);
- if (is_object($result) && $result instanceof Stringy) {
- return (string) $result;
- }
+ $cast = function($val) {
+ if (is_object($val) && $val instanceof Stringy) {
+ return (string) $val;
+ } else {
+ return $val;
+ }
+ };
- return $result;
+ return is_array($result) ? array_map($cast, $result) : $cast($result);
}
}
diff --git a/src/Stringy.php b/src/Stringy.php
index db34756..7a303cd 100644
--- a/src/Stringy.php
+++ b/src/Stringy.php
@@ -219,9 +219,9 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* default the comparison is case-sensitive, but can be made insensitive by
* setting $caseSensitive to false.
*
- * @param array $needles Substrings to look for
- * @param bool $caseSensitive Whether or not to enforce case-sensitivity
- * @return bool Whether or not $str contains $needle
+ * @param string[] $needles Substrings to look for
+ * @param bool $caseSensitive Whether or not to enforce case-sensitivity
+ * @return bool Whether or not $str contains $needle
*/
public function containsAll($needles, $caseSensitive = true)
{
@@ -243,9 +243,9 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* default the comparison is case-sensitive, but can be made insensitive by
* setting $caseSensitive to false.
*
- * @param array $needles Substrings to look for
- * @param bool $caseSensitive Whether or not to enforce case-sensitivity
- * @return bool Whether or not $str contains $needle
+ * @param string[] $needles Substrings to look for
+ * @param bool $caseSensitive Whether or not to enforce case-sensitivity
+ * @return bool Whether or not $str contains $needle
*/
public function containsAny($needles, $caseSensitive = true)
{
@@ -1180,7 +1180,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* by setting $caseSensitive to false.
*
* @param string $substring The substring to look for
- * @param bool $caseSensitive Whether or not to enforce case-sensitivity
+ * @param bool $caseSensitive Whether or not to enforce
+ * case-sensitivity
* @return bool Whether or not $str starts with $substring
*/
public function startsWith($substring, $caseSensitive = true)
diff --git a/tests/StaticStringyTest.php b/tests/StaticStringyTest.php
index 653708b..67c3946 100644
--- a/tests/StaticStringyTest.php
+++ b/tests/StaticStringyTest.php
@@ -15,25 +15,38 @@ class StaticStringyTestCase extends PHPUnit_Framework_TestCase
public function testEmptyArgsInvocation()
{
$result = S::toLowerCase();
- $this->assertEquals('', (string) $result);
+ $this->assertEquals('', $result);
}
public function testInvocation()
{
$result = S::toLowerCase('FOOBAR');
- $this->assertEquals('foobar', (string) $result);
+ $this->assertEquals('foobar', $result);
+ $this->assertInternalType('string', $result);
}
public function testPartialArgsInvocation()
{
$result = S::slice('foobar', 0, 3);
- $this->assertEquals('foo', (string) $result);
+ $this->assertEquals('foo', $result);
+ $this->assertInternalType('string', $result);
}
public function testFullArgsInvocation()
{
$result = S::slice('fòôbàř', 0, 3, 'UTF-8');
- $this->assertEquals('fòô', (string) $result);
+ $this->assertEquals('fòô', $result);
+ $this->assertInternalType('string', $result);
+ }
+
+ public function testArrayReturnValue()
+ {
+ $result = S::lines("a\nb");
+ $this->assertEquals(['a', 'b'], $result);
+ $this->assertInternalType('array', $result);
+ foreach ($result as $val) {
+ $this->assertInternalType('string', $val);
+ }
}
/**