1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-12 00:04:11 +02:00

Merge pull request #62 from vlakoff/static

Replace self::create() with static::create()
This commit is contained in:
Daniel St. Jules
2015-01-05 14:06:06 -08:00

View File

@@ -206,7 +206,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$str = mb_strtoupper($first, $this->encoding) . $rest; $str = mb_strtoupper($first, $this->encoding) . $rest;
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -222,7 +222,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$str = mb_strtolower($first, $this->encoding) . $rest; $str = mb_strtolower($first, $this->encoding) . $rest;
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -235,7 +235,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
public function camelize() public function camelize()
{ {
$encoding = $this->encoding; $encoding = $this->encoding;
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
$camelCase = preg_replace_callback( $camelCase = preg_replace_callback(
'/[-_\s]+(.)?/u', '/[-_\s]+(.)?/u',
@@ -311,7 +311,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
mb_regex_encoding($regexEncoding); mb_regex_encoding($regexEncoding);
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -321,7 +321,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function swapCase() public function swapCase()
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
$encoding = $stringy->encoding; $encoding = $stringy->encoding;
$stringy->str = preg_replace_callback( $stringy->str = preg_replace_callback(
@@ -378,7 +378,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{ {
$str = str_replace(array('_id', '_'), array('', ' '), $this->str); $str = str_replace(array('_id', '_'), array('', ' '), $this->str);
return self::create($str, $this->encoding)->trim()->upperCaseFirst(); return static::create($str, $this->encoding)->trim()->upperCaseFirst();
} }
/** /**
@@ -402,7 +402,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
'-', '-',
), $this->str); ), $this->str);
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -517,7 +517,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$str = preg_replace('/[^\x20-\x7E]/u', '', $str); $str = preg_replace('/[^\x20-\x7E]/u', '', $str);
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -604,7 +604,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
private function applyPadding($left = 0, $right = 0, $padStr = ' ') private function applyPadding($left = 0, $right = 0, $padStr = ' ')
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
$length = mb_strlen($padStr, $stringy->encoding); $length = mb_strlen($padStr, $stringy->encoding);
$strLength = $stringy->length(); $strLength = $stringy->length();
@@ -684,7 +684,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$spaces = str_repeat(' ', $tabLength); $spaces = str_repeat(' ', $tabLength);
$str = str_replace("\t", $spaces, $this->str); $str = str_replace("\t", $spaces, $this->str);
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -700,7 +700,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$spaces = str_repeat(' ', $tabLength); $spaces = str_repeat(' ', $tabLength);
$str = str_replace($spaces, "\t", $this->str); $str = str_replace($spaces, "\t", $this->str);
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -712,7 +712,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{ {
$str = mb_convert_case($this->str, MB_CASE_TITLE, $this->encoding); $str = mb_convert_case($this->str, MB_CASE_TITLE, $this->encoding);
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -725,7 +725,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{ {
$str = mb_strtolower($this->str, $this->encoding); $str = mb_strtolower($this->str, $this->encoding);
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -738,7 +738,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{ {
$str = mb_strtoupper($this->str, $this->encoding); $str = mb_strtoupper($this->str, $this->encoding);
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -753,7 +753,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function slugify($replacement = '-') public function slugify($replacement = '-')
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
$quotedReplacement = preg_quote($replacement); $quotedReplacement = preg_quote($replacement);
$pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u"; $pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u";
@@ -841,7 +841,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{ {
$str = implode('', array($substring, $this->str, $substring)); $str = implode('', array($substring, $this->str, $substring));
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -853,7 +853,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function insert($substring, $index) public function insert($substring, $index)
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
if ($index > $stringy->length()) { if ($index > $stringy->length()) {
return $stringy; return $stringy;
} }
@@ -878,7 +878,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function truncate($length, $substring = '') public function truncate($length, $substring = '')
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
if ($length >= $stringy->length()) { if ($length >= $stringy->length()) {
return $stringy; return $stringy;
} }
@@ -905,7 +905,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function safeTruncate($length, $substring = '') public function safeTruncate($length, $substring = '')
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
if ($length >= $stringy->length()) { if ($length >= $stringy->length()) {
return $stringy; return $stringy;
} }
@@ -944,7 +944,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$reversed .= mb_substr($this->str, $i, 1, $this->encoding); $reversed .= mb_substr($this->str, $i, 1, $this->encoding);
} }
return self::create($reversed, $this->encoding); return static::create($reversed, $this->encoding);
} }
/** /**
@@ -963,7 +963,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$shuffledStr .= mb_substr($this->str, $i, 1, $this->encoding); $shuffledStr .= mb_substr($this->str, $i, 1, $this->encoding);
} }
return self::create($shuffledStr, $this->encoding); return static::create($shuffledStr, $this->encoding);
} }
/** /**
@@ -973,7 +973,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function trim() public function trim()
{ {
return self::create(trim($this->str), $this->encoding); return static::create(trim($this->str), $this->encoding);
} }
/** /**
@@ -998,7 +998,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
} }
} }
return self::create($longestCommonPrefix, $encoding); return static::create($longestCommonPrefix, $encoding);
} }
/** /**
@@ -1023,7 +1023,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
} }
} }
return self::create($longestCommonSuffix, $encoding); return static::create($longestCommonSuffix, $encoding);
} }
/** /**
@@ -1038,7 +1038,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
// Uses dynamic programming to solve // Uses dynamic programming to solve
// http://en.wikipedia.org/wiki/Longest_common_substring_problem // http://en.wikipedia.org/wiki/Longest_common_substring_problem
$encoding = $this->encoding; $encoding = $this->encoding;
$stringy = self::create($this->str, $encoding); $stringy = static::create($this->str, $encoding);
$strLength = $stringy->length(); $strLength = $stringy->length();
$otherLength = mb_strlen($otherStr, $encoding); $otherLength = mb_strlen($otherStr, $encoding);
@@ -1098,7 +1098,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$length = $length === null ? $this->length() : $length; $length = $length === null ? $this->length() : $length;
$str = mb_substr($this->str, $start, $length, $this->encoding); $str = mb_substr($this->str, $start, $length, $this->encoding);
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
/** /**
@@ -1120,7 +1120,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function first($n) public function first($n)
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
if ($n < 0) { if ($n < 0) {
$stringy->str = ''; $stringy->str = '';
@@ -1139,7 +1139,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function last($n) public function last($n)
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
if ($n <= 0) { if ($n <= 0) {
$stringy->str = ''; $stringy->str = '';
@@ -1159,7 +1159,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function ensureLeft($substring) public function ensureLeft($substring)
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
if (!$stringy->startsWith($substring)) { if (!$stringy->startsWith($substring)) {
$stringy->str = $substring . $stringy->str; $stringy->str = $substring . $stringy->str;
@@ -1177,7 +1177,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function ensureRight($substring) public function ensureRight($substring)
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
if (!$stringy->endsWith($substring)) { if (!$stringy->endsWith($substring)) {
$stringy->str .= $substring; $stringy->str .= $substring;
@@ -1194,7 +1194,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function removeLeft($substring) public function removeLeft($substring)
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
if ($stringy->startsWith($substring)) { if ($stringy->startsWith($substring)) {
$substringLength = mb_strlen($substring, $stringy->encoding); $substringLength = mb_strlen($substring, $stringy->encoding);
@@ -1212,7 +1212,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function removeRight($substring) public function removeRight($substring)
{ {
$stringy = self::create($this->str, $this->encoding); $stringy = static::create($this->str, $this->encoding);
if ($stringy->endsWith($substring)) { if ($stringy->endsWith($substring)) {
$substringLength = mb_strlen($substring, $stringy->encoding); $substringLength = mb_strlen($substring, $stringy->encoding);
@@ -1379,6 +1379,6 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$str = mb_ereg_replace($pattern, $replacement, $this->str, $options); $str = mb_ereg_replace($pattern, $replacement, $this->str, $options);
mb_regex_encoding($regexEncoding); mb_regex_encoding($regexEncoding);
return self::create($str, $this->encoding); return static::create($str, $this->encoding);
} }
} }