Completed
Push — master ( 6621b2...ba1955 )
by Lars
03:54
created
src/Stringy.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     // init
69 69
     UTF8::checkForSupport();
70 70
 
71
-    $this->str = (string)$str;
71
+    $this->str = (string) $str;
72 72
 
73 73
     if ($encoding) {
74 74
       $this->encoding = $encoding;
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
    */
92 92
   public function __toString()
93 93
   {
94
-    return (string)$this->str;
94
+    return (string) $this->str;
95 95
   }
96 96
 
97 97
   /**
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
    */
104 104
   public function append($string)
105 105
   {
106
-    return static::create($this->str . $string, $this->encoding);
106
+    return static::create($this->str.$string, $this->encoding);
107 107
   }
108 108
 
109 109
   /**
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
    */
130 130
   public function appendUniqueIdentifier($extraPrefix = '')
131 131
   {
132
-    $prefix = mt_rand() .
133
-              session_id() .
134
-              (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '') .
135
-              (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '') .
132
+    $prefix = mt_rand().
133
+              session_id().
134
+              (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '').
135
+              (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '').
136 136
               $extraPrefix;
137 137
 
138
-    return $this->append(md5(uniqid($prefix, true) . $prefix));
138
+    return $this->append(md5(uniqid($prefix, true).$prefix));
139 139
   }
140 140
 
141 141
   /**
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
   {
151 151
     // init
152 152
     $i = 0;
153
-    $length = (int)$length;
153
+    $length = (int) $length;
154 154
     $str = $this->str;
155 155
     $maxlength = UTF8::strlen($possibleChars, $this->encoding);
156 156
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
    */
227 227
   public function indexOf($needle, $offset = 0)
228 228
   {
229
-    return UTF8::strpos($this->str, (string)$needle, (int)$offset, $this->encoding);
229
+    return UTF8::strpos($this->str, (string) $needle, (int) $offset, $this->encoding);
230 230
   }
231 231
 
232 232
   /**
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
     }
309 309
 
310 310
     $str = preg_replace(
311
-        '/' . $pattern . '/u' . $options,
311
+        '/'.$pattern.'/u'.$options,
312 312
         $replacement,
313 313
         $this->str
314 314
     );
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
     $stringy = static::create($this->str, $this->encoding);
470 470
 
471 471
     if (!$stringy->startsWith($substring)) {
472
-      $stringy->str = $substring . $stringy->str;
472
+      $stringy->str = $substring.$stringy->str;
473 473
     }
474 474
 
475 475
     return $stringy;
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
       $endOfStr = UTF8::strtolower($endOfStr, $this->encoding);
569 569
     }
570 570
 
571
-    return (string)$substring === $endOfStr;
571
+    return (string) $substring === $endOfStr;
572 572
   }
573 573
 
574 574
   /**
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
    */
690 690
   protected function matchesPattern($pattern)
691 691
   {
692
-    if (preg_match('/' . $pattern . '/u', $this->str)) {
692
+    if (preg_match('/'.$pattern.'/u', $this->str)) {
693 693
       return true;
694 694
     }
695 695
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
         $this->encoding
764 764
     );
765 765
 
766
-    $str = UTF8::strtoupper($first, $this->encoding) . $rest;
766
+    $str = UTF8::strtoupper($first, $this->encoding).$rest;
767 767
 
768 768
     return static::create($str, $this->encoding);
769 769
   }
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
    */
782 782
   public function indexOfLast($needle, $offset = 0)
783 783
   {
784
-    return UTF8::strrpos($this->str, (string)$needle, (int)$offset, $this->encoding);
784
+    return UTF8::strrpos($this->str, (string) $needle, (int) $offset, $this->encoding);
785 785
   }
786 786
 
787 787
   /**
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
     $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
803 803
     $end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding);
804 804
 
805
-    $stringy->str = $start . $substring . $end;
805
+    $stringy->str = $start.$substring.$end;
806 806
 
807 807
     return $stringy;
808 808
   }
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
     $quotedPattern = preg_quote($pattern, '/');
829 829
     $replaceWildCards = str_replace('\*', '.*', $quotedPattern);
830 830
 
831
-    return $this->matchesPattern('^' . $replaceWildCards . '\z');
831
+    return $this->matchesPattern('^'.$replaceWildCards.'\z');
832 832
   }
833 833
 
834 834
   /**
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
       $char = UTF8::substr($this->str, -$i, 1, $encoding);
1066 1066
 
1067 1067
       if ($char == UTF8::substr($otherStr, -$i, 1, $encoding)) {
1068
-        $longestCommonSuffix = $char . $longestCommonSuffix;
1068
+        $longestCommonSuffix = $char.$longestCommonSuffix;
1069 1069
       } else {
1070 1070
         break;
1071 1071
       }
@@ -1140,7 +1140,7 @@  discard block
 block discarded – undo
1140 1140
   {
1141 1141
     // init
1142 1142
     $length = $this->length();
1143
-    $offset = (int)$offset;
1143
+    $offset = (int) $offset;
1144 1144
 
1145 1145
     if ($offset >= 0) {
1146 1146
       return ($length > $offset);
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
   public function offsetGet($offset)
1165 1165
   {
1166 1166
     // init
1167
-    $offset = (int)$offset;
1167
+    $offset = (int) $offset;
1168 1168
     $length = $this->length();
1169 1169
 
1170 1170
     if (
@@ -1225,7 +1225,7 @@  discard block
 block discarded – undo
1225 1225
   {
1226 1226
     if (!in_array($padType, array('left', 'right', 'both'), true)) {
1227 1227
       throw new \InvalidArgumentException(
1228
-          'Pad expects $padType ' . "to be one of 'left', 'right' or 'both'"
1228
+          'Pad expects $padType '."to be one of 'left', 'right' or 'both'"
1229 1229
       );
1230 1230
     }
1231 1231
 
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
         $stringy->encoding
1297 1297
     );
1298 1298
 
1299
-    $stringy->str = $leftPadding . $stringy->str . $rightPadding;
1299
+    $stringy->str = $leftPadding.$stringy->str.$rightPadding;
1300 1300
 
1301 1301
     return $stringy;
1302 1302
   }
@@ -1340,7 +1340,7 @@  discard block
 block discarded – undo
1340 1340
    */
1341 1341
   public function prepend($string)
1342 1342
   {
1343
-    return static::create($string . $this->str, $this->encoding);
1343
+    return static::create($string.$this->str, $this->encoding);
1344 1344
   }
1345 1345
 
1346 1346
   /**
@@ -1447,7 +1447,7 @@  discard block
 block discarded – undo
1447 1447
    */
1448 1448
   public function replaceBeginning($search, $replacement)
1449 1449
   {
1450
-    $str = $this->regexReplace('^' . preg_quote($search, '/'), UTF8::str_replace('\\', '\\\\', $replacement));
1450
+    $str = $this->regexReplace('^'.preg_quote($search, '/'), UTF8::str_replace('\\', '\\\\', $replacement));
1451 1451
 
1452 1452
     return static::create($str, $this->encoding);
1453 1453
   }
@@ -1462,7 +1462,7 @@  discard block
 block discarded – undo
1462 1462
    */
1463 1463
   public function replaceEnding($search, $replacement)
1464 1464
   {
1465
-    $str = $this->regexReplace(preg_quote($search, '/') . '$', UTF8::str_replace('\\', '\\\\', $replacement));
1465
+    $str = $this->regexReplace(preg_quote($search, '/').'$', UTF8::str_replace('\\', '\\\\', $replacement));
1466 1466
 
1467 1467
     return static::create($str, $this->encoding);
1468 1468
   }
@@ -1515,7 +1515,7 @@  discard block
 block discarded – undo
1515 1515
       }
1516 1516
     }
1517 1517
 
1518
-    $stringy->str = $truncated . $substring;
1518
+    $stringy->str = $truncated.$substring;
1519 1519
 
1520 1520
     return $stringy;
1521 1521
   }
@@ -1637,7 +1637,7 @@  discard block
 block discarded – undo
1637 1637
     $trimChars = "\t\r\n -_()!~?=+/*\\,.:;\"'[]{}`&";
1638 1638
 
1639 1639
     if ($length === null) {
1640
-      $length = (int)round($this->length() / 2, 0);
1640
+      $length = (int) round($this->length() / 2, 0);
1641 1641
     }
1642 1642
 
1643 1643
     if (empty($search)) {
@@ -1651,7 +1651,7 @@  discard block
 block discarded – undo
1651 1651
             rtrim(
1652 1652
                 UTF8::substr($text, 0, $pos, $this->encoding),
1653 1653
                 $trimChars
1654
-            ) . $ellipsis,
1654
+            ).$ellipsis,
1655 1655
             $this->encoding
1656 1656
         );
1657 1657
       }
@@ -1665,7 +1665,7 @@  discard block
 block discarded – undo
1665 1665
         null,
1666 1666
         $this->encoding
1667 1667
     );
1668
-    $halfSide = (int)($wordPos - $length / 2 + UTF8::strlen($search, $this->encoding) / 2);
1668
+    $halfSide = (int) ($wordPos - $length / 2 + UTF8::strlen($search, $this->encoding) / 2);
1669 1669
 
1670 1670
     if ($halfSide > 0) {
1671 1671
 
@@ -1694,7 +1694,7 @@  discard block
 block discarded – undo
1694 1694
                  ) - $pos_start;
1695 1695
 
1696 1696
       if (!$pos_end || $pos_end <= 0) {
1697
-        $extract = $ellipsis . ltrim(
1697
+        $extract = $ellipsis.ltrim(
1698 1698
                 UTF8::substr(
1699 1699
                     $text,
1700 1700
                     $pos_start,
@@ -1704,7 +1704,7 @@  discard block
 block discarded – undo
1704 1704
                 $trimChars
1705 1705
             );
1706 1706
       } else {
1707
-        $extract = $ellipsis . trim(
1707
+        $extract = $ellipsis.trim(
1708 1708
                 UTF8::substr(
1709 1709
                     $text,
1710 1710
                     $pos_start,
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
                     $this->encoding
1713 1713
                 ),
1714 1714
                 $trimChars
1715
-            ) . $ellipsis;
1715
+            ).$ellipsis;
1716 1716
       }
1717 1717
 
1718 1718
     } else {
@@ -1733,7 +1733,7 @@  discard block
 block discarded – undo
1733 1733
         $extract = rtrim(
1734 1734
                        UTF8::substr($text, 0, $pos_end, $this->encoding),
1735 1735
                        $trimChars
1736
-                   ) . $ellipsis;
1736
+                   ).$ellipsis;
1737 1737
       } else {
1738 1738
         $extract = $text;
1739 1739
       }
@@ -1847,7 +1847,7 @@  discard block
 block discarded – undo
1847 1847
       $limit = -1;
1848 1848
     }
1849 1849
 
1850
-    $array = preg_split('/' . preg_quote($pattern, '/') . '/u', $this->str, $limit);
1850
+    $array = preg_split('/'.preg_quote($pattern, '/').'/u', $this->str, $limit);
1851 1851
 
1852 1852
     if ($limit > 0 && count($array) === $limit) {
1853 1853
       array_pop($array);
@@ -1921,14 +1921,14 @@  discard block
 block discarded – undo
1921 1921
 
1922 1922
     $stringy->str = preg_replace_callback(
1923 1923
         '/([\S]+)/u',
1924
-        function ($match) use ($encoding, $ignore) {
1924
+        function($match) use ($encoding, $ignore) {
1925 1925
           if ($ignore && in_array($match[0], $ignore, true)) {
1926 1926
             return $match[0];
1927 1927
           }
1928 1928
 
1929 1929
           $stringy = new Stringy($match[0], $encoding);
1930 1930
 
1931
-          return (string)$stringy->toLowerCase()->upperCaseFirst();
1931
+          return (string) $stringy->toLowerCase()->upperCaseFirst();
1932 1932
         },
1933 1933
         $stringy->str
1934 1934
     );
@@ -2005,10 +2005,10 @@  discard block
 block discarded – undo
2005 2005
     }
2006 2006
 
2007 2007
     if (is_numeric($this->str)) {
2008
-      return ((int)$this->str > 0);
2008
+      return ((int) $this->str > 0);
2009 2009
     }
2010 2010
 
2011
-    return (bool)$this->regexReplace('[[:space:]]', '')->str;
2011
+    return (bool) $this->regexReplace('[[:space:]]', '')->str;
2012 2012
   }
2013 2013
 
2014 2014
   /**
@@ -2018,7 +2018,7 @@  discard block
 block discarded – undo
2018 2018
    */
2019 2019
   public function toString()
2020 2020
   {
2021
-    return (string)$this->str;
2021
+    return (string) $this->str;
2022 2022
   }
2023 2023
 
2024 2024
   /**
@@ -2142,7 +2142,7 @@  discard block
 block discarded – undo
2142 2142
     $length -= $substringLength;
2143 2143
 
2144 2144
     $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2145
-    $stringy->str = $truncated . $substring;
2145
+    $stringy->str = $truncated.$substring;
2146 2146
 
2147 2147
     return $stringy;
2148 2148
   }
@@ -2187,7 +2187,7 @@  discard block
 block discarded – undo
2187 2187
 
2188 2188
     $stringy->str = preg_replace_callback(
2189 2189
         '/[-_\s]+(.)?/u',
2190
-        function ($match) use ($encoding) {
2190
+        function($match) use ($encoding) {
2191 2191
           if (isset($match[1])) {
2192 2192
             return UTF8::strtoupper($match[1], $encoding);
2193 2193
           }
@@ -2199,7 +2199,7 @@  discard block
 block discarded – undo
2199 2199
 
2200 2200
     $stringy->str = preg_replace_callback(
2201 2201
         '/[\d]+(.)?/u',
2202
-        function ($match) use ($encoding) {
2202
+        function($match) use ($encoding) {
2203 2203
           return UTF8::strtoupper($match[0], $encoding);
2204 2204
         },
2205 2205
         $stringy->str
@@ -2223,15 +2223,15 @@  discard block
 block discarded – undo
2223 2223
 
2224 2224
     $str = preg_replace_callback(
2225 2225
         '/([\d|A-Z])/u',
2226
-        function ($matches) use ($encoding) {
2226
+        function($matches) use ($encoding) {
2227 2227
           $match = $matches[1];
2228
-          $matchInt = (int)$match;
2228
+          $matchInt = (int) $match;
2229 2229
 
2230 2230
           if ("$matchInt" == $match) {
2231
-            return '_' . $match . '_';
2231
+            return '_'.$match.'_';
2232 2232
           }
2233 2233
 
2234
-          return '_' . UTF8::strtolower($match, $encoding);
2234
+          return '_'.UTF8::strtolower($match, $encoding);
2235 2235
         },
2236 2236
         $str
2237 2237
     );
@@ -2239,9 +2239,9 @@  discard block
 block discarded – undo
2239 2239
     $str = preg_replace(
2240 2240
         array(
2241 2241
 
2242
-            '/\s+/',      // convert spaces to "_"
2243
-            '/^\s+|\s+$/',  // trim leading & trailing spaces
2244
-            '/_+/',         // remove double "_"
2242
+            '/\s+/', // convert spaces to "_"
2243
+            '/^\s+|\s+$/', // trim leading & trailing spaces
2244
+            '/_+/', // remove double "_"
2245 2245
         ),
2246 2246
         array(
2247 2247
             '_',
@@ -2267,7 +2267,7 @@  discard block
 block discarded – undo
2267 2267
     $first = UTF8::substr($this->str, 0, 1, $this->encoding);
2268 2268
     $rest = UTF8::substr($this->str, 1, $this->length() - 1, $this->encoding);
2269 2269
 
2270
-    $str = UTF8::strtolower($first, $this->encoding) . $rest;
2270
+    $str = UTF8::strtolower($first, $this->encoding).$rest;
2271 2271
 
2272 2272
     return static::create($str, $this->encoding);
2273 2273
   }
@@ -2438,7 +2438,7 @@  discard block
 block discarded – undo
2438 2438
     $restOfWord = UTF8::substr($word, 1, null, $encoding);
2439 2439
     $firstCharacterUppercased = UTF8::strtoupper($firstCharacter, $encoding);
2440 2440
 
2441
-    return new static($firstCharacterUppercased . $restOfWord, $encoding);
2441
+    return new static($firstCharacterUppercased.$restOfWord, $encoding);
2442 2442
   }
2443 2443
 
2444 2444
   /**
@@ -2452,7 +2452,7 @@  discard block
 block discarded – undo
2452 2452
   protected function capitalizePersonalNameByDelimiter($names, $delimiter)
2453 2453
   {
2454 2454
     // init
2455
-    $names = explode((string)$delimiter, (string)$names);
2455
+    $names = explode((string) $delimiter, (string) $names);
2456 2456
     $encoding = $this->encoding;
2457 2457
 
2458 2458
     $specialCases = array(
Please login to merge, or discard this patch.