Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Stringy often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Stringy, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * An instance's string. |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $str; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The string's encoding, which should be one of the mbstring module's |
||
| 25 | * supported encodings. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $encoding; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Initializes a Stringy object and assigns both str and encoding properties |
||
| 33 | * the supplied values. $str is cast to a string prior to assignment, and if |
||
| 34 | * $encoding is not specified, it defaults to mb_internal_encoding(). Throws |
||
| 35 | * an InvalidArgumentException if the first argument is an array or object |
||
| 36 | * without a __toString method. |
||
| 37 | * |
||
| 38 | * @param mixed $str Value to modify, after being cast to string |
||
| 39 | * @param string $encoding The character encoding |
||
| 40 | * |
||
| 41 | * @throws \InvalidArgumentException if an array or object without a |
||
| 42 | * __toString method is passed as the first argument |
||
| 43 | */ |
||
| 44 | 1014 | public function __construct($str = '', $encoding = null) |
|
| 78 | |||
| 79 | /** |
||
| 80 | * Returns the value in $str. |
||
| 81 | * |
||
| 82 | * @return string The current value of the $str property |
||
| 83 | */ |
||
| 84 | 972 | public function __toString() |
|
| 88 | |||
| 89 | /** |
||
| 90 | * Returns a new string with $string appended. |
||
| 91 | * |
||
| 92 | * @param string $string The string to append |
||
| 93 | * |
||
| 94 | * @return Stringy Object with appended $string |
||
| 95 | */ |
||
| 96 | 5 | public function append($string) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Append an password (limited to chars that are good readable). |
||
| 103 | * |
||
| 104 | * @param int $length length of the random string |
||
| 105 | * |
||
| 106 | * @return Stringy Object with appended password |
||
| 107 | */ |
||
| 108 | 1 | public function appendPassword($length) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Append an unique identifier. |
||
| 117 | * |
||
| 118 | * @param string|int $extraPrefix |
||
| 119 | * |
||
| 120 | * @return Stringy Object with appended unique identifier as md5-hash |
||
| 121 | */ |
||
| 122 | 1 | public function appendUniqueIdentifier($extraPrefix = '') |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Append an random string. |
||
| 135 | * |
||
| 136 | * @param int $length length of the random string |
||
| 137 | * @param string $possibleChars characters string for the random selection |
||
| 138 | * |
||
| 139 | * @return Stringy Object with appended random string |
||
| 140 | */ |
||
| 141 | 2 | public function appendRandomString($length, $possibleChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') |
|
| 162 | |||
| 163 | /** |
||
| 164 | * Creates a Stringy object and assigns both str and encoding properties |
||
| 165 | * the supplied values. $str is cast to a string prior to assignment, and if |
||
| 166 | * $encoding is not specified, it defaults to mb_internal_encoding(). It |
||
| 167 | * then returns the initialized object. Throws an InvalidArgumentException |
||
| 168 | * if the first argument is an array or object without a __toString method. |
||
| 169 | * |
||
| 170 | * @param mixed $str Value to modify, after being cast to string |
||
| 171 | * @param string $encoding The character encoding |
||
| 172 | * |
||
| 173 | * @return Stringy A Stringy object |
||
| 174 | * @throws \InvalidArgumentException if an array or object without a |
||
| 175 | * __toString method is passed as the first argument |
||
| 176 | */ |
||
| 177 | 1004 | public static function create($str = '', $encoding = null) |
|
| 181 | |||
| 182 | /** |
||
| 183 | * Returns the substring between $start and $end, if found, or an empty |
||
| 184 | * string. An optional offset may be supplied from which to begin the |
||
| 185 | * search for the start string. |
||
| 186 | * |
||
| 187 | * @param string $start Delimiter marking the start of the substring |
||
| 188 | * @param string $end Delimiter marketing the end of the substring |
||
| 189 | * @param int $offset Index from which to begin the search |
||
| 190 | * |
||
| 191 | * @return Stringy Object whose $str has been converted to an URL slug |
||
| 192 | */ |
||
| 193 | 16 | public function between($start, $end, $offset = 0) |
|
| 208 | |||
| 209 | /** |
||
| 210 | * Returns the index of the first occurrence of $needle in the string, |
||
| 211 | * and false if not found. Accepts an optional offset from which to begin |
||
| 212 | * the search. |
||
| 213 | * |
||
| 214 | * @param string $needle Substring to look for |
||
| 215 | * @param int $offset Offset from which to search |
||
| 216 | * |
||
| 217 | * @return int|bool The occurrence's index if found, otherwise false |
||
| 218 | */ |
||
| 219 | 26 | public function indexOf($needle, $offset = 0) |
|
| 223 | |||
| 224 | /** |
||
| 225 | * Returns the substring beginning at $start with the specified $length. |
||
| 226 | * It differs from the UTF8::substr() function in that providing a $length of |
||
| 227 | * null will return the rest of the string, rather than an empty string. |
||
| 228 | * |
||
| 229 | * @param int $start Position of the first character to use |
||
| 230 | * @param int $length Maximum number of characters used |
||
| 231 | * |
||
| 232 | * @return Stringy Object with its $str being the substring |
||
| 233 | */ |
||
| 234 | 66 | public function substr($start, $length = null) |
|
| 244 | |||
| 245 | /** |
||
| 246 | * Returns the length of the string. |
||
| 247 | * |
||
| 248 | * @return int The number of characters in $str given the encoding |
||
| 249 | */ |
||
| 250 | 248 | public function length() |
|
| 254 | |||
| 255 | /** |
||
| 256 | * Trims the string and replaces consecutive whitespace characters with a |
||
| 257 | * single space. This includes tabs and newline characters, as well as |
||
| 258 | * multibyte whitespace such as the thin space and ideographic space. |
||
| 259 | * |
||
| 260 | * @return Stringy Object with a trimmed $str and condensed whitespace |
||
| 261 | */ |
||
| 262 | 13 | public function collapseWhitespace() |
|
| 266 | |||
| 267 | /** |
||
| 268 | * Returns a string with whitespace removed from the start and end of the |
||
| 269 | * string. Supports the removal of unicode whitespace. Accepts an optional |
||
| 270 | * string of characters to strip instead of the defaults. |
||
| 271 | * |
||
| 272 | * @param string $chars Optional string of characters to strip |
||
| 273 | * |
||
| 274 | * @return Stringy Object with a trimmed $str |
||
| 275 | */ |
||
| 276 | 114 | View Code Duplication | public function trim($chars = null) |
| 286 | |||
| 287 | /** |
||
| 288 | * Replaces all occurrences of $pattern in $str by $replacement. |
||
| 289 | * |
||
| 290 | * @param string $pattern The regular expression pattern |
||
| 291 | * @param string $replacement The string to replace with |
||
| 292 | * @param string $options Matching conditions to be used |
||
| 293 | * |
||
| 294 | * @return Stringy Object with the result2ing $str after the replacements |
||
| 295 | */ |
||
| 296 | 184 | public function regexReplace($pattern, $replacement, $options = '') |
|
| 310 | |||
| 311 | /** |
||
| 312 | * Returns true if the string contains all $needles, false otherwise. By |
||
| 313 | * default the comparison is case-sensitive, but can be made insensitive by |
||
| 314 | * setting $caseSensitive to false. |
||
| 315 | * |
||
| 316 | * @param array $needles SubStrings to look for |
||
| 317 | * @param bool $caseSensitive Whether or not to enforce case-sensitivity |
||
| 318 | * |
||
| 319 | * @return bool Whether or not $str contains $needle |
||
| 320 | */ |
||
| 321 | 43 | View Code Duplication | public function containsAll($needles, $caseSensitive = true) |
| 336 | |||
| 337 | /** |
||
| 338 | * Returns true if the string contains $needle, false otherwise. By default |
||
| 339 | * the comparison is case-sensitive, but can be made insensitive by setting |
||
| 340 | * $caseSensitive to false. |
||
| 341 | * |
||
| 342 | * @param string $needle Substring to look for |
||
| 343 | * @param bool $caseSensitive Whether or not to enforce case-sensitivity |
||
| 344 | * |
||
| 345 | * @return bool Whether or not $str contains $needle |
||
| 346 | */ |
||
| 347 | 105 | public function contains($needle, $caseSensitive = true) |
|
| 357 | |||
| 358 | /** |
||
| 359 | * Returns true if the string contains any $needles, false otherwise. By |
||
| 360 | * default the comparison is case-sensitive, but can be made insensitive by |
||
| 361 | * setting $caseSensitive to false. |
||
| 362 | * |
||
| 363 | * @param array $needles SubStrings to look for |
||
| 364 | * @param bool $caseSensitive Whether or not to enforce case-sensitivity |
||
| 365 | * |
||
| 366 | * @return bool Whether or not $str contains $needle |
||
| 367 | */ |
||
| 368 | 43 | View Code Duplication | public function containsAny($needles, $caseSensitive = true) |
| 383 | |||
| 384 | /** |
||
| 385 | * Returns the length of the string, implementing the countable interface. |
||
| 386 | * |
||
| 387 | * @return int The number of characters in the string, given the encoding |
||
| 388 | */ |
||
| 389 | 1 | public function count() |
|
| 393 | |||
| 394 | /** |
||
| 395 | * Returns the number of occurrences of $substring in the given string. |
||
| 396 | * By default, the comparison is case-sensitive, but can be made insensitive |
||
| 397 | * by setting $caseSensitive to false. |
||
| 398 | * |
||
| 399 | * @param string $substring The substring to search for |
||
| 400 | * @param bool $caseSensitive Whether or not to enforce case-sensitivity |
||
| 401 | * |
||
| 402 | * @return int The number of $substring occurrences |
||
| 403 | */ |
||
| 404 | 15 | public function countSubstr($substring, $caseSensitive = true) |
|
| 415 | |||
| 416 | /** |
||
| 417 | * Returns a lowercase and trimmed string separated by dashes. Dashes are |
||
| 418 | * inserted before uppercase characters (with the exception of the first |
||
| 419 | * character of the string), and in place of spaces as well as underscores. |
||
| 420 | * |
||
| 421 | * @return Stringy Object with a dasherized $str |
||
| 422 | */ |
||
| 423 | 19 | public function dasherize() |
|
| 427 | |||
| 428 | /** |
||
| 429 | * Returns a lowercase and trimmed string separated by the given delimiter. |
||
| 430 | * Delimiters are inserted before uppercase characters (with the exception |
||
| 431 | * of the first character of the string), and in place of spaces, dashes, |
||
| 432 | * and underscores. Alpha delimiters are not converted to lowercase. |
||
| 433 | * |
||
| 434 | * @param string $delimiter Sequence used to separate parts of the string |
||
| 435 | * |
||
| 436 | * @return Stringy Object with a delimited $str |
||
| 437 | */ |
||
| 438 | 49 | public function delimit($delimiter) |
|
| 450 | |||
| 451 | /** |
||
| 452 | * Ensures that the string begins with $substring. If it doesn't, it's |
||
| 453 | * prepended. |
||
| 454 | * |
||
| 455 | * @param string $substring The substring to add if not present |
||
| 456 | * |
||
| 457 | * @return Stringy Object with its $str prefixed by the $substring |
||
| 458 | */ |
||
| 459 | 10 | View Code Duplication | public function ensureLeft($substring) |
| 469 | |||
| 470 | /** |
||
| 471 | * Returns true if the string begins with $substring, false otherwise. By |
||
| 472 | * default, the comparison is case-sensitive, but can be made insensitive |
||
| 473 | * by setting $caseSensitive to false. |
||
| 474 | * |
||
| 475 | * @param string $substring The substring to look for |
||
| 476 | * @param bool $caseSensitive Whether or not to enforce case-sensitivity |
||
| 477 | * |
||
| 478 | * @return bool Whether or not $str starts with $substring |
||
| 479 | */ |
||
| 480 | 33 | public function startsWith($substring, $caseSensitive = true) |
|
| 495 | |||
| 496 | /** |
||
| 497 | * Ensures that the string ends with $substring. If it doesn't, it's |
||
| 498 | * appended. |
||
| 499 | * |
||
| 500 | * @param string $substring The substring to add if not present |
||
| 501 | * |
||
| 502 | * @return Stringy Object with its $str suffixed by the $substring |
||
| 503 | */ |
||
| 504 | 10 | View Code Duplication | public function ensureRight($substring) |
| 514 | |||
| 515 | /** |
||
| 516 | * Returns true if the string ends with $substring, false otherwise. By |
||
| 517 | * default, the comparison is case-sensitive, but can be made insensitive |
||
| 518 | * by setting $caseSensitive to false. |
||
| 519 | * |
||
| 520 | * @param string $substring The substring to look for |
||
| 521 | * @param bool $caseSensitive Whether or not to enforce case-sensitivity |
||
| 522 | * |
||
| 523 | * @return bool Whether or not $str ends with $substring |
||
| 524 | */ |
||
| 525 | 33 | public function endsWith($substring, $caseSensitive = true) |
|
| 544 | |||
| 545 | /** |
||
| 546 | * Returns the first $n characters of the string. |
||
| 547 | * |
||
| 548 | * @param int $n Number of characters to retrieve from the start |
||
| 549 | * |
||
| 550 | * @return Stringy Object with its $str being the first $n chars |
||
| 551 | */ |
||
| 552 | 12 | View Code Duplication | public function first($n) |
| 564 | |||
| 565 | /** |
||
| 566 | * Returns the encoding used by the Stringy object. |
||
| 567 | * |
||
| 568 | * @return string The current value of the $encoding property |
||
| 569 | */ |
||
| 570 | 3 | public function getEncoding() |
|
| 574 | |||
| 575 | /** |
||
| 576 | * Returns a new ArrayIterator, thus implementing the IteratorAggregate |
||
| 577 | * interface. The ArrayIterator's constructor is passed an array of chars |
||
| 578 | * in the multibyte string. This enables the use of foreach with instances |
||
| 579 | * of Stringy\Stringy. |
||
| 580 | * |
||
| 581 | * @return \ArrayIterator An iterator for the characters in the string |
||
| 582 | */ |
||
| 583 | 1 | public function getIterator() |
|
| 587 | |||
| 588 | /** |
||
| 589 | * Returns an array consisting of the characters in the string. |
||
| 590 | * |
||
| 591 | * @return array An array of string chars |
||
| 592 | */ |
||
| 593 | 4 | public function chars() |
|
| 605 | |||
| 606 | /** |
||
| 607 | * Returns the character at $index, with indexes starting at 0. |
||
| 608 | * |
||
| 609 | * @param int $index Position of the character |
||
| 610 | * |
||
| 611 | * @return Stringy The character at $index |
||
| 612 | */ |
||
| 613 | 11 | public function at($index) |
|
| 617 | |||
| 618 | /** |
||
| 619 | * Returns true if the string contains a lower case char, false |
||
| 620 | * otherwise. |
||
| 621 | * |
||
| 622 | * @return bool Whether or not the string contains a lower case character. |
||
| 623 | */ |
||
| 624 | 12 | public function hasLowerCase() |
|
| 628 | |||
| 629 | /** |
||
| 630 | * Returns true if $str matches the supplied pattern, false otherwise. |
||
| 631 | * |
||
| 632 | * @param string $pattern Regex pattern to match against |
||
| 633 | * |
||
| 634 | * @return bool Whether or not $str matches the pattern |
||
| 635 | */ |
||
| 636 | 91 | private function matchesPattern($pattern) |
|
| 644 | |||
| 645 | /** |
||
| 646 | * Returns true if the string contains an upper case char, false |
||
| 647 | * otherwise. |
||
| 648 | * |
||
| 649 | * @return bool Whether or not the string contains an upper case character. |
||
| 650 | */ |
||
| 651 | 12 | public function hasUpperCase() |
|
| 655 | |||
| 656 | /** |
||
| 657 | * Convert all HTML entities to their applicable characters. |
||
| 658 | * |
||
| 659 | * @param int|null $flags Optional flags |
||
| 660 | * |
||
| 661 | * @return Stringy Object with the resulting $str after being html decoded. |
||
| 662 | */ |
||
| 663 | 5 | public function htmlDecode($flags = ENT_COMPAT) |
|
| 669 | |||
| 670 | /** |
||
| 671 | * Convert all applicable characters to HTML entities. |
||
| 672 | * |
||
| 673 | * @param int|null $flags Optional flags |
||
| 674 | * |
||
| 675 | * @return Stringy Object with the resulting $str after being html encoded. |
||
| 676 | */ |
||
| 677 | 5 | public function htmlEncode($flags = ENT_COMPAT) |
|
| 683 | |||
| 684 | /** |
||
| 685 | * Capitalizes the first word of the string, replaces underscores with |
||
| 686 | * spaces, and strips '_id'. |
||
| 687 | * |
||
| 688 | * @return Stringy Object with a humanized $str |
||
| 689 | */ |
||
| 690 | 3 | public function humanize() |
|
| 696 | |||
| 697 | /** |
||
| 698 | * Converts the first character of the supplied string to upper case. |
||
| 699 | * |
||
| 700 | * @return Stringy Object with the first character of $str being upper case |
||
| 701 | */ |
||
| 702 | 27 | View Code Duplication | public function upperCaseFirst() |
| 716 | |||
| 717 | /** |
||
| 718 | * Returns the index of the last occurrence of $needle in the string, |
||
| 719 | * and false if not found. Accepts an optional offset from which to begin |
||
| 720 | * the search. Offsets may be negative to count from the last character |
||
| 721 | * in the string. |
||
| 722 | * |
||
| 723 | * @param string $needle Substring to look for |
||
| 724 | * @param int $offset Offset from which to search |
||
| 725 | * |
||
| 726 | * @return int|bool The last occurrence's index if found, otherwise false |
||
| 727 | */ |
||
| 728 | 10 | public function indexOfLast($needle, $offset = 0) |
|
| 732 | |||
| 733 | /** |
||
| 734 | * Inserts $substring into the string at the $index provided. |
||
| 735 | * |
||
| 736 | * @param string $substring String to be inserted |
||
| 737 | * @param int $index The index at which to insert the substring |
||
| 738 | * |
||
| 739 | * @return Stringy Object with the resulting $str after the insertion |
||
| 740 | */ |
||
| 741 | 8 | View Code Duplication | public function insert($substring, $index) |
| 758 | |||
| 759 | /** |
||
| 760 | * Returns true if the string contains only alphabetic chars, false |
||
| 761 | * otherwise. |
||
| 762 | * |
||
| 763 | * @return bool Whether or not $str contains only alphabetic chars |
||
| 764 | */ |
||
| 765 | 10 | public function isAlpha() |
|
| 769 | |||
| 770 | /** |
||
| 771 | * Returns true if the string contains only alphabetic and numeric chars, |
||
| 772 | * false otherwise. |
||
| 773 | * |
||
| 774 | * @return bool Whether or not $str contains only alphanumeric chars |
||
| 775 | */ |
||
| 776 | 13 | public function isAlphanumeric() |
|
| 780 | |||
| 781 | /** |
||
| 782 | * Returns true if the string contains only whitespace chars, false |
||
| 783 | * otherwise. |
||
| 784 | * |
||
| 785 | * @return bool Whether or not $str contains only whitespace characters |
||
| 786 | */ |
||
| 787 | 15 | public function isBlank() |
|
| 791 | |||
| 792 | /** |
||
| 793 | * Returns true if the string contains only hexadecimal chars, false |
||
| 794 | * otherwise. |
||
| 795 | * |
||
| 796 | * @return bool Whether or not $str contains only hexadecimal chars |
||
| 797 | */ |
||
| 798 | 13 | public function isHexadecimal() |
|
| 802 | |||
| 803 | /** |
||
| 804 | * Returns true if the string contains HTML-Tags, false otherwise. |
||
| 805 | * |
||
| 806 | * @return bool Whether or not $str contains HTML-Tags |
||
| 807 | */ |
||
| 808 | public function isHtml() |
||
| 812 | 20 | ||
| 813 | 1 | /** |
|
| 814 | * Returns true if the string is JSON, false otherwise. Unlike json_decode |
||
| 815 | * in PHP 5.x, this method is consistent with PHP 7 and other JSON parsers, |
||
| 816 | 19 | * in that an empty string is not considered valid JSON. |
|
| 817 | * |
||
| 818 | 19 | * @return bool Whether or not $str is JSON |
|
| 819 | 11 | */ |
|
| 820 | public function isJson() |
||
| 834 | 3 | ||
| 835 | /** |
||
| 836 | 5 | * Returns true if the string contains only lower case chars, false |
|
| 837 | * otherwise. |
||
| 838 | * |
||
| 839 | * @return bool Whether or not $str contains only lower case characters |
||
| 840 | */ |
||
| 841 | public function isLowerCase() |
||
| 849 | |||
| 850 | /** |
||
| 851 | * Returns true if the string is serialized, false otherwise. |
||
| 852 | * |
||
| 853 | 6 | * @return bool Whether or not $str is serialized |
|
| 854 | */ |
||
| 855 | 6 | public function isSerialized() |
|
| 872 | |||
| 873 | /** |
||
| 874 | * Returns true if the string contains only lower case chars, false |
||
| 875 | * otherwise. |
||
| 876 | * |
||
| 877 | * @return bool Whether or not $str contains only lower case characters |
||
| 878 | */ |
||
| 879 | public function isUpperCase() |
||
| 883 | 12 | ||
| 884 | /** |
||
| 885 | 12 | * Returns the last $n characters of the string. |
|
| 886 | 4 | * |
|
| 887 | * @param int $n Number of characters to retrieve from the end |
||
| 888 | 8 | * |
|
| 889 | * @return Stringy Object with its $str being the last $n chars |
||
| 890 | */ |
||
| 891 | 4 | View Code Duplication | public function last($n) |
| 903 | |||
| 904 | /** |
||
| 905 | 15 | * Splits on newlines and carriage returns, returning an array of Stringy |
|
| 906 | 15 | * objects corresponding to the lines in the string. |
|
| 907 | * |
||
| 908 | * @return Stringy[] An array of Stringy objects |
||
| 909 | 15 | */ |
|
| 910 | public function lines() |
||
| 921 | 10 | ||
| 922 | 10 | /** |
|
| 923 | * Returns the longest common prefix between the string and $otherStr. |
||
| 924 | 10 | * |
|
| 925 | 10 | * @param string $otherStr Second string for comparison |
|
| 926 | 8 | * |
|
| 927 | * @return Stringy Object with its $str being the longest common prefix |
||
| 928 | 8 | */ |
|
| 929 | 6 | public function longestCommonPrefix($otherStr) |
|
| 947 | 10 | ||
| 948 | 10 | /** |
|
| 949 | * Returns the longest common suffix between the string and $otherStr. |
||
| 950 | 10 | * |
|
| 951 | 10 | * @param string $otherStr Second string for comparison |
|
| 952 | 8 | * |
|
| 953 | * @return Stringy Object with its $str being the longest common suffix |
||
| 954 | 8 | */ |
|
| 955 | 6 | public function longestCommonSuffix($otherStr) |
|
| 973 | |||
| 974 | /** |
||
| 975 | * Returns the longest common substring between the string and $otherStr. |
||
| 976 | 10 | * In the case of ties, it returns that which occurs first. |
|
| 977 | 10 | * |
|
| 978 | 10 | * @param string $otherStr Second string for comparison |
|
| 979 | 10 | * |
|
| 980 | * @return Stringy Object with its $str being the longest common substring |
||
| 981 | */ |
||
| 982 | 10 | public function longestCommonSubstring($otherStr) |
|
| 1026 | 6 | ||
| 1027 | /** |
||
| 1028 | * Returns whether or not a character exists at an index. Offsets may be |
||
| 1029 | 6 | * negative to count from the last character in the string. Implements |
|
| 1030 | 6 | * part of the ArrayAccess interface. |
|
| 1031 | * |
||
| 1032 | 6 | * @param mixed $offset The index to check |
|
| 1033 | 3 | * |
|
| 1034 | * @return boolean Whether or not the index exists |
||
| 1035 | */ |
||
| 1036 | 3 | public function offsetExists($offset) |
|
| 1048 | |||
| 1049 | /** |
||
| 1050 | * Returns the character at the given index. Offsets may be negative to |
||
| 1051 | 2 | * count from the last character in the string. Implements part of the |
|
| 1052 | * ArrayAccess interface, and throws an OutOfBoundsException if the index |
||
| 1053 | * does not exist. |
||
| 1054 | 2 | * |
|
| 1055 | 2 | * @param mixed $offset The index from which to retrieve the char |
|
| 1056 | * |
||
| 1057 | * @return string The character at the specified index |
||
| 1058 | 2 | * @throws \OutOfBoundsException If the positive or negative offset does |
|
| 1059 | * not exist |
||
| 1060 | 2 | */ |
|
| 1061 | public function offsetGet($offset) |
||
| 1077 | 1 | ||
| 1078 | /** |
||
| 1079 | * Implements part of the ArrayAccess interface, but throws an exception |
||
| 1080 | 1 | * when called. This maintains the immutability of Stringy objects. |
|
| 1081 | * |
||
| 1082 | * @param mixed $offset The index of the character |
||
| 1083 | * @param mixed $value Value to set |
||
| 1084 | * |
||
| 1085 | * @throws \Exception When called |
||
| 1086 | */ |
||
| 1087 | public function offsetSet($offset, $value) |
||
| 1092 | |||
| 1093 | /** |
||
| 1094 | 1 | * Implements part of the ArrayAccess interface, but throws an exception |
|
| 1095 | * when called. This maintains the immutability of Stringy objects. |
||
| 1096 | * |
||
| 1097 | * @param mixed $offset The index of the character |
||
| 1098 | * |
||
| 1099 | * @throws \Exception When called |
||
| 1100 | */ |
||
| 1101 | public function offsetUnset($offset) |
||
| 1106 | |||
| 1107 | /** |
||
| 1108 | * Pads the string to a given length with $padStr. If length is less than |
||
| 1109 | * or equal to the length of the string, no padding takes places. The |
||
| 1110 | * default string used for padding is a space, and the default type (one of |
||
| 1111 | 13 | * 'left', 'right', 'both') is 'right'. Throws an InvalidArgumentException |
|
| 1112 | * if $padType isn't one of those 3 values. |
||
| 1113 | 13 | * |
|
| 1114 | 1 | * @param int $length Desired string length after padding |
|
| 1115 | 1 | * @param string $padStr String used to pad, defaults to space |
|
| 1116 | * @param string $padType One of 'left', 'right', 'both' |
||
| 1117 | * |
||
| 1118 | * @return Stringy Object with a padded $str |
||
| 1119 | * @throws \InvalidArgumentException If $padType isn't one of 'right', 'left' or 'both' |
||
| 1120 | 12 | */ |
|
| 1121 | 3 | public function pad($length, $padStr = ' ', $padType = 'right') |
|
| 1138 | 10 | ||
| 1139 | /** |
||
| 1140 | 10 | * Returns a new string of a given length such that the beginning of the |
|
| 1141 | * string is padded. Alias for pad() with a $padType of 'left'. |
||
| 1142 | * |
||
| 1143 | * @param int $length Desired string length after padding |
||
| 1144 | * @param string $padStr String used to pad, defaults to space |
||
| 1145 | * |
||
| 1146 | * @return Stringy String with left padding |
||
| 1147 | */ |
||
| 1148 | public function padLeft($length, $padStr = ' ') |
||
| 1152 | |||
| 1153 | 37 | /** |
|
| 1154 | * Adds the specified amount of left and right padding to the given string. |
||
| 1155 | 37 | * The default character used is a space. |
|
| 1156 | * |
||
| 1157 | 37 | * @param int $left Length of left padding |
|
| 1158 | * @param int $right Length of right padding |
||
| 1159 | 37 | * @param string $padStr String used to pad |
|
| 1160 | 37 | * |
|
| 1161 | * @return Stringy String with padding applied |
||
| 1162 | 37 | */ |
|
| 1163 | 3 | private function applyPadding($left = 0, $right = 0, $padStr = ' ') |
|
| 1200 | 13 | ||
| 1201 | /** |
||
| 1202 | 13 | * Returns a new string of a given length such that the end of the string |
|
| 1203 | * is padded. Alias for pad() with a $padType of 'right'. |
||
| 1204 | * |
||
| 1205 | * @param int $length Desired string length after padding |
||
| 1206 | * @param string $padStr String used to pad, defaults to space |
||
| 1207 | * |
||
| 1208 | * @return Stringy String with right padding |
||
| 1209 | */ |
||
| 1210 | public function padRight($length, $padStr = ' ') |
||
| 1214 | 14 | ||
| 1215 | /** |
||
| 1216 | 14 | * Returns a new string of a given length such that both sides of the |
|
| 1217 | * string are padded. Alias for pad() with a $padType of 'both'. |
||
| 1218 | 14 | * |
|
| 1219 | * @param int $length Desired string length after padding |
||
| 1220 | * @param string $padStr String used to pad, defaults to space |
||
| 1221 | * |
||
| 1222 | * @return Stringy String with padding applied |
||
| 1223 | */ |
||
| 1224 | public function padBoth($length, $padStr = ' ') |
||
| 1230 | 2 | ||
| 1231 | /** |
||
| 1232 | * Returns a new string starting with $string. |
||
| 1233 | * |
||
| 1234 | * @param string $string The string to append |
||
| 1235 | * |
||
| 1236 | * @return Stringy Object with appended $string |
||
| 1237 | */ |
||
| 1238 | public function prepend($string) |
||
| 1242 | 12 | ||
| 1243 | /** |
||
| 1244 | 12 | * Returns a new string with the prefix $substring removed, if present. |
|
| 1245 | 8 | * |
|
| 1246 | * @param string $substring The prefix to remove |
||
| 1247 | 8 | * |
|
| 1248 | * @return Stringy Object having a $str without the prefix $substring |
||
| 1249 | */ |
||
| 1250 | 4 | View Code Duplication | public function removeLeft($substring) |
| 1262 | 12 | ||
| 1263 | /** |
||
| 1264 | 12 | * Returns a new string with the suffix $substring removed, if present. |
|
| 1265 | 8 | * |
|
| 1266 | * @param string $substring The suffix to remove |
||
| 1267 | 8 | * |
|
| 1268 | * @return Stringy Object having a $str without the suffix $substring |
||
| 1269 | */ |
||
| 1270 | 4 | View Code Duplication | public function removeRight($substring) |
| 1282 | 7 | ||
| 1283 | /** |
||
| 1284 | 7 | * Returns a repeated string given a multiplier. |
|
| 1285 | * |
||
| 1286 | * @param int $multiplier The number of times to repeat the string |
||
| 1287 | * |
||
| 1288 | * @return Stringy Object with a repeated str |
||
| 1289 | */ |
||
| 1290 | public function repeat($multiplier) |
||
| 1296 | 28 | ||
| 1297 | /** |
||
| 1298 | 28 | * Replaces all occurrences of $search in $str by $replacement. |
|
| 1299 | 21 | * |
|
| 1300 | * @param string $search The needle to search for |
||
| 1301 | 7 | * @param string $replacement The string to replace with |
|
| 1302 | * @param bool $caseSensitive Whether or not to enforce case-sensitivity |
||
| 1303 | * |
||
| 1304 | 28 | * @return Stringy Object with the resulting $str after the replacements |
|
| 1305 | */ |
||
| 1306 | View Code Duplication | public function replace($search, $replacement, $caseSensitive = true) |
|
| 1316 | 30 | ||
| 1317 | /** |
||
| 1318 | 30 | * Replaces all occurrences of $search in $str by $replacement. |
|
| 1319 | 23 | * |
|
| 1320 | * @param array $search The elements to search for |
||
| 1321 | 7 | * @param string|array $replacement The string to replace with |
|
| 1322 | * @param bool $caseSensitive Whether or not to enforce case-sensitivity |
||
| 1323 | * |
||
| 1324 | 30 | * @return Stringy Object with the resulting $str after the replacements |
|
| 1325 | */ |
||
| 1326 | View Code Duplication | public function replaceAll(array $search, $replacement, $caseSensitive = true) |
|
| 1336 | |||
| 1337 | 16 | /** |
|
| 1338 | * Replaces all occurrences of $search from the beginning of string with $replacement |
||
| 1339 | 16 | * |
|
| 1340 | * @param string $search |
||
| 1341 | * @param string $replacement |
||
| 1342 | * |
||
| 1343 | * @return Stringy Object with the resulting $str after the replacements |
||
| 1344 | */ |
||
| 1345 | public function replaceBeginning($search, $replacement) |
||
| 1351 | |||
| 1352 | 16 | /** |
|
| 1353 | * Replaces all occurrences of $search from the ending of string with $replacement |
||
| 1354 | 16 | * |
|
| 1355 | * @param string $search |
||
| 1356 | * @param string $replacement |
||
| 1357 | * |
||
| 1358 | * @return Stringy Object with the resulting $str after the replacements |
||
| 1359 | */ |
||
| 1360 | public function replaceEnding($search, $replacement) |
||
| 1366 | 5 | ||
| 1367 | /** |
||
| 1368 | * Returns a reversed string. A multibyte version of strrev(). |
||
| 1369 | * |
||
| 1370 | * @return Stringy Object with a reversed $str |
||
| 1371 | */ |
||
| 1372 | public function reverse() |
||
| 1378 | |||
| 1379 | /** |
||
| 1380 | 22 | * Truncates the string to a given length, while ensuring that it does not |
|
| 1381 | * split words. If $substring is provided, and truncating occurs, the |
||
| 1382 | 22 | * string is further truncated so that the substring may be appended without |
|
| 1383 | 22 | * exceeding the desired length. |
|
| 1384 | 4 | * |
|
| 1385 | * @param int $length Desired length of the truncated string |
||
| 1386 | * @param string $substring The substring to append if it can fit |
||
| 1387 | * |
||
| 1388 | 18 | * @return Stringy Object with the resulting $str after truncating |
|
| 1389 | 18 | */ |
|
| 1390 | 18 | public function safeTruncate($length, $substring = '') |
|
| 1415 | |||
| 1416 | 3 | /** |
|
| 1417 | * A multibyte string shuffle function. It returns a string with its |
||
| 1418 | * characters in random order. |
||
| 1419 | * |
||
| 1420 | * @return Stringy Object with a shuffled $str |
||
| 1421 | */ |
||
| 1422 | public function shuffle() |
||
| 1428 | |||
| 1429 | /** |
||
| 1430 | * Converts the string into an URL slug. This includes replacing non-ASCII |
||
| 1431 | * characters with their closest ASCII equivalents, removing remaining |
||
| 1432 | 15 | * non-ASCII and non-alphanumeric characters, and replacing whitespace with |
|
| 1433 | * $replacement. The replacement defaults to a single dash, and the string |
||
| 1434 | 15 | * is also converted to lowercase. |
|
| 1435 | * |
||
| 1436 | 15 | * @param string $replacement The string used to replace whitespace |
|
| 1437 | * @param string $language The language for the url |
||
| 1438 | * @param bool $strToLower string to lower |
||
| 1439 | * |
||
| 1440 | * @return Stringy Object whose $str has been converted to an URL slug |
||
| 1441 | */ |
||
| 1442 | public function slugify($replacement = '-', $language = 'de', $strToLower = true) |
||
| 1448 | |||
| 1449 | /** |
||
| 1450 | * Remove css media-queries. |
||
| 1451 | * |
||
| 1452 | * @return Stringy |
||
| 1453 | */ |
||
| 1454 | public function stripeCssMediaQueries() |
||
| 1459 | 1 | ||
| 1460 | /** |
||
| 1461 | 1 | * Remove empty html-tag. |
|
| 1462 | * |
||
| 1463 | * e.g.: <tag></tag> |
||
| 1464 | * |
||
| 1465 | * @return Stringy |
||
| 1466 | */ |
||
| 1467 | public function stripeEmptyHtmlTags() |
||
| 1473 | |||
| 1474 | /** |
||
| 1475 | * Converts the string into an valid UTF-8 string. |
||
| 1476 | * |
||
| 1477 | * @return Stringy |
||
| 1478 | */ |
||
| 1479 | 6 | public function utf8ify() |
|
| 1483 | 6 | ||
| 1484 | 6 | /** |
|
| 1485 | * escape html |
||
| 1486 | * |
||
| 1487 | 6 | * @return Stringy |
|
| 1488 | */ |
||
| 1489 | public function escape() |
||
| 1499 | 6 | ||
| 1500 | 1 | /** |
|
| 1501 | * remove xss from html |
||
| 1502 | * |
||
| 1503 | 6 | * @return Stringy |
|
| 1504 | */ |
||
| 1505 | 6 | public function removeXss() |
|
| 1517 | 6 | ||
| 1518 | /** |
||
| 1519 | 6 | * remove html-break [br | \r\n | \r | \n | ...] |
|
| 1520 | * |
||
| 1521 | * @param string $replacement |
||
| 1522 | * |
||
| 1523 | * @return Stringy |
||
| 1524 | */ |
||
| 1525 | public function removeHtmlBreak($replacement = '') |
||
| 1531 | 6 | ||
| 1532 | /** |
||
| 1533 | 6 | * remove html |
|
| 1534 | * |
||
| 1535 | * @param $allowableTags |
||
| 1536 | * |
||
| 1537 | * @return Stringy |
||
| 1538 | */ |
||
| 1539 | public function removeHtml($allowableTags = null) |
||
| 1545 | |||
| 1546 | /** |
||
| 1547 | 18 | * Returns the substring beginning at $start, and up to, but not including |
|
| 1548 | * the index specified by $end. If $end is omitted, the function extracts |
||
| 1549 | 18 | * the remaining string. If $end is negative, it is computed from the end |
|
| 1550 | 4 | * of the string. |
|
| 1551 | 14 | * |
|
| 1552 | 4 | * @param int $start Initial index from which to begin extraction |
|
| 1553 | 10 | * @param int $end Optional index at which to end extraction |
|
| 1554 | 2 | * |
|
| 1555 | * @return Stringy Object with its $str being the extracted substring |
||
| 1556 | 8 | */ |
|
| 1557 | public function slice($start, $end = null) |
||
| 1573 | |||
| 1574 | 19 | /** |
|
| 1575 | * Splits the string with the provided regular expression, returning an |
||
| 1576 | 19 | * array of Stringy objects. An optional integer $limit will truncate the |
|
| 1577 | 2 | * results. |
|
| 1578 | * |
||
| 1579 | * @param string $pattern The regex with which to split the string |
||
| 1580 | * @param int $limit Optional maximum number of results to return |
||
| 1581 | * |
||
| 1582 | 17 | * @return Stringy[] An array of Stringy objects |
|
| 1583 | 1 | */ |
|
| 1584 | public function split($pattern, $limit = null) |
||
| 1618 | |||
| 1619 | 5 | /** |
|
| 1620 | * Surrounds $str with the given substring. |
||
| 1621 | 5 | * |
|
| 1622 | * @param string $substring The substring to add to both sides |
||
| 1623 | * |
||
| 1624 | * @return Stringy Object whose $str had the substring both prepended and |
||
| 1625 | * appended |
||
| 1626 | */ |
||
| 1627 | public function surround($substring) |
||
| 1633 | 5 | ||
| 1634 | /** |
||
| 1635 | 5 | * Returns a case swapped version of the string. |
|
| 1636 | * |
||
| 1637 | * @return Stringy Object whose $str has each character's case swapped |
||
| 1638 | */ |
||
| 1639 | public function swapCase() |
||
| 1647 | 4 | ||
| 1648 | /** |
||
| 1649 | 4 | * Returns a string with smart quotes, ellipsis characters, and dashes from |
|
| 1650 | * Windows-1252 (commonly used in Word documents) replaced by their ASCII |
||
| 1651 | * equivalents. |
||
| 1652 | * |
||
| 1653 | * @return Stringy Object whose $str has those characters removed |
||
| 1654 | */ |
||
| 1655 | public function tidy() |
||
| 1661 | 5 | ||
| 1662 | /** |
||
| 1663 | 5 | * Returns a trimmed string with the first letter of each word capitalized. |
|
| 1664 | 5 | * Also accepts an array, $ignore, allowing you to list words not to be |
|
| 1665 | * capitalized. |
||
| 1666 | 5 | * |
|
| 1667 | 5 | * @param array $ignore An array of words not to capitalize |
|
| 1668 | * |
||
| 1669 | 5 | * @return Stringy Object with a titleized $str |
|
| 1670 | 2 | */ |
|
| 1671 | public function titleize($ignore = null) |
||
| 1692 | |||
| 1693 | 27 | /** |
|
| 1694 | * Converts all characters in the string to lowercase. An alias for PHP's |
||
| 1695 | * UTF8::strtolower(). |
||
| 1696 | * |
||
| 1697 | * @return Stringy Object with all characters of $str being lowercase |
||
| 1698 | */ |
||
| 1699 | public function toLowerCase() |
||
| 1705 | |||
| 1706 | /** |
||
| 1707 | * Returns true if the string is base64 encoded, false otherwise. |
||
| 1708 | * |
||
| 1709 | * @return bool Whether or not $str is base64 encoded |
||
| 1710 | */ |
||
| 1711 | public function isBase64() |
||
| 1715 | 16 | ||
| 1716 | /** |
||
| 1717 | 16 | * Returns an ASCII version of the string. A set of non-ASCII characters are |
|
| 1718 | * replaced with their closest ASCII counterparts, and the rest are removed |
||
| 1719 | * unless instructed otherwise. |
||
| 1720 | * |
||
| 1721 | * @return Stringy Object whose $str contains only ASCII characters |
||
| 1722 | */ |
||
| 1723 | public function toAscii() |
||
| 1729 | |||
| 1730 | /** |
||
| 1731 | 15 | * Returns a boolean representation of the given logical string value. |
|
| 1732 | * For example, 'true', '1', 'on' and 'yes' will return true. 'false', '0', |
||
| 1733 | 15 | * 'off', and 'no' will return false. In all instances, case is ignored. |
|
| 1734 | * For other numeric strings, their sign will determine the return value. |
||
| 1735 | 15 | * In addition, blank strings consisting of only whitespace will return |
|
| 1736 | * false. For all other strings, the return value is a result of a |
||
| 1737 | * boolean cast. |
||
| 1738 | * |
||
| 1739 | * @return bool A boolean value for the string |
||
| 1740 | */ |
||
| 1741 | public function toBoolean() |
||
| 1763 | |||
| 1764 | /** |
||
| 1765 | * Return Stringy object as string, but you can also use (string) for automatically casting the object into a string. |
||
| 1766 | * |
||
| 1767 | * @return string |
||
| 1768 | */ |
||
| 1769 | public function toString() |
||
| 1773 | |||
| 1774 | 6 | /** |
|
| 1775 | 6 | * Converts each tab in the string to some number of spaces, as defined by |
|
| 1776 | * $tabLength. By default, each tab is converted to 4 consecutive spaces. |
||
| 1777 | 6 | * |
|
| 1778 | * @param int $tabLength Number of spaces to replace each tab with |
||
| 1779 | * |
||
| 1780 | * @return Stringy Object whose $str has had tabs switched to spaces |
||
| 1781 | */ |
||
| 1782 | View Code Duplication | public function toSpaces($tabLength = 4) |
|
| 1789 | 5 | ||
| 1790 | /** |
||
| 1791 | 5 | * Converts each occurrence of some consecutive number of spaces, as |
|
| 1792 | 5 | * defined by $tabLength, to a tab. By default, each 4 consecutive spaces |
|
| 1793 | * are converted to a tab. |
||
| 1794 | 5 | * |
|
| 1795 | * @param int $tabLength Number of spaces to replace with a tab |
||
| 1796 | * |
||
| 1797 | * @return Stringy Object whose $str has had spaces switched to tabs |
||
| 1798 | */ |
||
| 1799 | View Code Duplication | public function toTabs($tabLength = 4) |
|
| 1806 | |||
| 1807 | 5 | /** |
|
| 1808 | * Converts the first character of each word in the string to uppercase. |
||
| 1809 | * |
||
| 1810 | * @return Stringy Object with all characters of $str being title-cased |
||
| 1811 | */ |
||
| 1812 | public function toTitleCase() |
||
| 1819 | |||
| 1820 | 5 | /** |
|
| 1821 | * Converts all characters in the string to uppercase. An alias for PHP's |
||
| 1822 | * UTF8::strtoupper(). |
||
| 1823 | * |
||
| 1824 | * @return Stringy Object with all characters of $str being uppercase |
||
| 1825 | */ |
||
| 1826 | public function toUpperCase() |
||
| 1832 | 13 | ||
| 1833 | /** |
||
| 1834 | 13 | * Returns a string with whitespace removed from the start of the string. |
|
| 1835 | 11 | * Supports the removal of unicode whitespace. Accepts an optional |
|
| 1836 | * string of characters to strip instead of the defaults. |
||
| 1837 | 2 | * |
|
| 1838 | * @param string $chars Optional string of characters to strip |
||
| 1839 | * |
||
| 1840 | 13 | * @return Stringy Object with a trimmed $str |
|
| 1841 | */ |
||
| 1842 | View Code Duplication | public function trimLeft($chars = null) |
|
| 1852 | 13 | ||
| 1853 | /** |
||
| 1854 | 13 | * Returns a string with whitespace removed from the end of the string. |
|
| 1855 | 11 | * Supports the removal of unicode whitespace. Accepts an optional |
|
| 1856 | * string of characters to strip instead of the defaults. |
||
| 1857 | 2 | * |
|
| 1858 | * @param string $chars Optional string of characters to strip |
||
| 1859 | * |
||
| 1860 | 13 | * @return Stringy Object with a trimmed $str |
|
| 1861 | */ |
||
| 1862 | View Code Duplication | public function trimRight($chars = null) |
|
| 1872 | |||
| 1873 | 22 | /** |
|
| 1874 | * Truncates the string to a given length. If $substring is provided, and |
||
| 1875 | 22 | * truncating occurs, the string is further truncated so that the substring |
|
| 1876 | 22 | * may be appended without exceeding the desired length. |
|
| 1877 | 4 | * |
|
| 1878 | * @param int $length Desired length of the truncated string |
||
| 1879 | * @param string $substring The substring to append if it can fit |
||
| 1880 | * |
||
| 1881 | 18 | * @return Stringy Object with the resulting $str after truncating |
|
| 1882 | 18 | */ |
|
| 1883 | View Code Duplication | public function truncate($length, $substring = '') |
|
| 1899 | |||
| 1900 | 16 | /** |
|
| 1901 | * Returns a lowercase and trimmed string separated by underscores. |
||
| 1902 | * Underscores are inserted before uppercase characters (with the exception |
||
| 1903 | * of the first character of the string), and in place of spaces as well as |
||
| 1904 | * dashes. |
||
| 1905 | * |
||
| 1906 | * @return Stringy Object with an underscored $str |
||
| 1907 | */ |
||
| 1908 | public function underscored() |
||
| 1912 | 13 | ||
| 1913 | /** |
||
| 1914 | * Returns an UpperCamelCase version of the supplied string. It trims |
||
| 1915 | * surrounding spaces, capitalizes letters following digits, spaces, dashes |
||
| 1916 | * and underscores, and removes spaces, dashes, underscores. |
||
| 1917 | * |
||
| 1918 | * @return Stringy Object with $str in UpperCamelCase |
||
| 1919 | */ |
||
| 1920 | public function upperCamelize() |
||
| 1924 | 32 | ||
| 1925 | 32 | /** |
|
| 1926 | 32 | * Returns a camelCase version of the string. Trims surrounding spaces, |
|
| 1927 | * capitalizes letters following digits, spaces, dashes and underscores, |
||
| 1928 | 32 | * and removes spaces, dashes, as well as underscores. |
|
| 1929 | 32 | * |
|
| 1930 | * @return Stringy Object with $str in camelCase |
||
| 1931 | 27 | */ |
|
| 1932 | 27 | public function camelize() |
|
| 1960 | 20 | ||
| 1961 | 20 | /** |
|
| 1962 | * Convert a string to e.g.: "snake_case" |
||
| 1963 | 20 | * |
|
| 1964 | 20 | * @return Stringy Object with $str in snake_case |
|
| 1965 | 20 | */ |
|
| 1966 | 8 | public function snakeize() |
|
| 2008 | 37 | ||
| 2009 | 37 | /** |
|
| 2010 | * Converts the first character of the string to lower case. |
||
| 2011 | * |
||
| 2012 | 37 | * @return Stringy Object with the first character of $str being lower case |
|
| 2013 | */ |
||
| 2014 | 37 | View Code Duplication | public function lowerCaseFirst() |
| 2026 | |||
| 2027 | 4 | /** |
|
| 2028 | * Shorten the string after $length, but also after the next word. |
||
| 2029 | 4 | * |
|
| 2030 | * @param int $length |
||
| 2031 | * @param string $strAddOn |
||
| 2032 | * |
||
| 2033 | * @return Stringy |
||
| 2034 | */ |
||
| 2035 | public function shortenAfterWord($length, $strAddOn = '...') |
||
| 2041 | 1 | ||
| 2042 | /** |
||
| 2043 | 1 | * Line-Wrap the string after $limit, but also after the next word. |
|
| 2044 | 1 | * |
|
| 2045 | 1 | * @param int $limit |
|
| 2046 | 1 | * |
|
| 2047 | * @return Stringy |
||
| 2048 | */ |
||
| 2049 | 1 | public function lineWrapAfterWord($limit) |
|
| 2061 | } |
||
| 2062 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: