1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-11 15:54:04 +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;
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;
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()
{
$encoding = $this->encoding;
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
$camelCase = preg_replace_callback(
'/[-_\s]+(.)?/u',
@@ -311,7 +311,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
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()
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
$encoding = $stringy->encoding;
$stringy->str = preg_replace_callback(
@@ -378,7 +378,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{
$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);
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);
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 = ' ')
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
$length = mb_strlen($padStr, $stringy->encoding);
$strLength = $stringy->length();
@@ -684,7 +684,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$spaces = str_repeat(' ', $tabLength);
$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);
$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);
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);
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);
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 = '-')
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
$quotedReplacement = preg_quote($replacement);
$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));
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)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($index > $stringy->length()) {
return $stringy;
}
@@ -878,7 +878,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function truncate($length, $substring = '')
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($length >= $stringy->length()) {
return $stringy;
}
@@ -905,7 +905,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function safeTruncate($length, $substring = '')
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($length >= $stringy->length()) {
return $stringy;
}
@@ -944,7 +944,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$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);
}
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()
{
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
// http://en.wikipedia.org/wiki/Longest_common_substring_problem
$encoding = $this->encoding;
$stringy = self::create($this->str, $encoding);
$stringy = static::create($this->str, $encoding);
$strLength = $stringy->length();
$otherLength = mb_strlen($otherStr, $encoding);
@@ -1098,7 +1098,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$length = $length === null ? $this->length() : $length;
$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)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($n < 0) {
$stringy->str = '';
@@ -1139,7 +1139,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function last($n)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($n <= 0) {
$stringy->str = '';
@@ -1159,7 +1159,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function ensureLeft($substring)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if (!$stringy->startsWith($substring)) {
$stringy->str = $substring . $stringy->str;
@@ -1177,7 +1177,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function ensureRight($substring)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if (!$stringy->endsWith($substring)) {
$stringy->str .= $substring;
@@ -1194,7 +1194,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function removeLeft($substring)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($stringy->startsWith($substring)) {
$substringLength = mb_strlen($substring, $stringy->encoding);
@@ -1212,7 +1212,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function removeRight($substring)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($stringy->endsWith($substring)) {
$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);
mb_regex_encoding($regexEncoding);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
}