From 397d2ca2f86106fbf61467f3ff4e2ca1c63d5d1f Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Mon, 29 Jun 2015 15:33:00 -0700 Subject: [PATCH] Style fixes --- README.md | 24 +++++++++++---------- src/StaticStringy.php | 38 ++++++++++++++++++-------------- src/Stringy.php | 50 +++++++++++++++++++++---------------------- 3 files changed, 60 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 0258191..5f70261 100644 --- a/README.md +++ b/README.md @@ -479,30 +479,32 @@ S::humanize('author_id'); // 'Author' #### indexOf -$stringy->indexOf(string $substr [, $offset = 0 ]); +$stringy->indexOf(string $needle [, $offset = 0 ]); -S::indexOf(string $str , string $substr [, $offset = 0 [, $encoding = null ]]) +S::indexOf(string $haystack , string $needle [, $offset = 0 [, $encoding = null ]]) -Returns the offset/index of the first occurrence of $substr in the string. -In case $substr is not a substring of the string, returns false. +Returns the index of the first occurrence of $needle in the string, +and false if not found. Accepts an optional offset from which to begin +the search. ```php S::create('string', 'UTF-8')->indexOf('ing'); -S::indexOf('string', 'ing', 0, 'UTF-8'); // 3 +S::indexOf('string', 'ing'); // 3 ``` #### indexOfLast -$stringy->indexOfLast(string $substr [, $offset = 0 ]); +$stringy->indexOfLast(string $needle [, $offset = 0 ]); -S::indexOfLast(string $str , string $substr [, $offset = 0 [, $encoding = null ]]) +S::indexOfLast(string $haystack , string $needle [, $offset = 0 [, $encoding = null ]]) -Returns the offset/index of the last occurrence of $substr in the string. -In case $substr is not a substring of the string, returns false. +Returns the index of the last occurrence of $needle in the string, +and false if not found. Accepts an optional offset from which to begin +the search. ```php S::create('string', 'UTF-8')->indexOfLast('ing'); -S::indexOfLast('string string', 'ing', 0, 'UTF-8'); // 10 +S::indexOfLast('string string', 'ing'); // 10 ``` #### insert @@ -1054,7 +1056,7 @@ $stringy->trim() S::trim(string $str) -Returns the trimmed string. An alias for PHP's trim() function. +Returns the trimmed string. ```php S::create('fòô bàř', 'UTF-8')->trim(); diff --git a/src/StaticStringy.php b/src/StaticStringy.php index d9ac76a..79d31e7 100644 --- a/src/StaticStringy.php +++ b/src/StaticStringy.php @@ -422,31 +422,37 @@ class StaticStringy } /** - * Returns the offset/index of the first occurance of $substr in the string. - * In case $substr is not a substring of the string, returns false. + * Returns the index of the first occurrence of $needle in the string, + * and false if not found. Accepts an optional offset from which to begin + * the search. * - * @param string $str The haystack to search through - * @param string $substr substring - * @param int $offset - * @return int|bool + * @param string $haystack String to search + * @param string $needle Substring to look for + * @param int $offset Offset from which to search + * @return int|bool The occurrence's index if found, otherwise false */ - public static function indexOf($str, $substr, $offset = 0, $encoding = null) + public static function indexOf($haystack, $needle, $offset = 0, + $encoding = null) { - return Stringy::create($str, $encoding)->indexOf($substr, $offset); + return Stringy::create($haystack, $encoding) + ->indexOf($needle, $offset); } /** - * Returns the offset/index of the last occurance of $substr in the string. - * In case $substr is not a substring of the string, returns false. + * Returns the index of the last occurrence of $needle in the string, + * and false if not found. Accepts an optional offset from which to begin + * the search. * - * @param string $str The haystack to search through - * @param string $substr substring - * @param int $offset - * @return int|bool + * @param string $haystack String to search + * @param string $needle Substring to look for + * @param int $offset Offset from which to search + * @return int|bool The last occurrence's index if found, otherwise false */ - public static function indexOfLast($str, $substr, $offset = 0, $encoding = null) + public static function indexOfLast($haystack, $needle, $offset = 0, + $encoding = null) { - return Stringy::create($str, $encoding)->indexOfLast($substr, $offset); + return Stringy::create($haystack, $encoding) + ->indexOfLast($needle, $offset); } /** diff --git a/src/Stringy.php b/src/Stringy.php index 8a03bf4..2b0a0b0 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -895,29 +895,33 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess } /** - * Returns the offset/index of the first occurrence of $substr in the string. - * In case $substr is not a substring of the string, returns false. + * Returns the index of the first occurrence of $needle in the string, + * and false if not found. Accepts an optional offset from which to begin + * the search. * - * @param string $substr substring - * @param int $offset - * @return int|bool + * @param string $needle Substring to look for + * @param int $offset Offset from which to search + * @return int|bool The occurrence's index if found, otherwise false */ - public function indexOf($substr, $offset = 0) + public function indexOf($needle, $offset = 0) { - return mb_strpos($this->str, (string)$substr, (int)$offset, $this->encoding); + return mb_strpos($this->str, (string) $needle, + (int) $offset, $this->encoding); } /** - * Returns the offset/index of the last occurrence of $substr in the string. - * In case $substr is not a substring of the string, returns false. + * Returns the index of the last occurrence of $needle in the string, + * and false if not found. Accepts an optional offset from which to begin + * the search. * - * @param string $substr substring - * @param int $offset - * @return int|bool + * @param string $needle Substring to look for + * @param int $offset Offset from which to search + * @return int|bool The last occurrence's index if found, otherwise false */ - public function indexOfLast($substr, $offset = 0) + public function indexOfLast($needle, $offset = 0) { - return mb_strrpos($this->str, (string)$substr, (int)$offset, $this->encoding); + return mb_strrpos($this->str, (string) $needle, + (int) $offset, $this->encoding); } /** @@ -1057,10 +1061,10 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess } /** - * Returns the trimmed string. An alias for PHP's trim() function. + * Returns the trimmed string. * - * @param string $charList list with characters to be removed - * @param int $type which function will be used to trim the string, trim, ltrim or rtrim + * @param string $charList Characters to be removed + * @param int $type One of TRIM_BOTH, TRIM_LEFT or TRIM_RIGHT * @return Stringy Object with a trimmed $str * @throws \InvalidArgumentException */ @@ -1072,14 +1076,10 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess ); } - if (!in_array($type, array( - self::TRIM_BOTH, - self::TRIM_LEFT, - self::TRIM_RIGHT, - ))) { - throw new \InvalidArgumentException( - 'Type of trim function must be trim (default), rtrim or ltrim, just as native php.' - ); + $validTypes = array(self::TRIM_BOTH, self::TRIM_LEFT, self::TRIM_RIGHT); + if (!in_array($type, $validTypes)) { + throw new \InvalidArgumentException('Type of trim function must ' . + 'be trim (default), rtrim or ltrim, just as native php.'); } return static::create($type($this->str, $charList), $this->encoding);