Completed
Push — master ( 41323f...5a1e5b )
by Lars
03:51
created
src/Stringy.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     // init
63 63
     UTF8::checkForSupport();
64 64
 
65
-    $this->str = (string)$str;
65
+    $this->str = (string) $str;
66 66
 
67 67
     if ($encoding) {
68 68
       $this->encoding = $encoding;
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
    */
86 86
   public function __toString()
87 87
   {
88
-    return (string)$this->str;
88
+    return (string) $this->str;
89 89
   }
90 90
 
91 91
   /**
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
    */
98 98
   public function append($string)
99 99
   {
100
-    return static::create($this->str . $string, $this->encoding);
100
+    return static::create($this->str.$string, $this->encoding);
101 101
   }
102 102
 
103 103
   /**
@@ -123,13 +123,13 @@  discard block
 block discarded – undo
123 123
    */
124 124
   public function appendUniqueIdentifier($extraPrefix = '')
125 125
   {
126
-    $prefix = mt_rand() .
127
-              session_id() .
128
-              (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '') .
129
-              (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '') .
126
+    $prefix = mt_rand().
127
+              session_id().
128
+              (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '').
129
+              (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '').
130 130
               $extraPrefix;
131 131
 
132
-    return $this->append(md5(uniqid($prefix, true) . $prefix));
132
+    return $this->append(md5(uniqid($prefix, true).$prefix));
133 133
   }
134 134
 
135 135
   /**
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
   {
145 145
     // init
146 146
     $i = 0;
147
-    $length = (int)$length;
147
+    $length = (int) $length;
148 148
     $str = $this->str;
149 149
     $maxlength = UTF8::strlen($possibleChars, $this->encoding);
150 150
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
    */
221 221
   public function indexOf($needle, $offset = 0)
222 222
   {
223
-    return UTF8::strpos($this->str, (string)$needle, (int)$offset, $this->encoding);
223
+    return UTF8::strpos($this->str, (string) $needle, (int) $offset, $this->encoding);
224 224
   }
225 225
 
226 226
   /**
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
     }
303 303
 
304 304
     $str = preg_replace(
305
-        '/' . $pattern . '/u' . $options,
305
+        '/'.$pattern.'/u'.$options,
306 306
         $replacement,
307 307
         $this->str
308 308
     );
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
     $stringy = static::create($this->str, $this->encoding);
464 464
 
465 465
     if (!$stringy->startsWith($substring)) {
466
-      $stringy->str = $substring . $stringy->str;
466
+      $stringy->str = $substring.$stringy->str;
467 467
     }
468 468
 
469 469
     return $stringy;
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
       $endOfStr = UTF8::strtolower($endOfStr, $this->encoding);
563 563
     }
564 564
 
565
-    return (string)$substring === $endOfStr;
565
+    return (string) $substring === $endOfStr;
566 566
   }
567 567
 
568 568
   /**
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
    */
659 659
   private function matchesPattern($pattern)
660 660
   {
661
-    if (preg_match('/' . $pattern . '/u', $this->str)) {
661
+    if (preg_match('/'.$pattern.'/u', $this->str)) {
662 662
       return true;
663 663
     } else {
664 664
       return false;
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
         $this->encoding
733 733
     );
734 734
 
735
-    $str = UTF8::strtoupper($first, $this->encoding) . $rest;
735
+    $str = UTF8::strtoupper($first, $this->encoding).$rest;
736 736
 
737 737
     return static::create($str, $this->encoding);
738 738
   }
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
    */
751 751
   public function indexOfLast($needle, $offset = 0)
752 752
   {
753
-    return UTF8::strrpos($this->str, (string)$needle, (int)$offset, $this->encoding);
753
+    return UTF8::strrpos($this->str, (string) $needle, (int) $offset, $this->encoding);
754 754
   }
755 755
 
756 756
   /**
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
     $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
772 772
     $end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding);
773 773
 
774
-    $stringy->str = $start . $substring . $end;
774
+    $stringy->str = $start.$substring.$end;
775 775
 
776 776
     return $stringy;
777 777
   }
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
     $quotedPattern = preg_quote($pattern, '/');
798 798
     $replaceWildCards = str_replace('\*', '.*', $quotedPattern);
799 799
 
800
-    return $this->matchesPattern('^' . $replaceWildCards . '\z');
800
+    return $this->matchesPattern('^'.$replaceWildCards.'\z');
801 801
   }
802 802
 
803 803
   /**
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
       $char = UTF8::substr($this->str, -$i, 1, $encoding);
1035 1035
 
1036 1036
       if ($char == UTF8::substr($otherStr, -$i, 1, $encoding)) {
1037
-        $longestCommonSuffix = $char . $longestCommonSuffix;
1037
+        $longestCommonSuffix = $char.$longestCommonSuffix;
1038 1038
       } else {
1039 1039
         break;
1040 1040
       }
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
   {
1110 1110
     // init
1111 1111
     $length = $this->length();
1112
-    $offset = (int)$offset;
1112
+    $offset = (int) $offset;
1113 1113
 
1114 1114
     if ($offset >= 0) {
1115 1115
       return ($length > $offset);
@@ -1133,7 +1133,7 @@  discard block
 block discarded – undo
1133 1133
   public function offsetGet($offset)
1134 1134
   {
1135 1135
     // init
1136
-    $offset = (int)$offset;
1136
+    $offset = (int) $offset;
1137 1137
     $length = $this->length();
1138 1138
 
1139 1139
     if (
@@ -1194,7 +1194,7 @@  discard block
 block discarded – undo
1194 1194
   {
1195 1195
     if (!in_array($padType, array('left', 'right', 'both'), true)) {
1196 1196
       throw new \InvalidArgumentException(
1197
-          'Pad expects $padType ' . "to be one of 'left', 'right' or 'both'"
1197
+          'Pad expects $padType '."to be one of 'left', 'right' or 'both'"
1198 1198
       );
1199 1199
     }
1200 1200
 
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
         $stringy->encoding
1266 1266
     );
1267 1267
 
1268
-    $stringy->str = $leftPadding . $stringy->str . $rightPadding;
1268
+    $stringy->str = $leftPadding.$stringy->str.$rightPadding;
1269 1269
 
1270 1270
     return $stringy;
1271 1271
   }
@@ -1309,7 +1309,7 @@  discard block
 block discarded – undo
1309 1309
    */
1310 1310
   public function prepend($string)
1311 1311
   {
1312
-    return static::create($string . $this->str, $this->encoding);
1312
+    return static::create($string.$this->str, $this->encoding);
1313 1313
   }
1314 1314
 
1315 1315
   /**
@@ -1416,7 +1416,7 @@  discard block
 block discarded – undo
1416 1416
    */
1417 1417
   public function replaceBeginning($search, $replacement)
1418 1418
   {
1419
-    $str = $this->regexReplace('^' . preg_quote($search, '/'), UTF8::str_replace('\\', '\\\\', $replacement));
1419
+    $str = $this->regexReplace('^'.preg_quote($search, '/'), UTF8::str_replace('\\', '\\\\', $replacement));
1420 1420
 
1421 1421
     return static::create($str, $this->encoding);
1422 1422
   }
@@ -1431,7 +1431,7 @@  discard block
 block discarded – undo
1431 1431
    */
1432 1432
   public function replaceEnding($search, $replacement)
1433 1433
   {
1434
-    $str = $this->regexReplace(preg_quote($search, '/') . '$', UTF8::str_replace('\\', '\\\\', $replacement));
1434
+    $str = $this->regexReplace(preg_quote($search, '/').'$', UTF8::str_replace('\\', '\\\\', $replacement));
1435 1435
 
1436 1436
     return static::create($str, $this->encoding);
1437 1437
   }
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
       }
1485 1485
     }
1486 1486
 
1487
-    $stringy->str = $truncated . $substring;
1487
+    $stringy->str = $truncated.$substring;
1488 1488
 
1489 1489
     return $stringy;
1490 1490
   }
@@ -1609,7 +1609,7 @@  discard block
 block discarded – undo
1609 1609
             rtrim(
1610 1610
                 UTF8::substr($text, 0, $pos, $this->encoding),
1611 1611
                 $trimChars
1612
-            ) . $ellipsis,
1612
+            ).$ellipsis,
1613 1613
             $this->encoding
1614 1614
         );
1615 1615
       } else {
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
         null,
1625 1625
         $this->encoding
1626 1626
     );
1627
-    $halfSide = (int)($wordPos - $length / 2 + UTF8::strlen($search, $this->encoding) / 2);
1627
+    $halfSide = (int) ($wordPos - $length / 2 + UTF8::strlen($search, $this->encoding) / 2);
1628 1628
 
1629 1629
     if ($halfSide > 0) {
1630 1630
 
@@ -1653,7 +1653,7 @@  discard block
 block discarded – undo
1653 1653
                  ) - $pos_start;
1654 1654
 
1655 1655
       if (!$pos_end || $pos_end <= 0) {
1656
-        $extract = $ellipsis . ltrim(
1656
+        $extract = $ellipsis.ltrim(
1657 1657
                 UTF8::substr(
1658 1658
                     $text,
1659 1659
                     $pos_start,
@@ -1663,7 +1663,7 @@  discard block
 block discarded – undo
1663 1663
                 $trimChars
1664 1664
             );
1665 1665
       } else {
1666
-        $extract = $ellipsis . trim(
1666
+        $extract = $ellipsis.trim(
1667 1667
                 UTF8::substr(
1668 1668
                     $text,
1669 1669
                     $pos_start,
@@ -1671,7 +1671,7 @@  discard block
 block discarded – undo
1671 1671
                     $this->encoding
1672 1672
                 ),
1673 1673
                 $trimChars
1674
-            ) . $ellipsis;
1674
+            ).$ellipsis;
1675 1675
       }
1676 1676
 
1677 1677
     } else {
@@ -1692,7 +1692,7 @@  discard block
 block discarded – undo
1692 1692
         $extract = rtrim(
1693 1693
                        UTF8::substr($text, 0, $pos_end, $this->encoding),
1694 1694
                        $trimChars
1695
-                   ) . $ellipsis;
1695
+                   ).$ellipsis;
1696 1696
       } else {
1697 1697
         $extract = $text;
1698 1698
       }
@@ -1806,7 +1806,7 @@  discard block
 block discarded – undo
1806 1806
       $limit = -1;
1807 1807
     }
1808 1808
 
1809
-    $array = preg_split('/' . preg_quote($pattern, '/') . '/u', $this->str, $limit);
1809
+    $array = preg_split('/'.preg_quote($pattern, '/').'/u', $this->str, $limit);
1810 1810
 
1811 1811
     if ($limit > 0 && count($array) === $limit) {
1812 1812
       array_pop($array);
@@ -1880,13 +1880,13 @@  discard block
 block discarded – undo
1880 1880
 
1881 1881
     $stringy->str = preg_replace_callback(
1882 1882
         '/([\S]+)/u',
1883
-        function ($match) use ($encoding, $ignore) {
1883
+        function($match) use ($encoding, $ignore) {
1884 1884
           if ($ignore && in_array($match[0], $ignore, true)) {
1885 1885
             return $match[0];
1886 1886
           } else {
1887 1887
             $stringy = new Stringy($match[0], $encoding);
1888 1888
 
1889
-            return (string)$stringy->toLowerCase()->upperCaseFirst();
1889
+            return (string) $stringy->toLowerCase()->upperCaseFirst();
1890 1890
           }
1891 1891
         },
1892 1892
         $stringy->str
@@ -1962,9 +1962,9 @@  discard block
 block discarded – undo
1962 1962
     if (array_key_exists($key, $map)) {
1963 1963
       return $map[$key];
1964 1964
     } elseif (is_numeric($this->str)) {
1965
-      return ((int)$this->str > 0);
1965
+      return ((int) $this->str > 0);
1966 1966
     } else {
1967
-      return (bool)$this->regexReplace('[[:space:]]', '')->str;
1967
+      return (bool) $this->regexReplace('[[:space:]]', '')->str;
1968 1968
     }
1969 1969
   }
1970 1970
 
@@ -1975,7 +1975,7 @@  discard block
 block discarded – undo
1975 1975
    */
1976 1976
   public function toString()
1977 1977
   {
1978
-    return (string)$this->str;
1978
+    return (string) $this->str;
1979 1979
   }
1980 1980
 
1981 1981
   /**
@@ -2099,7 +2099,7 @@  discard block
 block discarded – undo
2099 2099
     $length -= $substringLength;
2100 2100
 
2101 2101
     $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2102
-    $stringy->str = $truncated . $substring;
2102
+    $stringy->str = $truncated.$substring;
2103 2103
 
2104 2104
     return $stringy;
2105 2105
   }
@@ -2144,7 +2144,7 @@  discard block
 block discarded – undo
2144 2144
 
2145 2145
     $stringy->str = preg_replace_callback(
2146 2146
         '/[-_\s]+(.)?/u',
2147
-        function ($match) use ($encoding) {
2147
+        function($match) use ($encoding) {
2148 2148
           if (isset($match[1])) {
2149 2149
             return UTF8::strtoupper($match[1], $encoding);
2150 2150
           } else {
@@ -2156,7 +2156,7 @@  discard block
 block discarded – undo
2156 2156
 
2157 2157
     $stringy->str = preg_replace_callback(
2158 2158
         '/[\d]+(.)?/u',
2159
-        function ($match) use ($encoding) {
2159
+        function($match) use ($encoding) {
2160 2160
           return UTF8::strtoupper($match[0], $encoding);
2161 2161
         },
2162 2162
         $stringy->str
@@ -2180,14 +2180,14 @@  discard block
 block discarded – undo
2180 2180
 
2181 2181
     $str = preg_replace_callback(
2182 2182
         '/([\d|A-Z])/u',
2183
-        function ($matches) use ($encoding) {
2183
+        function($matches) use ($encoding) {
2184 2184
           $match = $matches[1];
2185
-          $matchInt = (int)$match;
2185
+          $matchInt = (int) $match;
2186 2186
 
2187 2187
           if ("$matchInt" == $match) {
2188
-            return '_' . $match . '_';
2188
+            return '_'.$match.'_';
2189 2189
           } else {
2190
-            return '_' . UTF8::strtolower($match, $encoding);
2190
+            return '_'.UTF8::strtolower($match, $encoding);
2191 2191
           }
2192 2192
         },
2193 2193
         $str
@@ -2196,9 +2196,9 @@  discard block
 block discarded – undo
2196 2196
     $str = preg_replace(
2197 2197
         array(
2198 2198
 
2199
-            '/\s+/',      // convert spaces to "_"
2200
-            '/^\s+|\s+$/',  // trim leading & trailing spaces
2201
-            '/_+/',         // remove double "_"
2199
+            '/\s+/', // convert spaces to "_"
2200
+            '/^\s+|\s+$/', // trim leading & trailing spaces
2201
+            '/_+/', // remove double "_"
2202 2202
         ),
2203 2203
         array(
2204 2204
             '_',
@@ -2224,7 +2224,7 @@  discard block
 block discarded – undo
2224 2224
     $first = UTF8::substr($this->str, 0, 1, $this->encoding);
2225 2225
     $rest = UTF8::substr($this->str, 1, $this->length() - 1, $this->encoding);
2226 2226
 
2227
-    $str = UTF8::strtolower($first, $this->encoding) . $rest;
2227
+    $str = UTF8::strtolower($first, $this->encoding).$rest;
2228 2228
 
2229 2229
     return static::create($str, $this->encoding);
2230 2230
   }
@@ -2395,7 +2395,7 @@  discard block
 block discarded – undo
2395 2395
     $restOfWord = UTF8::substr($word, 1, null, $encoding);
2396 2396
     $firstCharacterUppercased = UTF8::strtoupper($firstCharacter, $encoding);
2397 2397
 
2398
-    return new static($firstCharacterUppercased . $restOfWord, $encoding);
2398
+    return new static($firstCharacterUppercased.$restOfWord, $encoding);
2399 2399
   }
2400 2400
 
2401 2401
   /**
Please login to merge, or discard this patch.