From 2bd4be60bbdfef55e2712adb478a621d13493c5a Mon Sep 17 00:00:00 2001 From: vlakoff Date: Tue, 3 Feb 2015 11:10:27 +0100 Subject: [PATCH 1/2] Uniformization in docblocks --- src/StaticStringy.php | 4 ++-- src/Stringy.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/StaticStringy.php b/src/StaticStringy.php index 3e904a0..84c54c2 100644 --- a/src/StaticStringy.php +++ b/src/StaticStringy.php @@ -169,8 +169,8 @@ class StaticStringy * replaced with their closest ASCII counterparts, and the rest are removed * unless instructed otherwise. * - * @param string $str A string with non-ASCII characters - * @param bool $removeUnsupported Whether to remove or not the unsupported characters + * @param string $str A string with non-ASCII characters + * @param bool $removeUnsupported Whether or not to remove the unsupported characters * @return string A string containing only ASCII characters */ public static function toAscii($str, $removeUnsupported = true) diff --git a/src/Stringy.php b/src/Stringy.php index d901c3a..5896c2b 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -422,7 +422,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess * replaced with their closest ASCII counterparts, and the rest are removed * unless instructed otherwise. * - * @param bool $removeUnsupported Whether to remove or not the unsupported characters + * @param bool $removeUnsupported Whether or not to remove the unsupported characters * @return Stringy Object whose $str contains only ASCII characters */ public function toAscii($removeUnsupported = true) From 61b986a3e64c15a24b95466928f5d8bc4075cfb6 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Tue, 3 Feb 2015 11:13:58 +0100 Subject: [PATCH 2/2] Code tweaking Prettier, one less instanciation. --- src/Stringy.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Stringy.php b/src/Stringy.php index 5896c2b..3ab573c 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -235,14 +235,14 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess public function camelize() { $encoding = $this->encoding; - $stringy = static::create($this->str, $this->encoding); + $stringy = $this->trim()->lowerCaseFirst(); $camelCase = preg_replace_callback( '/[-_\s]+(.)?/u', function ($match) use ($encoding) { return $match[1] ? mb_strtoupper($match[1], $encoding) : ''; }, - $stringy->trim()->lowerCaseFirst()->str + $stringy->str ); $stringy->str = preg_replace_callback( @@ -784,11 +784,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess */ public function slugify($replacement = '-') { - $stringy = static::create($this->str, $this->encoding); + $stringy = $this->toAscii(); $quotedReplacement = preg_quote($replacement); $pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u"; - $stringy->str = preg_replace($pattern, '', $stringy->toAscii()); + $stringy->str = preg_replace($pattern, '', $stringy); return $stringy->toLowerCase()->applyDelimiter($replacement) ->removeLeft($replacement)->removeRight($replacement);