From f0063f8bac788ae8cf1fab240b402046d78c8c42 Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Thu, 1 Aug 2013 00:53:54 -0400 Subject: [PATCH] Cleanup and fixes for 1.0.0 Release --- CHANGELOG.md | 9 ++ README.md | 173 ++++++++++++++-------------- src/Stringy/StaticStringy.php | 168 ++++++++++++++------------- src/Stringy/Stringy.php | 166 +++++++++++++------------- tests/Stringy/CommonTest.php | 2 +- tests/Stringy/StaticStringyTest.php | 54 ++++++++- tests/Stringy/StringyTest.php | 68 ++++++++++- 7 files changed, 381 insertions(+), 259 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d5836b..0de0a63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +### 1.0.0 (2013-08-1) + + * 1.0.0 release + * Added test coverage for Stringy::create and method chaining + * Added tests for returned type + * Fixed StaticStringy::replace(). It was returning a Stringy object instead of string + * Renamed standardize() to the more appropriate toAscii() + * Cleaned up comments and README + ### 1.0.0-rc.1 (2013-07-28) * Release candidate diff --git a/README.md b/README.md index cc78d9d..fd8d65e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ A PHP library with a variety of string manipulation functions with multibyte support. Offers both OO method chaining and a procedural-style static wrapper. Compatible with PHP 5.3+. Inspired by underscore.string.js. [![Build Status](https://travis-ci.org/danielstjules/Stringy.png)](https://travis-ci.org/danielstjules/Stringy) -[![Total Downloads](https://poser.pugx.org/danielstjules/Stringy/downloads.png)](https://packagist.org/packages/danielstjules/stringy) [![Latest Stable Version](https://poser.pugx.org/danielstjules/Stringy/v/stable.png)](https://packagist.org/packages/danielstjules/stringy) * [Requiring/Loading](#requiringloading) @@ -44,13 +43,13 @@ A PHP library with a variety of string manipulation functions with multibyte sup * [safeTruncate](#safetruncate) * [shuffle](#shuffle) * [slugify](#slugify) - * [standardize](#standardize) * [startsWith](#startswith) * [substr](#substr) * [surround](#surround) * [swapCase](#swapcase) * [tidy](#tidy) * [titleize](#titleize) + * [toAscii](#toascii) * [toSpaces](#tospaces) * [toTabs](#totabs) * [trim](#trim) @@ -117,7 +116,7 @@ echo S::swapCase($string, 'UTF-8'); // 'fÒÔ bÀŘ'' ## Methods In the list below, any static method other than S::create refers to a -method in Stringy\StaticStringy. For all others, they're found in Stringy\Stringy. Furthermore, all methods that return an object of type Stringy return a new object, and do not modify the original. +method in Stringy\StaticStringy. For all others, they're found in Stringy\Stringy. Furthermore, all methods that return a Stringy object or string do not modify the original. *Note: If $encoding is not given, it defaults to mb_internal_encoding().* @@ -127,7 +126,7 @@ $stringy->at(int $index) S::substr(int $index [, string $encoding ]) -Gets the character of $str at $index, with indexes starting at 0. +Returns the character of the string at $index, with indexes starting at 0. ```php S::create('fòô bàř', 'UTF-8')->at(6); @@ -140,9 +139,9 @@ $stringy->camelize(); S::camelize(string $str [, string $encoding ]) -Returns a camelCase version of a supplied string, with multibyte support. -Trims surrounding spaces, capitalizes letters following digits, spaces, -dashes and underscores, and removes spaces, dashes, underscores. +Returns a camelCase version of the supplied string. Trims surrounding +spaces, capitalizes letters following digits, spaces, dashes and +underscores, and removes spaces, dashes, underscores. ```php S::create('Camel-Case')->camelize(); @@ -156,7 +155,7 @@ $stringy->collapseWhitespace() S::collapseWhitespace(string $str) Trims the string and replaces consecutive whitespace characters with a -single space. This inclues tabs and newline characters. +single space. This includes tabs and newline characters. ```php S::create(' Ο συγγραφέας ')->collapseWhitespace(); @@ -169,7 +168,7 @@ $stringy->contains(string $needle) S::contains(string $haystack, string $needle [, string $encoding ]) -Returns true if $haystack contains $needle, false otherwise. +Returns true if the string contains $needle, false otherwise. ```php S::create('Ο συγγραφέας είπε', 'UTF-8')->contains('συγγραφέας'); @@ -182,7 +181,7 @@ $stringy->count(string $substring) S::count(string $str, string $substring [, string $encoding ]) -Returns the number of occurences of $substring in $str. An alias for +Returns the number of occurrences of $substring in the given string. An alias for mb_substr_count() ```php @@ -192,14 +191,14 @@ S::count('Ο συγγραφέας είπε', 'α', 'UTF-8'); // 2 #### create -$stringy = S::create(string $str, [, $encoding ]) +S::create(string $str, [, $encoding ]) Creates a Stringy object and assigns both str and encoding properties the supplied values. If $encoding is not specified, it defaults to -mb_internal_encoding(). It then returns the instantiated object. +mb_internal_encoding(). It then returns the initialized object. ```php -S::create('fòô bàř', 'UTF-8'); // 'fòô bàř' +$stringy = S::create('fòô bàř', 'UTF-8'); // 'fòô bàř' ``` #### dasherize @@ -208,10 +207,9 @@ $stringy->dasherize(); S::dasherize(string $str [, string $encoding ]) -Returns a lowercase and trimmed string seperated by dashes, with -multibyte support. Dashes are inserted before uppercase characters -(with the exception of the first character of the string), and in place -of spaces as well as underscores. +Returns a lowercase and trimmed string separated by dashes. Dashes are +inserted before uppercase characters (with the exception of the first +character of the string), and in place of spaces as well as underscores. ```php S::create('TestDCase')->dasherize(); @@ -224,9 +222,9 @@ $stringy->endsWith(string $substring [, boolean $caseSensitive = true ]) S::endsWith(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]]) -Returns true if the string $str ends with $substring, false otherwise. -By default, the comparison is case-sensitive, but can be made insensitive -by setting $caseSensitive to false. +Returns true if the string ends with $substring, false otherwise. By +default, the comparison is case-sensitive, but can be made insensitive by +setting $caseSensitive to false. ```php S::create('FÒÔ bàřs', 'UTF-8')->endsWith('àřs', true); @@ -239,7 +237,7 @@ $stringy->ensureLeft(string $substring) S::ensureLeft(string $substring [, string $encoding ]) -Ensures that $str begins with $substring. +Ensures that the string begins with $substring. If it doesn't, it's prepended. ```php S::create('foobar')->ensureLeft('http://'); @@ -252,7 +250,7 @@ $stringy->ensureRight(string $substring) S::ensureRight(string $substring [, string $encoding ]) -Ensures that $str ends with $substring. +Ensures that the string begins with $substring. If it doesn't, it's appended. ```php S::create('foobar')->ensureRight('.com'); @@ -265,7 +263,7 @@ $stringy->first(int $n) S::first(int $n [, string $encoding ]) -Gets the first $n characters of $str. +Returns the first $n characters of the string. ```php S::create('fòô bàř', 'UTF-8')->first(3); @@ -278,8 +276,8 @@ $stringy->humanize() S::humanize(string $str [, string $encoding ]) -Capitalizes the first word of a string, replaces underscores with spaces, -and strips '_id'. +Capitalizes the first word of the string, replaces underscores with +spaces, and strips '_id'. ```php S::create('author_id')->humanize(); @@ -292,7 +290,7 @@ $stringy->insert(int $index, string $substring) S::insert(string $str, int $index, string $substring [, string $encoding ]) -Inserts $substring into $str at the $index provided. +Inserts $substring into the string at the $index provided. ```php S::create('fòô bà', 'UTF-8')->insert('ř', 6); @@ -305,7 +303,7 @@ $stringy->isAlpha() S::isAlpha(string $str [, string $encoding ]) -Returns true if $str contains only alphabetic chars, false otherwise. +Returns true if the string contains only alphabetic chars, false otherwise. ```php S::create('丹尼爾', 'UTF-8')->isAlpha(); @@ -318,7 +316,7 @@ $stringy->isAlphanumeric() S::isAlphanumeric(string $str [, string $encoding ]) -Returns true if $str contains only alphabetic and numeric chars, false +Returns true if the string contains only alphabetic and numeric chars, false otherwise. ```php @@ -332,7 +330,7 @@ $stringy->isBlank() S::isBlank(string $str [, string $encoding ]) -Returns true if $str contains only whitespace chars, false otherwise. +Returns true if the string contains only whitespace chars, false otherwise. ```php S::create("\n\t \v\f")->isBlank(); @@ -345,7 +343,7 @@ $stringy->isLowerCase() S::isLowerCase(string $str [, string $encoding ]) -Returns true if $str contains only lower case chars, false otherwise. +Returns true if the string contains only lower case chars, false otherwise. ```php S::create('fòô bàř', 'UTF-8')->isLowerCase(); @@ -358,7 +356,7 @@ $stringy->isUpperCase() S::isUpperCase(string $str [, string $encoding ]) -Returns true if $str contains only upper case chars, false otherwise. +Returns true if the string contains only upper case chars, false otherwise. ```php S::create('FÒÔBÀŘ',, 'UTF-8')->isUpperCase(); @@ -371,7 +369,7 @@ $stringy->last(int $n) S::last(int $n [, string $encoding ]) -Gets the last $n characters of $str. +Returns the last $n characters of the string. ```php S::create('fòô bàř', 'UTF-8')->last(3); @@ -384,7 +382,7 @@ $stringy->length() S::length(string $str [, string $encoding ]) -Returns the length of $str. An alias for PHP's mb_strlen() function. +Returns the length of the string. An alias for PHP's mb_strlen() function. ```php S::create('fòô bàř', 'UTF-8')->length(); @@ -397,7 +395,7 @@ $stringy->longestCommonPrefix(string $otherStr) S::longestCommonPrefix(string $str, string $otherStr [, $encoding ]) -Finds the longest common prefix between $str and $otherStr. +Returns the longest common prefix between the string and $otherStr. ```php S::create('fòô bar', 'UTF-8')->longestCommonPrefix('fòr bar'); @@ -410,7 +408,7 @@ $stringy->longestCommonSuffix(string $otherStr) S::longestCommonSuffix(string $str, string $otherStr [, $encoding ]) -Finds the longest common suffix between $str and $otherStr. +Returns the longest common suffix between the string and $otherStr. ```php S::create('fòô bàř', 'UTF-8')->longestCommonSuffix('fòr bàř'); @@ -423,8 +421,8 @@ $stringy->longestCommonSubstring(string $otherStr) S::longestCommonSubstring(string $str, string $otherStr [, $encoding ]) -Finds the longest common substring between $str and $otherStr. In the -case of ties, returns that which occurs first. +Returns the longest common substring between the string and $otherStr. In the +case of ties, it returns that which occurs first. ```php S::create('foo bar')->longestCommonSubstring('boo far'); @@ -437,8 +435,7 @@ $stringy->lowerCaseFirst(); S::lowerCaseFirst(string $str [, string $encoding ]) -Converts the first character of the supplied string to lower case, with -support for multibyte strings. +Converts the first character of the supplied string to lower case. ```php S::create('Σ test', 'UTF-8')->lowerCaseFirst(); @@ -451,11 +448,11 @@ $stringy->pad(int $length [, string $padStr = ' ' [, string $padType = 'right' ] S::pad(string $str , int $length [, string $padStr = ' ' [, string $padType = 'right' [, string $encoding ]]]) -Pads a string to a given length with another string. If length is less -than or equal to the length of $str, then no padding takes places. The -default string used for padding is a space, and the default type (one of -'left', 'right', 'both') is 'right'. Throws an exception if $padType -isn't one of those 3 values. +Pads the string to a given length with $padStr. If length is less than +or equal to the length of the string, no padding takes places. The default +string used for padding is a space, and the default type (one of 'left', +'right', 'both') is 'right'. Throws an InvalidArgumentException if +$padType isn't one of those 3 values. ```php S::create('fòô bàř', 'UTF-8')->pad( 10, '¬ø', 'left',); @@ -469,7 +466,7 @@ $stringy->padBoth(int $length [, string $padStr = ' ' ]) S::padBoth(string $str , int $length [, string $padStr = ' ' [, string $encoding ]]) Returns a new string of a given length such that both sides of the string -string are padded. Alias for pad($str, $length, $padStr, 'both', $encoding) +string are padded. Alias for pad() with a $padType of 'both'. ```php S::create('foo bar')->padBoth(9, ' '); @@ -483,7 +480,7 @@ $stringy->padLeft(int $length [, string $padStr = ' ' ]) S::padLeft(string $str , int $length [, string $padStr = ' ' [, string $encoding ]]) Returns a new string of a given length such that the beginning of the -string is padded. Alias for pad($str, $length, $padStr, 'left', $encoding) +string is padded. Alias for pad() with a $padType of 'left'. ```php S::create($str, $encoding)->padLeft($length, $padStr); @@ -497,7 +494,7 @@ $stringy->padRight(int $length [, string $padStr = ' ' ]) S::padRight(string $str , int $length [, string $padStr = ' ' [, string $encoding ]]) Returns a new string of a given length such that the end of the string is -padded. Alias for pad($str, $length, $padStr, 'right', $encoding) +padded. Alias for pad() with a $padType of 'right'. ```php S::create('foo bar')->padRight(10, '_*'); @@ -510,7 +507,7 @@ $stringy->removeLeft(string $substring) S::removeLeft(string $str, string $substring [, string $encoding ]) -Removes the prefix $substring if present. +Returns a new string with the prefix $substring removed, if it was present. ```php S::create('fòô bàř', 'UTF-8')->removeLeft('fòô '); @@ -523,7 +520,7 @@ $stringy->removeRight(string $substring) S::removeRight(string $str, string $substring [, string $encoding ]) -Removes the suffix $substring if present. +Returns a new string with the suffix $substring removed, if it was present. ```php S::create('fòô bàř', 'UTF-8')->removeRight(' bàř'); @@ -536,7 +533,7 @@ $stringy->replace(string $search, string $replace) S::replace(string $str, string $search, string $replace [, string $encoding ]) -Replaces all occurrences of $search with $replace in $str. +Returns a string with all occurrences of $search replaced with $replace. ```php S::create('fòô bàř fòô bàř', 'UTF-8')->replace('fòô ', ''); @@ -549,7 +546,7 @@ $stringy->reverse() S::reverse(string $str, [, string $encoding ]) -Reverses a string. A multibyte version of strrev. +Returns a reversed string. A multibyte version of strrev(). ```php S::create('fòô bàř', 'UTF-8')->reverse(); @@ -578,8 +575,7 @@ $stringy->shuffle() S::shuffle(string $str [, string $encoding ]) -A multibyte str_shuffle function. It randomizes the order of characters -in a string. +A multibyte str_shuffle() function. It returns a string with its characters in random order. ```php S::create('fòô bàř', 'UTF-8')->shuffle(); @@ -592,36 +588,23 @@ $stringy->slugify() S::slugify(string $str) -Converts the supplied text into an URL slug. This includes replacing -non-ASCII characters with their closest ASCII equivalents, removing -non-alphanumeric and non-ASCII characters, and replacing whitespace with -dashes. The string is also converted to lowercase. +Converts the string into an URL slug. This includes replacing non-ASCII +characters with their closest ASCII equivalents, removing non-alphanumeric +and non-ASCII characters, and replacing whitespace with dashes. The string +is also converted to lowercase. ```php S::create('Using strings like fòô bàř')->slugify(); S::slugify('Using strings like fòô bàř'); // 'using-strings-like-foo-bar' ``` -#### standardize - -$stringy->standardize() - -S::standardize(string $str) - -Converts some non-ASCII characters to their closest ASCII counterparts. - -```php -S::create('fòô bàř')->standardize(); -S::standardize('fòô bàř'); // 'foo bar' -``` - #### startsWith $stringy->startsWith(string $substring [, boolean $caseSensitive = true ]) S::startsWith(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]]) -Returns true if the string $str begins with $substring, false otherwise. +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. @@ -636,7 +619,7 @@ $stringy->substr(int $start [, int $length ]) S::substr(string $str, int $start [, int $length [, string $encoding ]]) -Gets the substring of $str beginning at $start with the specified $length. +Returns the substring beginning at $start with the specified $length. It differs from the mb_substr() function in that providing a $length of null will return the rest of the string, rather than an empty string. @@ -664,7 +647,7 @@ $stringy->swapCase(); S::swapCase(string $str [, string $encoding ]) -Returns a case swapped version of a string. +Returns a case swapped version of the string. ```php S::create('Ντανιλ', 'UTF-8')->swapCase(); @@ -677,8 +660,8 @@ $stringy->tidy() S::tidy(string $str) -Replaces smart quotes, ellipsis characters, and dashes from Windows-1252 -(and commonly used in Word documents) with their ASCII equivalents. +Returns a string with smart quotes, ellipsis characters, and dashes from +Windows-1252 (commonly used in Word documents) replaced by their ASCII equivalents. ```php S::create('“I see…”')->tidy(); @@ -691,7 +674,7 @@ $stringy->titleize([ string $encoding ]) S::titleize(string $str [, array $ignore [, string $encoding ]]) -Capitalizes the first letter of each word in a string, after trimming. +Returns a trimmed string with the first letter of each word capitalized. Ignores the case of other letters, allowing for the use of acronyms. Also accepts an array, $ignore, allowing you to list words not to be capitalized. @@ -703,13 +686,27 @@ S::titleize('i like to watch DVDs at home', $ignore, 'UTF-8'); // 'I Like to Watch DVDs at Home' ``` +#### toAscii + +$stringy->toAscii() + +S::toAscii(string $str) + +Returns an ASCII version of the string. A set of non-ASCII characters are +replaced with their closest ASCII counterparts, and the rest are removed. + +```php +S::create('fòô bàř')->toAscii(); +S::toAscii('fòô bàř'); // 'foo bar' +``` + #### toSpaces $stringy->toSpaces([ tabLength = 4 ]) S::toSpaces(string $str, [, int $tabLength = 4 ]) -Converts each tab in a string to some number of spaces, as defined by +Converts each tab in the string to some number of spaces, as defined by $tabLength. By default, each tab is converted to 4 consecutive spaces. ```php @@ -723,7 +720,7 @@ $stringy->toTabs([ tabLength = 4 ]) S::toTabs(string $str, [, int $tabLength = 4 ]) -Converts each occurence of some consecutive number of spaces, as defined +Converts each occurrence of some consecutive number of spaces, as defined by $tabLength, to a tab. By default, each 4 consecutive spaces are converted to a tab. @@ -738,7 +735,7 @@ $stringy->trim() S::trim(string $str) -Trims $str. An alias for PHP's trim() function. +Returns the trimmed string. An alias for PHP's trim() function. ```php S::create('fòô bàř', 'UTF-8')->trim(); @@ -751,7 +748,7 @@ $stringy->truncate(int $length, [, string $substring = '' ]) S::truncate(string $str, int $length, [, string $substring = '' [, string $encoding ]]) -Truncates $str to a given length. If $substring is provided, and +Truncates the string to a given length. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length. @@ -766,10 +763,9 @@ $stringy->underscored(); S::underscored(string $str [, string $encoding ]) -Returns a lowercase and trimmed string seperated by underscores, with -multibyte support. Underscores are inserted before uppercase characters -(with the exception of the first character of the string), and in place -of spaces as well as dashes. +Returns a lowercase and trimmed string separated by underscores. +Underscores are inserted before uppercase characters (with the exception +of the first character of the string), and in place of spaces as well as dashes. ```php S::create('TestUCase')->underscored(); @@ -782,9 +778,9 @@ $stringy->upperCamelize(); S::upperCamelize(string $str [, string $encoding ]) -Returns an UpperCamelCase version of a supplied string, with multibyte -support. Trims surrounding spaces, capitalizes letters following digits, -spaces, dashes and underscores, and removes spaces, dashes, underscores. +Returns an UpperCamelCase version of the supplied string. It trims +surrounding spaces, capitalizes letters following digits, spaces, dashes +and underscores, and removes spaces, dashes, underscores. ```php S::create('Upper Camel-Case')->upperCamelize(); @@ -797,8 +793,7 @@ $stringy->upperCaseFirst(); S::upperCaseFirst(string $str [, string $encoding ]) -Converts the first character of the supplied string to upper case, with -support for multibyte strings. +Converts the first character of the supplied string to upper case. ```php S::create('σ test', 'UTF-8')->upperCaseFirst(); diff --git a/src/Stringy/StaticStringy.php b/src/Stringy/StaticStringy.php index afff10a..f116a21 100644 --- a/src/Stringy/StaticStringy.php +++ b/src/Stringy/StaticStringy.php @@ -29,7 +29,7 @@ class StaticStringy } /** - * Returns a camelCase version of a supplied string. Trims surrounding + * Returns a camelCase version of the supplied string. Trims surrounding * spaces, capitalizes letters following digits, spaces, dashes and * underscores, and removes spaces, dashes, underscores. * @@ -43,9 +43,9 @@ class StaticStringy } /** - * Returns an UpperCamelCase version of a supplied string. Trims surrounding - * spaces, capitalizes letters following digits, spaces, dashes and - * underscores, and removes spaces, dashes, underscores. + * Returns an UpperCamelCase version of the supplied string. It trims + * surrounding spaces, capitalizes letters following digits, spaces, dashes + * and underscores, and removes spaces, dashes, underscores. * * @param string $str String to convert to UpperCamelCase * @param string $encoding The character encoding @@ -57,7 +57,7 @@ class StaticStringy } /** - * Returns a lowercase and trimmed string seperated by dashes. Dashes are + * Returns a lowercase and trimmed string separated by dashes. Dashes are * inserted before uppercase characters (with the exception of the first * character of the string), and in place of spaces as well as underscores. * @@ -71,7 +71,7 @@ class StaticStringy } /** - * Returns a lowercase and trimmed string seperated by underscores. + * Returns a lowercase and trimmed string separated by underscores. * Underscores are inserted before uppercase characters (with the exception * of the first character of the string), and in place of spaces as well as * dashes. @@ -86,7 +86,7 @@ class StaticStringy } /** - * Returns a case swapped version of a string. + * Returns a case swapped version of the string. * * @param string $str String to swap case * @param string $encoding The character encoding @@ -98,7 +98,7 @@ class StaticStringy } /** - * Capitalizes the first letter of each word in a string, after trimming. + * Returns a trimmed string with the first letter of each word capitalized. * Ignores the case of other letters, allowing for the use of acronyms. * Also accepts an array, $ignore, allowing you to list words not to be * capitalized. @@ -114,8 +114,8 @@ class StaticStringy } /** - * Capitalizes the first word of a string, replaces underscores with spaces, - * and strips '_id'. + * Capitalizes the first word of the string, replaces underscores with + * spaces, and strips '_id'. * * @param string $str String to humanize * @param string $encoding The character encoding @@ -127,8 +127,9 @@ class StaticStringy } /** - * Replaces smart quotes, ellipsis characters, and dashes from Windows-1252 - * (and commonly used in Word documents) with their ASCII equivalents. + * Returns a string with smart quotes, ellipsis characters, and dashes from + * Windows-1252 (commonly used in Word documents) replaced by their ASCII + * equivalents. * * @param string $str String to remove special chars * @param string $encoding The character encoding @@ -141,7 +142,7 @@ class StaticStringy /** * Trims the string and replaces consecutive whitespace characters with a - * single space. This inclues tabs and newline characters. + * single space. This includes tabs and newline characters. * * @param string $str The string to cleanup whitespace * @return string The trimmed string with condensed whitespace @@ -152,22 +153,23 @@ class StaticStringy } /** - * Converts some non-ASCII characters to their closest ASCII counterparts. + * Returns an ASCII version of the string. A set of non-ASCII characters are + * replaced with their closest ASCII counterparts, and the rest are removed. * * @param string $str A string with non-ASCII characters - * @return string The string after the replacements + * @return string A string containing only ASCII characters */ - public static function standardize($str) + public static function toAscii($str) { - return $result = Stringy::create($str)->standardize()->str; + return $result = Stringy::create($str)->toAscii()->str; } /** - * Pads a string to a given length with another string. If length is less - * than or equal to the length of $str, then no padding takes places. The - * default string used for padding is a space, and the default type (one of - * 'left', 'right', 'both') is 'right'. Throws an exception if $padType - * isn't one of those 3 values. + * Pads the string to a given length with $padStr. If length is less than + * or equal to the length of the string, no padding takes places. The default + * string used for padding is a space, and the default type (one of 'left', + * 'right', 'both') is 'right'. Throws an InvalidArgumentException if + * $padType isn't one of those 3 values. * * @param string $str String to pad * @param int $length Desired string length after padding @@ -187,7 +189,7 @@ class StaticStringy /** * Returns a new string of a given length such that the beginning of the - * string is padded. Alias for pad($str, $length, $padStr, 'left', $encoding) + * string is padded. Alias for pad() with a $padType of 'left'. * * @param string $str String to pad * @param int $length Desired string length after padding @@ -202,7 +204,7 @@ class StaticStringy /** * Returns a new string of a given length such that the end of the string is - * padded. Alias for pad($str, $length, $padStr, 'right', $encoding) + * padded. Alias for pad() with a $padType of 'right'. * * @param string $str String to pad * @param int $length Desired string length after padding @@ -217,7 +219,7 @@ class StaticStringy /** * Returns a new string of a given length such that both sides of the string - * string are padded. Alias for pad($str, $length, $padStr, 'both', $encoding) + * string are padded. Alias for pad() with a $padType of 'both'. * * @param string $str String to pad * @param int $length Desired string length after padding @@ -231,13 +233,13 @@ class StaticStringy } /** - * Returns true if the string $str begins with $substring, false otherwise. + * 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. * * @param string $str String to check the start of * @param string $substring The substring to look for - * @param bool $caseSensitive Whether or not to enfore case-sensitivity + * @param bool $caseSensitive Whether or not to enforce case-sensitivity * @param string $encoding The character encoding * @return bool Whether or not $str starts with $substring */ @@ -249,13 +251,13 @@ class StaticStringy } /** - * Returns true if the string $str ends with $substring, false otherwise. - * By default, the comparison is case-sensitive, but can be made insensitive - * by setting $caseSensitive to false. + * Returns true if the string ends with $substring, false otherwise. By + * default, the comparison is case-sensitive, but can be made insensitive by + * setting $caseSensitive to false. * * @param string $str String to check the end of * @param string $substring The substring to look for - * @param bool $caseSensitive Whether or not to enfore case-sensitivity + * @param bool $caseSensitive Whether or not to enforce case-sensitivity * @param string $encoding The character encoding * @return bool Whether or not $str ends with $substring */ @@ -267,7 +269,7 @@ class StaticStringy } /** - * Converts each tab in a string to some number of spaces, as defined by + * Converts each tab in the string to some number of spaces, as defined by * $tabLength. By default, each tab is converted to 4 consecutive spaces. * * @param string $str String to convert tabs to spaces @@ -280,7 +282,7 @@ class StaticStringy } /** - * Converts each occurence of some consecutive number of spaces, as defined + * Converts each occurrence of some consecutive number of spaces, as defined * by $tabLength, to a tab. By default, each 4 consecutive spaces are * converted to a tab. * @@ -294,10 +296,10 @@ class StaticStringy } /** - * Converts the supplied text into an URL slug. This includes replacing - * non-ASCII characters with their closest ASCII equivalents, removing - * non-alphanumeric and non-ASCII characters, and replacing whitespace with - * dashes. The string is also converted to lowercase. + * Converts the string into an URL slug. This includes replacing non-ASCII + * characters with their closest ASCII equivalents, removing non-alphanumeric + * and non-ASCII characters, and replacing whitespace with dashes. The string + * is also converted to lowercase. * * @param string $str Text to transform into an URL slug * @return string The corresponding URL slug @@ -308,7 +310,7 @@ class StaticStringy } /** - * Returns true if $haystack contains $needle, false otherwise. + * Returns true if the string contains $needle, false otherwise. * * @param string $haystack String being checked * @param string $needle Substring to look for @@ -333,7 +335,7 @@ class StaticStringy } /** - * Inserts $substring into $str at the $index provided. + * Inserts $substring into the string at the $index provided. * * @param string $str String to insert into * @param string $substring String to be inserted @@ -347,14 +349,14 @@ class StaticStringy } /** - * Truncates $str to a given length. If $substring is provided, and + * Truncates the string to a given length. If $substring is provided, and * truncating occurs, the string is further truncated so that the substring * may be appended without exceeding the desired length. * - * @param string $str String to truncate - * @param int $length Desired length of the truncated string - * @param string $substring The substring to append if it can fit - * @param string $encoding The character encoding + * @param string $str String to truncate + * @param int $length Desired length of the truncated string + * @param string $substring The substring to append if it can fit + * @param string $encoding The character encoding * @return string The resulting string after truncating */ public static function truncate($str, $length, $substring = '', @@ -370,10 +372,10 @@ class StaticStringy * is further truncated so that the substring may be appended without * exceeding the desired length. * - * @param string $str String to truncate - * @param int $length Desired length of the truncated string - * @param string $substring The substring to append if it can fit - * @param string $encoding The character encoding + * @param string $str String to truncate + * @param int $length Desired length of the truncated string + * @param string $substring The substring to append if it can fit + * @param string $encoding The character encoding * @return string The resulting string after truncating */ public static function safeTruncate($str, $length, $substring = '', @@ -384,10 +386,10 @@ class StaticStringy } /** - * Reverses a string. A multibyte version of strrev. + * Returns a reversed string. A multibyte version of strrev(). * - * @param string $str String to reverse - * @param string $encoding The character encoding + * @param string $str String to reverse + * @param string $encoding The character encoding * @return string The reversed string */ public static function reverse($str, $encoding = null) @@ -396,8 +398,8 @@ class StaticStringy } /** - * A multibyte str_shuffle function. It randomizes the order of characters - * in a string. + * A multibyte str_shuffle() function. It returns a string with its + * characters in random order. * * @param string $str String to shuffle * @param string $encoding The character encoding @@ -409,7 +411,7 @@ class StaticStringy } /** - * Trims $str. An alias for PHP's trim() function. + * Returns the trimmed string. An alias for PHP's trim() function. * * @param string $str String to trim * @return string Trimmed $str @@ -420,7 +422,7 @@ class StaticStringy } /** - * Finds the longest common prefix between $str and $otherStr. + * Returns the longest common prefix between the string and $otherStr. * * @param string $str First string for comparison * @param string $otherStr Second string for comparison @@ -434,7 +436,7 @@ class StaticStringy } /** - * Finds the longest common suffix between $str and $otherStr. + * Returns the longest common suffix between the string and $otherStr. * * @param string $str First string for comparison * @param string $otherStr Second string for comparison @@ -448,8 +450,8 @@ class StaticStringy } /** - * Finds the longest common substring between $str and $otherStr. In the - * case of ties, returns that which occurs first. + * Returns the longest common substring between the string and $otherStr. + * In the case of ties, it returns that which occurs first. * * @param string $str First string for comparison * @param string $otherStr Second string for comparison @@ -464,7 +466,7 @@ class StaticStringy } /** - * Returns the length of $str. An alias for PHP's mb_strlen() function. + * Returns the length of the string. An alias for PHP's mb_strlen() function. * * @param string $str The string to get the length of * @param string $encoding The character encoding @@ -476,13 +478,13 @@ class StaticStringy } /** - * Gets the substring of $str beginning at $start with the specified $length. + * Returns the substring beginning at $start with the specified $length. * It differs from the mb_substr() function in that providing a $length of * null will return the rest of the string, rather than an empty string. * - * @param string $str The string to get the length of - * @param int $start Position of the first character to use from str - * @param int $length Maximum number of characters used + * @param string $str The string to get the length of + * @param int $start Position of the first character to use + * @param int $length Maximum number of characters used * @param string $encoding The character encoding * @return string The substring of $str */ @@ -492,7 +494,7 @@ class StaticStringy } /** - * Gets the character of $str at $index, with indexes starting at 0. + * Returns the character of the string at $index, with indexes starting at 0. * * @param string $str The string from which to get the char * @param int $index Position of the character @@ -505,7 +507,7 @@ class StaticStringy } /** - * Gets the first $n characters of $str. + * Returns the first $n characters of the string. * * @param string $str The string from which to get the substring * @param int $n Number of chars to retrieve from the start @@ -518,7 +520,7 @@ class StaticStringy } /** - * Gets the last $n characters of $str. + * Returns the last $n characters of the string. * * @param string $str The string from which to get the substring * @param int $n Number of chars to retrieve from the end @@ -531,7 +533,8 @@ class StaticStringy } /** - * Ensures that $str begins with $substring. + * Ensures that the string begins with $substring. If it doesn't, it's + * prepended. * * @param string $str The string to modify * @param string $substring The substring to add if not present @@ -544,7 +547,8 @@ class StaticStringy } /** - * Ensures that $str ends with $substring. + * Ensures that the string begins with $substring. If it doesn't, it's + * appended. * * @param string $str The string to modify * @param string $substring The substring to add if not present @@ -557,7 +561,7 @@ class StaticStringy } /** - * Removes the prefix $substring if present. + * Returns a new string with the prefix $substring removed, if it was present. * * @param string $str String from which to remove the prefix * @param string $substring The prefix to remove @@ -570,7 +574,7 @@ class StaticStringy } /** - * Removes the suffix $substring if present. + * Returns a new string with the suffix $substring removed, if it was present. * * @param string $str String from which to remove the suffix * @param string $substring The suffix to remove @@ -583,7 +587,7 @@ class StaticStringy } /** - * Returns true if $str contains only alphabetic chars, false otherwise. + * Returns true if the string contains only alphabetic chars, false otherwise. * * @param string $str String to check * @param string $encoding The character encoding @@ -595,8 +599,8 @@ class StaticStringy } /** - * Returns true if $str contains only alphabetic and numeric chars, false - * otherwise. + * Returns true if the string contains only alphabetic and numeric chars, + * false otherwise. * * @param string $str String to check * @param string $encoding The character encoding @@ -608,7 +612,7 @@ class StaticStringy } /** - * Returns true if $str contains only whitespace chars, false otherwise. + * Returns true if the string contains only whitespace chars, false otherwise. * * @param string $str String to check * @param string $encoding The character encoding @@ -620,7 +624,7 @@ class StaticStringy } /** - * Returns true if $str contains only lower case chars, false otherwise. + * Returns true if the string contains only lower case chars, false otherwise. * * @param string $str String to check * @param string $encoding The character encoding @@ -632,7 +636,7 @@ class StaticStringy } /** - * Returns true if $str contains only upper case chars, false otherwise. + * Returns true if the string contains only upper case chars, false otherwise. * * @param string $str String to check * @param string $encoding The character encoding @@ -644,13 +648,13 @@ class StaticStringy } /** - * Returns the number of occurences of $substring in $str. An alias for - * mb_substr_count() + * Returns the number of occurrences of $substring in the given string. + * An alias for mb_substr_count() * - * @param string $str The haystack to search through + * @param string $str The string to search through * @param string $substring The substring to search for * @param string $encoding The character encoding - * @return int The number of $substring occurences + * @return int The number of $substring occurrences */ public static function count($str, $substring, $encoding = null) { @@ -658,7 +662,7 @@ class StaticStringy } /** - * Replaces all occurrences of $search with $replace in $str. + * Returns a string with all occurrences of $search replaced with $replace. * * @param string $str The haystack to search through * @param string $search The needle to search for @@ -668,6 +672,6 @@ class StaticStringy */ public static function replace($str, $search, $replace, $encoding = null) { - return Stringy::create($str, $encoding)->replace($search, $replace); + return Stringy::create($str, $encoding)->replace($search, $replace)->str; } } diff --git a/src/Stringy/Stringy.php b/src/Stringy/Stringy.php index 00d4bc5..7a0a75e 100644 --- a/src/Stringy/Stringy.php +++ b/src/Stringy/Stringy.php @@ -11,7 +11,7 @@ class Stringy /** * Creates a Stringy object and assigns both str and encoding properties * the supplied values. If $encoding is not specified, it defaults to - * mb_internal_encoding(). It then returns the instantiated object. + * mb_internal_encoding(). It then returns the initialized object. * * @param string $str String to modify * @param string $encoding The character encoding @@ -39,7 +39,7 @@ class Stringy } /** - * Converts the first character of the string to upper case. + * Converts the first character of the supplied string to upper case. * * @return Stringy Object with the first character of $str being upper case */ @@ -71,9 +71,9 @@ class Stringy } /** - * Converts the string to camelCase. Trims surrounding spaces, capitalizes - * letters following digits, spaces, dashes and underscores, and removes - * spaces, dashes, underscores. + * Returns a camelCase version of the supplied string. Trims surrounding + * spaces, capitalizes letters following digits, spaces, dashes and + * underscores, and removes spaces, dashes, underscores. * * @return Stringy Object with $str in camelCase */ @@ -102,9 +102,9 @@ class Stringy } /** - * Converts the string to UpperCamelCase. Trims surrounding spaces, capitalizes - * letters following digits, spaces, dashes and underscores, and removes - * spaces, dashes, underscores. + * Returns an UpperCamelCase version of the supplied string. It trims + * surrounding spaces, capitalizes letters following digits, spaces, dashes + * and underscores, and removes spaces, dashes, underscores. * * @return Stringy Object with $str in UpperCamelCase */ @@ -114,8 +114,8 @@ class Stringy } /** - * Sets the string to lowercase, trims it, and seperates is by dashes. Dashes - * are inserted before uppercase characters (with the exception of the first + * Returns a lowercase and trimmed string separated by dashes. Dashes are + * inserted before uppercase characters (with the exception of the first * character of the string), and in place of spaces as well as underscores. * * @return Stringy Object with a dasherized $str @@ -137,7 +137,7 @@ class Stringy } /** - * Sets $str to a lowercase and trimmed string seperated by underscores. + * Returns a lowercase and trimmed string separated by underscores. * Underscores are inserted before uppercase characters (with the exception * of the first character of the string), and in place of spaces as well as * dashes. @@ -161,7 +161,7 @@ class Stringy } /** - * Sets $str to a case swapped version of the string. + * Returns a case swapped version of the string. * * @return Stringy Object whose $str has each character's case swapped */ @@ -185,7 +185,7 @@ class Stringy } /** - * Capitalizes the first letter of each word in $str, after trimming. + * Returns a trimmed string with the first letter of each word capitalized. * Ignores the case of other letters, allowing for the use of acronyms. * Also accepts an array, $ignore, allowing you to list words not to be * capitalized. @@ -213,8 +213,8 @@ class Stringy } /** - * Capitalizes the first word of $str, replaces underscores with spaces, - * and strips '_id'. + * Capitalizes the first word of the string, replaces underscores with + * spaces, and strips '_id'. * * @return Stringy Object with a humanized $str */ @@ -229,8 +229,9 @@ class Stringy } /** - * Replaces smart quotes, ellipsis characters, and dashes from Windows-1252 - * (and commonly used in Word documents) with their ASCII equivalents. + * Returns a string with smart quotes, ellipsis characters, and dashes from + * Windows-1252 (commonly used in Word documents) replaced by their ASCII + * equivalents. * * @return Stringy Object whose $str has those characters removed */ @@ -247,10 +248,10 @@ class Stringy } /** - * Trims $str and replaces consecutive whitespace characters with a single - * space. This inclues tabs and newline characters. + * Trims the string and replaces consecutive whitespace characters with a + * single space. This includes tabs and newline characters. * - * @return Stringy Object with a trimmed $str with condensed whitespace + * @return Stringy Object with a trimmed $str and condensed whitespace */ public function collapseWhitespace() { @@ -261,11 +262,12 @@ class Stringy } /** - * Converts some non-ASCII characters to their closest ASCII counterparts. + * Returns an ASCII version of the string. A set of non-ASCII characters are + * replaced with their closest ASCII counterparts, and the rest are removed. * - * @return Stringy Object whose $str had those characters replaced + * @return Stringy Object whose $str contains only ASCII characters */ - public function standardize() + public function toAscii() { $stringy = self::create($this->str, $this->encoding); $charsArray = array( @@ -328,11 +330,11 @@ class Stringy } /** - * Pads $str to a given length with another string. If length is less than - * or equal to the length of $str, then no padding takes places. The default + * Pads the string to a given length with $padStr. If length is less than + * or equal to the length of the string, no padding takes places. The default * string used for padding is a space, and the default type (one of 'left', - * 'right', 'both') is 'right'. Throws an exception if $padType isn't one - * of those 3 values. + * 'right', 'both') is 'right'. Throws an InvalidArgumentException if + * $padType isn't one of those 3 values. * * @param int $length Desired string length after padding * @param string $padStr String used to pad, defaults to space @@ -387,8 +389,8 @@ class Stringy } /** - * Pads $str to a given length from the begining of the string. - * Alias for pad($length, $padStr, 'left') + * Returns a new string of a given length such that the beginning of the + * string is padded. Alias for pad() with a $padType of 'left'. * * @param int $length Desired string length after padding * @param string $padStr String used to pad, defaults to space @@ -400,8 +402,8 @@ class Stringy } /** - * Pads $str to a given length from the end of the string. - * Alias for pad($length, $padStr, 'left') + * Returns a new string of a given length such that the end of the string is + * padded. Alias for pad() with a $padType of 'right'. * * @param int $length Desired string length after padding * @param string $padStr String used to pad, defaults to space @@ -413,8 +415,8 @@ class Stringy } /** - * Pads $str to a given length such that both sides of the string string are - * padded. Alias for pad($str, $length, $padStr, 'both', $encoding) + * Returns a new string of a given length such that both sides of the string + * string are padded. Alias for pad() with a $padType of 'both'. * * @param int $length Desired string length after padding * @param string $padStr String used to pad, defaults to space @@ -426,12 +428,12 @@ class Stringy } /** - * Returns true if $str begins with $substring, false otherwise. By default, - * the comparison is case-sensitive, but can be made insensitive by setting - * $caseSensitive to false. + * 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. * * @param string $substring The substring to look for - * @param bool $caseSensitive Whether or not to enfore 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) @@ -448,12 +450,12 @@ class Stringy } /** - * Returns true if $str ends with $substring, false otherwise. By default, - * the comparison is case-sensitive, but can be made insensitive by setting - * $caseSensitive to false. + * Returns true if the string ends with $substring, false otherwise. By + * default, the comparison is case-sensitive, but can be made insensitive by + * setting $caseSensitive to false. * * @param string $substring The substring to look for - * @param bool $caseSensitive Whether or not to enfore case-sensitivity + * @param bool $caseSensitive Whether or not to enforce case-sensitivity * @return bool Whether or not $str ends with $substring */ public function endsWith($substring, $caseSensitive = true) @@ -473,7 +475,7 @@ class Stringy } /** - * Converts each tab in $str to some number of spaces, as defined by + * Converts each tab in the string to some number of spaces, as defined by * $tabLength. By default, each tab is converted to 4 consecutive spaces. * * @param int $tabLength Number of spaces to replace each tab with @@ -490,7 +492,7 @@ class Stringy } /** - * Converts each occurence of some consecutive number of spaces, as defined + * Converts each occurrence of some consecutive number of spaces, as defined * by $tabLength, to a tab. By default, each 4 consecutive spaces are * converted to a tab. * @@ -508,7 +510,7 @@ class Stringy } /** - * Converts $str into an URL slug. This includes replacing non-ASCII + * Converts the string into an URL slug. This includes replacing non-ASCII * characters with their closest ASCII equivalents, removing non-alphanumeric * and non-ASCII characters, and replacing whitespace with dashes. The string * is also converted to lowercase. @@ -519,7 +521,7 @@ class Stringy { $stringy = self::create($this->str, $this->encoding); - $stringy->str = preg_replace('/[^a-zA-Z\d -]/u', '', $stringy->standardize()); + $stringy->str = preg_replace('/[^a-zA-Z\d -]/u', '', $stringy->toAscii()); $stringy->str = $stringy->collapseWhitespace()->str; $stringy->str = str_replace(' ', '-', strtolower($stringy->str)); @@ -527,7 +529,7 @@ class Stringy } /** - * Returns true if $str contains $needle, false otherwise. + * Returns true if the string contains $needle, false otherwise. * * @param string $needle Substring to look for * @return bool Whether or not $str contains $needle @@ -555,7 +557,7 @@ class Stringy } /** - * Inserts $substring into $str at the $index provided. + * Inserts $substring into the string at the $index provided. * * @param string $substring String to be inserted * @param int $index The index at which to insert the substring @@ -576,7 +578,7 @@ class Stringy } /** - * Truncates $str to a given length. If $substring is provided, and + * Truncates the string to a given length. If $substring is provided, and * truncating occurs, the string is further truncated so that the substring * may be appended without exceeding the desired length. * @@ -601,8 +603,8 @@ class Stringy } /** - * Truncates $str to a given length, while ensuring that it does not chop - * words. If $substring is provided, and truncating occurs, the string + * Truncates the string to a given length, while ensuring that it does not + * chop words. If $substring is provided, and truncating occurs, the string * is further truncated so that the substring may be appended without * exceeding the desired length. * @@ -635,7 +637,7 @@ class Stringy } /** - * Reverses $str. A multibyte version of strrev. + * Returns a reversed string. A multibyte version of strrev(). * * @return Stringy Object with a reversed $str */ @@ -653,8 +655,8 @@ class Stringy } /** - * A multibyte str_shuffle function. It randomizes the order of characters - * in $str. + * A multibyte str_shuffle() function. It returns a string with its + * characters in random order. * * @return Stringy Object with a shuffled $str */ @@ -672,7 +674,7 @@ class Stringy } /** - * Trims $str. An alias for PHP's trim() function. + * Returns the trimmed string. An alias for PHP's trim() function. * * @return Stringy Object with a trimmed $str */ @@ -682,7 +684,7 @@ class Stringy } /** - * Finds the longest common prefix between $str and $otherStr. + * Returns the longest common prefix between the string and $otherStr. * * @param string $otherStr Second string for comparison * @return Stringy Object with its $str being the longest common prefix @@ -706,7 +708,7 @@ class Stringy } /** - * Finds the longest common suffix between $str and $otherStr. + * Returns the longest common suffix between the string and $otherStr. * * @param string $otherStr Second string for comparison * @return Stringy Object with its $str being the longest common suffix @@ -730,8 +732,8 @@ class Stringy } /** - * Finds the longest common substring between $str and $otherStr. In the - * case of ties, returns that which occurs first. + * Returns the longest common substring between the string and $otherStr. + * In the case of ties, it returns that which occurs first. * * @param string $otherStr Second string for comparison * @return Stringy Object with its $str being the longest common substring @@ -777,7 +779,7 @@ class Stringy } /** - * Returns the length of $str. An alias for PHP's mb_strlen() function. + * Returns the length of the string. An alias for PHP's mb_strlen() function. * * @return int The number of characters in $str given the encoding */ @@ -787,12 +789,12 @@ class Stringy } /** - * Gets the substring of $str beginning at $start with the specified $length. + * Returns the substring beginning at $start with the specified $length. * It differs from the mb_substr() function in that providing a $length of * null will return the rest of the string, rather than an empty string. * - * @param int $start Position of the first character to use from str - * @param int $length Maximum number of characters used + * @param int $start Position of the first character to use + * @param int $length Maximum number of characters used * @return Stringy Object with its $str being the substring */ public function substr($start, $length = null) @@ -811,10 +813,10 @@ class Stringy } /** - * Gets the character of $str at $index, with indexes starting at 0. + * Returns the character of the string at $index, with indexes starting at 0. * - * @param int $index Position of the character - * @return Stringy Object with its $str being the selected character + * @param int $index Position of the character + * @return Stringy The character at $index */ public function at($index) { @@ -822,7 +824,7 @@ class Stringy } /** - * Gets the first $n characters of $str. + * Returns the first $n characters of the string. * * @param int $n Number of characters to retrieve from the start * @return Stringy Object with its $str being the first $n chars @@ -841,7 +843,7 @@ class Stringy } /** - * Gets the last $n characters of $str. + * Returns the last $n characters of the string. * * @param int $n Number of characters to retrieve from the end * @return Stringy Object with its $str being the last $n chars @@ -860,7 +862,8 @@ class Stringy } /** - * Ensures that $str begins with $substring. + * Ensures that the string begins with $substring. If it doesn't, it's + * prepended. * * @param string $substring The substring to add if not present * @return Stringy Object with its $str prefixed by the $substring @@ -876,7 +879,8 @@ class Stringy } /** - * Ensures that $str ends with $substring. + * Ensures that the string begins with $substring. If it doesn't, it's + * appended. * * @param string $substring The substring to add if not present * @return Stringy Object with its $str suffixed by the $substring @@ -892,7 +896,7 @@ class Stringy } /** - * Removes the prefix $substring if present. + * Returns a new string with the prefix $substring removed, if it was present. * * @param string $substring The prefix to remove * @return Stringy Object having a $str without the prefix $substring @@ -910,7 +914,7 @@ class Stringy } /** - * Removes the suffix $substring if present. + * Returns a new string with the suffix $substring removed, if it was present. * * @param string $substring The suffix to remove * @return Stringy Object having a $str without the suffix $substring @@ -945,7 +949,7 @@ class Stringy } /** - * Returns true if $str contains only alphabetic chars, false otherwise. + * Returns true if the string contains only alphabetic chars, false otherwise. * * @return bool Whether or not $str contains only alphabetic chars */ @@ -955,8 +959,8 @@ class Stringy } /** - * Returns true if $str contains only alphabetic and numeric chars, false - * otherwise. + * Returns true if the string contains only alphabetic and numeric chars, + * false otherwise. * * @return bool Whether or not $str contains only alphanumeric chars */ @@ -966,7 +970,7 @@ class Stringy } /** - * Returns true if $str contains only whitespace chars, false otherwise. + * Returns true if the string contains only whitespace chars, false otherwise. * * @return bool Whether or not $str contains only whitespace characters */ @@ -976,7 +980,7 @@ class Stringy } /** - * Returns true if $str contains only lower case chars, false otherwise. + * Returns true if the string contains only lower case chars, false otherwise. * * @return bool Whether or not $str contains only lower case characters */ @@ -986,7 +990,7 @@ class Stringy } /** - * Returns true if $str contains only lower case chars, false otherwise. + * Returns true if the string contains only lower case chars, false otherwise. * * @return bool Whether or not $str contains only lower case characters */ @@ -996,11 +1000,11 @@ class Stringy } /** - * Returns the number of occurences of $substring in $str. An alias for - * mb_substr_count() + * Returns the number of occurrences of $substring in the given string. + * An alias for mb_substr_count() * * @param string $substring The substring to search for - * @return int The number of $substring occurences + * @return int The number of $substring occurrences */ public function count($substring) { @@ -1008,7 +1012,7 @@ class Stringy } /** - * Replaces all occurrences of $search with $replace in $str. + * Returns a string with all occurrences of $search replaced with $replace. * * @param string $search The needle to search for * @param string $replace The string to replace with diff --git a/tests/Stringy/CommonTest.php b/tests/Stringy/CommonTest.php index f3cfcc8..54afb6c 100644 --- a/tests/Stringy/CommonTest.php +++ b/tests/Stringy/CommonTest.php @@ -180,7 +180,7 @@ class CommonTest extends PHPUnit_Framework_TestCase return $testData; } - public function stringsForStandardize() + public function stringsForToAscii() { $testData = array( array('foo bar', 'fòô bàř'), diff --git a/tests/Stringy/StaticStringyTest.php b/tests/Stringy/StaticStringyTest.php index dab1f23..d2be4f2 100644 --- a/tests/Stringy/StaticStringyTest.php +++ b/tests/Stringy/StaticStringyTest.php @@ -13,6 +13,7 @@ class StaticStringyTestCase extends CommonTest public function testUpperCaseFirst($expected, $str, $encoding = null) { $result = S::upperCaseFirst($str, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -22,6 +23,7 @@ class StaticStringyTestCase extends CommonTest public function testLowerCaseFirst($expected, $str, $encoding = null) { $result = S::lowerCaseFirst($str, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -31,6 +33,7 @@ class StaticStringyTestCase extends CommonTest public function testCamelize($expected, $str, $encoding = null) { $result = S::camelize($str, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -40,6 +43,7 @@ class StaticStringyTestCase extends CommonTest public function testUpperCamelize($expected, $str, $encoding = null) { $result = S::upperCamelize($str, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -49,6 +53,7 @@ class StaticStringyTestCase extends CommonTest public function testDasherize($expected, $str, $encoding = null) { $result = S::dasherize($str, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -58,6 +63,7 @@ class StaticStringyTestCase extends CommonTest public function testUnderscored($expected, $str, $encoding = null) { $result = S::underscored($str, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -67,6 +73,7 @@ class StaticStringyTestCase extends CommonTest public function testSwapCase($expected, $str, $encoding = null) { $result = S::swapCase($str, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -77,6 +84,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::titleize($str, $ignore, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -86,6 +94,7 @@ class StaticStringyTestCase extends CommonTest public function testHumanize($expected, $str, $encoding = null) { $result = S::humanize($str, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -95,6 +104,7 @@ class StaticStringyTestCase extends CommonTest public function testTidy($expected, $str) { $result = S::tidy($str); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -104,15 +114,17 @@ class StaticStringyTestCase extends CommonTest public function testCollapseWhitespace($expected, $str) { $result = S::collapseWhitespace($str); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } /** - * @dataProvider stringsForStandardize + * @dataProvider stringsForToAscii */ - public function testStandardize($expected, $str) + public function testToAscii($expected, $str) { - $result = S::standardize($str); + $result = S::toAscii($str); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -123,6 +135,7 @@ class StaticStringyTestCase extends CommonTest $padType = 'right', $encoding = null) { $result = S::pad($str, $length, $padStr, $padType, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -133,6 +146,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::padLeft($str, $length, $padStr, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -143,6 +157,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::padRight($str, $length, $padStr, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -153,6 +168,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::padBoth($str, $length, $padStr, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -163,6 +179,7 @@ class StaticStringyTestCase extends CommonTest $caseSensitive = true, $encoding = null) { $result = S::startsWith($str, $substring, $caseSensitive, $encoding); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); } @@ -173,6 +190,7 @@ class StaticStringyTestCase extends CommonTest $caseSensitive = true, $encoding = null) { $result = S::endsWith($str, $substring, $caseSensitive, $encoding); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); } @@ -182,6 +200,7 @@ class StaticStringyTestCase extends CommonTest public function testToSpaces($expected, $str, $tabLength = 4) { $result = S::toSpaces($str, $tabLength); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -191,6 +210,7 @@ class StaticStringyTestCase extends CommonTest public function testToTabs($expected, $str, $tabLength = 4) { $result = S::toTabs($str, $tabLength); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -200,6 +220,7 @@ class StaticStringyTestCase extends CommonTest public function testSlugify($expected, $str) { $result = S::slugify($str); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -209,6 +230,7 @@ class StaticStringyTestCase extends CommonTest public function testContains($expected, $haystack, $needle, $encoding = null) { $result = S::contains($haystack, $needle, $encoding); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); } @@ -218,6 +240,7 @@ class StaticStringyTestCase extends CommonTest public function testSurround($expected, $str, $substring) { $result = S::surround($str, $substring); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -228,6 +251,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::insert($str, $substring, $index, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -238,6 +262,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::truncate($str, $length, $substring, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -248,6 +273,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::safeTruncate($str, $length, $substring, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -257,6 +283,7 @@ class StaticStringyTestCase extends CommonTest public function testReverse($expected, $str, $encoding = null) { $result = S::reverse($str, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -267,6 +294,7 @@ class StaticStringyTestCase extends CommonTest { // We'll just make sure that the chars are present before/after shuffle $result = S::shuffle($str, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals(count_chars($str), count_chars($result)); } @@ -276,6 +304,7 @@ class StaticStringyTestCase extends CommonTest public function testTrim($expected, $str) { $result = S::trim($str); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -286,6 +315,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::longestCommonPrefix($str, $otherStr, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -296,6 +326,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::longestCommonSuffix($str, $otherStr, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -306,6 +337,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::longestCommonSubstring($str, $otherStr, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -316,6 +348,7 @@ class StaticStringyTestCase extends CommonTest { $result = S::length($str, $encoding); $this->assertEquals($expected, $result); + $this->assertInternalType('int', $result); } /** @@ -325,6 +358,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::substr($str, $start, $length, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -334,6 +368,7 @@ class StaticStringyTestCase extends CommonTest public function testAt($expected, $str, $index, $encoding = null) { $result = S::at($str, $index, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -343,6 +378,7 @@ class StaticStringyTestCase extends CommonTest public function testFirst($expected, $str, $n, $encoding = null) { $result = S::first($str, $n, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -352,6 +388,7 @@ class StaticStringyTestCase extends CommonTest public function testLast($expected, $str, $n, $encoding = null) { $result = S::last($str, $n, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -361,6 +398,7 @@ class StaticStringyTestCase extends CommonTest public function testEnsureLeft($expected, $str, $substring, $encoding = null) { $result = S::ensureLeft($str, $substring, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -370,6 +408,7 @@ class StaticStringyTestCase extends CommonTest public function testEnsureRight($expected, $str, $substring, $encoding = null) { $result = S::ensureRight($str, $substring, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -379,6 +418,7 @@ class StaticStringyTestCase extends CommonTest public function testRemoveLeft($expected, $str, $substring, $encoding = null) { $result = S::removeLeft($str, $substring, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -388,6 +428,7 @@ class StaticStringyTestCase extends CommonTest public function testRemoveRight($expected, $str, $substring, $encoding = null) { $result = S::removeRight($str, $substring, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } @@ -397,6 +438,7 @@ class StaticStringyTestCase extends CommonTest public function testIsAlpha($expected, $str, $encoding = null) { $result = S::isAlpha($str, $encoding); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); } @@ -406,6 +448,7 @@ class StaticStringyTestCase extends CommonTest public function testIsAlphanumeric($expected, $str, $encoding = null) { $result = S::isAlphanumeric($str, $encoding); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); } @@ -415,6 +458,7 @@ class StaticStringyTestCase extends CommonTest public function testIsBlank($expected, $str, $encoding = null) { $result = S::isBlank($str, $encoding); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); } @@ -424,6 +468,7 @@ class StaticStringyTestCase extends CommonTest public function testIsLowerCase($expected, $str, $encoding = null) { $result = S::isLowerCase($str, $encoding); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); } @@ -433,6 +478,7 @@ class StaticStringyTestCase extends CommonTest public function testIsUpperCase($expected, $str, $encoding = null) { $result = S::isUpperCase($str, $encoding); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); } @@ -442,6 +488,7 @@ class StaticStringyTestCase extends CommonTest public function testCount($expected, $str, $substring, $encoding = null) { $result = S::count($str, $substring, $encoding); + $this->assertInternalType('int', $result); $this->assertEquals($expected, $result); } @@ -452,6 +499,7 @@ class StaticStringyTestCase extends CommonTest $encoding = null) { $result = S::replace($str, $search, $replace, $encoding); + $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); } } diff --git a/tests/Stringy/StringyTest.php b/tests/Stringy/StringyTest.php index 7c4567d..45bfdc8 100644 --- a/tests/Stringy/StringyTest.php +++ b/tests/Stringy/StringyTest.php @@ -7,12 +7,29 @@ use Stringy\Stringy as S; class StringyTestCase extends CommonTest { + public function testCreate() + { + $stringy = S::create('foo bar', 'UTF-8'); + $this->assertInstanceOf('Stringy\Stringy', $stringy); + $this->assertEquals('foo bar', $stringy->str); + $this->assertEquals('UTF-8', $stringy->encoding); + } + + public function testChaining() + { + $stringy = S::create("Fòô Bàř", 'UTF-8'); + $this->assertInstanceOf('Stringy\Stringy', $stringy); + $result = $stringy->collapseWhitespace()->swapCase()->upperCaseFirst(); + $this->assertEquals('FÒÔ bÀŘ', $result); + } + /** * @dataProvider stringsForUpperCaseFirst */ public function testUpperCaseFirst($expected, $str, $encoding = null) { $result = S::create($str, $encoding)->upperCaseFirst(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); } @@ -23,6 +40,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->lowerCaseFirst(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -34,6 +52,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->camelize(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -45,6 +64,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->upperCamelize(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -56,6 +76,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->dasherize(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -67,6 +88,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->underscored(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -78,6 +100,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->swapCase(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -90,6 +113,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->titleize($ignore); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -101,6 +125,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->humanize(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -112,6 +137,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str); $result = $stringy->tidy(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -123,17 +149,19 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str); $result = $stringy->collapseWhitespace(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } /** - * @dataProvider stringsForStandardize + * @dataProvider stringsForToAscii */ - public function testStandardize($expected, $str) + public function testToAscii($expected, $str) { $stringy = S::create($str); - $result = $stringy->standardize(); + $result = $stringy->toAscii(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -146,6 +174,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->pad($length, $padStr, $padType); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -158,6 +187,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->padLeft($length, $padStr); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -170,6 +200,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->padRight($length, $padStr); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -182,6 +213,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->padBoth($length, $padStr); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -194,6 +226,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->startsWith($substring, $caseSensitive); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -206,6 +239,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->endsWith($substring, $caseSensitive); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -217,6 +251,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str); $result = $stringy->toSpaces($tabLength); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -228,6 +263,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str); $result = $stringy->toTabs($tabLength); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -239,6 +275,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str); $result = $stringy->slugify(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -250,6 +287,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($haystack, $encoding); $result = $stringy->contains($needle); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); $this->assertEquals($haystack, $stringy); } @@ -261,6 +299,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str); $result = $stringy->surround($substring); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -273,6 +312,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->insert($substring, $index); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -285,6 +325,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->truncate($length, $substring); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -296,6 +337,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->reverse(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -308,6 +350,7 @@ class StringyTestCase extends CommonTest // We'll just make sure that the chars are present before/after shuffle $stringy = S::create($str, $encoding); $result = $stringy->shuffle(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals(count_chars($str), count_chars($result)); $this->assertEquals($str, $stringy); } @@ -319,6 +362,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str); $result = $stringy->trim(); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -331,6 +375,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->longestCommonPrefix($otherStr); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -343,6 +388,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->longestCommonSubstring($otherStr); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -354,6 +400,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->length(); + $this->assertInternalType('int', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -366,6 +413,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->substr($start, $length); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -377,6 +425,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->at($index); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -388,6 +437,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->first($n); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -399,6 +449,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->last($n); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -410,6 +461,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->ensureLeft($substring); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -421,6 +473,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->ensureRight($substring); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -432,6 +485,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->removeLeft($substring); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -443,6 +497,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->removeRight($substring); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -454,6 +509,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->isAlpha(); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -465,6 +521,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->isAlphanumeric(); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -476,6 +533,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->isBlank(); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -487,6 +545,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->isLowerCase(); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -498,6 +557,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->isUpperCase(); + $this->assertInternalType('boolean', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -509,6 +569,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->count($substring); + $this->assertInternalType('int', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); } @@ -521,6 +582,7 @@ class StringyTestCase extends CommonTest { $stringy = S::create($str, $encoding); $result = $stringy->replace($search, $replace); + $this->assertInstanceOf('Stringy\Stringy', $result); $this->assertEquals($expected, $result); $this->assertEquals($str, $stringy); }