Completed
Push — master ( 6b3f4e...f227f3 )
by Lars
01:33
created
src/StaticStringy.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Stringy;
6 6
 
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     }
148 148
 
149 149
     if (!isset(static::$methodArgs[$name])) {
150
-      throw new \BadMethodCallException($name . ' is not a valid method');
150
+      throw new \BadMethodCallException($name.' is not a valid method');
151 151
     }
152 152
 
153 153
     $numArgs = \count($arguments);
Please login to merge, or discard this patch.
src/Stringy.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1897,9 +1897,9 @@  discard block
 block discarded – undo
1897 1897
       }
1898 1898
 
1899 1899
       $pos_end = \min(
1900
-                     UTF8::strpos($text, ' ', $l, $this->encoding),
1901
-                     UTF8::strpos($text, '.', $l, $this->encoding)
1902
-                 ) - $pos_start;
1900
+                      UTF8::strpos($text, ' ', $l, $this->encoding),
1901
+                      UTF8::strpos($text, '.', $l, $this->encoding)
1902
+                  ) - $pos_start;
1903 1903
 
1904 1904
       if (!$pos_end || $pos_end <= 0) {
1905 1905
         $extract = $replacerForSkippedText . \ltrim(
@@ -1939,9 +1939,9 @@  discard block
 block discarded – undo
1939 1939
 
1940 1940
       if ($pos_end) {
1941 1941
         $extract = \rtrim(
1942
-                       UTF8::substr($text, 0, $pos_end, $this->encoding),
1943
-                       $trimChars
1944
-                   ) . $replacerForSkippedText;
1942
+                        UTF8::substr($text, 0, $pos_end, $this->encoding),
1943
+                        $trimChars
1944
+                    ) . $replacerForSkippedText;
1945 1945
       } else {
1946 1946
         $extract = $text;
1947 1947
       }
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Stringy;
6 6
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
     // init
66 66
     UTF8::checkForSupport();
67 67
 
68
-    $this->str = (string)$str;
68
+    $this->str = (string) $str;
69 69
 
70 70
     if ($encoding) {
71 71
       $this->encoding = $encoding;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
    */
82 82
   public function __toString()
83 83
   {
84
-    return (string)$this->str;
84
+    return (string) $this->str;
85 85
   }
86 86
 
87 87
   /**
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
    */
94 94
   public function append(string $string): Stringy
95 95
   {
96
-    return static::create($this->str . $string, $this->encoding);
96
+    return static::create($this->str.$string, $this->encoding);
97 97
   }
98 98
 
99 99
   /**
@@ -120,16 +120,16 @@  discard block
 block discarded – undo
120 120
    */
121 121
   public function appendUniqueIdentifier($entropyExtra = '', bool $md5 = true): Stringy
122 122
   {
123
-    $uniqueHelper = \mt_rand() .
124
-                    \session_id() .
125
-                    ($_SERVER['REMOTE_ADDR'] ?? '') .
126
-                    ($_SERVER['SERVER_ADDR'] ?? '') .
123
+    $uniqueHelper = \mt_rand().
124
+                    \session_id().
125
+                    ($_SERVER['REMOTE_ADDR'] ?? '').
126
+                    ($_SERVER['SERVER_ADDR'] ?? '').
127 127
                     $entropyExtra;
128 128
 
129 129
     $uniqueString = \uniqid($uniqueHelper, true);
130 130
 
131 131
     if ($md5) {
132
-      $uniqueString = \md5($uniqueString . $uniqueHelper);
132
+      $uniqueString = \md5($uniqueString.$uniqueHelper);
133 133
     }
134 134
 
135 135
     return $this->append($uniqueString);
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
       $delimiter = '/';
326 326
     }
327 327
 
328
-    $str = (string)\preg_replace(
329
-        $delimiter . $pattern . $delimiter . 'u' . $options,
328
+    $str = (string) \preg_replace(
329
+        $delimiter.$pattern.$delimiter.'u'.$options,
330 330
         $replacement,
331 331
         $this->str
332 332
     );
@@ -465,11 +465,11 @@  discard block
 block discarded – undo
465 465
   {
466 466
     $str = $this->trim();
467 467
 
468
-    $str = (string)\preg_replace('/\B([A-Z])/u', '-\1', $str);
468
+    $str = (string) \preg_replace('/\B([A-Z])/u', '-\1', $str);
469 469
 
470 470
     $str = UTF8::strtolower($str, $this->encoding);
471 471
 
472
-    $str = (string)\preg_replace('/[-_\s]+/u', $delimiter, $str);
472
+    $str = (string) \preg_replace('/[-_\s]+/u', $delimiter, $str);
473 473
 
474 474
     return static::create($str, $this->encoding);
475 475
   }
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
     $stringy = static::create($this->str, $this->encoding);
488 488
 
489 489
     if (!$stringy->startsWith($substring)) {
490
-      $stringy->str = $substring . $stringy->str;
490
+      $stringy->str = $substring.$stringy->str;
491 491
     }
492 492
 
493 493
     return $stringy;
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
    */
706 706
   protected function matchesPattern(string $pattern): bool
707 707
   {
708
-    if (\preg_match('/' . $pattern . '/u', $this->str)) {
708
+    if (\preg_match('/'.$pattern.'/u', $this->str)) {
709 709
       return true;
710 710
     }
711 711
 
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
         $this->encoding
871 871
     );
872 872
 
873
-    $str = UTF8::strtoupper($first, $this->encoding) . $rest;
873
+    $str = UTF8::strtoupper($first, $this->encoding).$rest;
874 874
 
875 875
     return static::create($str, $this->encoding);
876 876
   }
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
     $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
926 926
     $end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding);
927 927
 
928
-    $stringy->str = $start . $substring . $end;
928
+    $stringy->str = $start.$substring.$end;
929 929
 
930 930
     return $stringy;
931 931
   }
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
     $quotedPattern = \preg_quote($pattern, '/');
952 952
     $replaceWildCards = \str_replace('\*', '.*', $quotedPattern);
953 953
 
954
-    return $this->matchesPattern('^' . $replaceWildCards . '\z');
954
+    return $this->matchesPattern('^'.$replaceWildCards.'\z');
955 955
   }
956 956
 
957 957
   /**
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
       $char = UTF8::substr($this->str, -$i, 1, $encoding);
1175 1175
 
1176 1176
       if ($char == UTF8::substr($otherStr, -$i, 1, $encoding)) {
1177
-        $longestCommonSuffix = $char . $longestCommonSuffix;
1177
+        $longestCommonSuffix = $char.$longestCommonSuffix;
1178 1178
       } else {
1179 1179
         break;
1180 1180
       }
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
   {
1251 1251
     // init
1252 1252
     $length = $this->length();
1253
-    $offset = (int)$offset;
1253
+    $offset = (int) $offset;
1254 1254
 
1255 1255
     if ($offset >= 0) {
1256 1256
       return ($length > $offset);
@@ -1274,7 +1274,7 @@  discard block
 block discarded – undo
1274 1274
   public function offsetGet($offset): string
1275 1275
   {
1276 1276
     // init
1277
-    $offset = (int)$offset;
1277
+    $offset = (int) $offset;
1278 1278
     $length = $this->length();
1279 1279
 
1280 1280
     if (
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
   {
1337 1337
     if (!\in_array($padType, ['left', 'right', 'both'], true)) {
1338 1338
       throw new \InvalidArgumentException(
1339
-          'Pad expects $padType ' . "to be one of 'left', 'right' or 'both'"
1339
+          'Pad expects $padType '."to be one of 'left', 'right' or 'both'"
1340 1340
       );
1341 1341
     }
1342 1342
 
@@ -1390,7 +1390,7 @@  discard block
 block discarded – undo
1390 1390
     $leftPadding = UTF8::substr(
1391 1391
         UTF8::str_repeat(
1392 1392
             $padStr,
1393
-            (int)\ceil($left / $length)
1393
+            (int) \ceil($left / $length)
1394 1394
         ),
1395 1395
         0,
1396 1396
         $left,
@@ -1400,14 +1400,14 @@  discard block
 block discarded – undo
1400 1400
     $rightPadding = UTF8::substr(
1401 1401
         UTF8::str_repeat(
1402 1402
             $padStr,
1403
-            (int)\ceil($right / $length)
1403
+            (int) \ceil($right / $length)
1404 1404
         ),
1405 1405
         0,
1406 1406
         $right,
1407 1407
         $stringy->encoding
1408 1408
     );
1409 1409
 
1410
-    $stringy->str = $leftPadding . $stringy->str . $rightPadding;
1410
+    $stringy->str = $leftPadding.$stringy->str.$rightPadding;
1411 1411
 
1412 1412
     return $stringy;
1413 1413
   }
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
   {
1440 1440
     $padding = $length - $this->length();
1441 1441
 
1442
-    return $this->applyPadding((int)\floor($padding / 2), (int)\ceil($padding / 2), $padStr);
1442
+    return $this->applyPadding((int) \floor($padding / 2), (int) \ceil($padding / 2), $padStr);
1443 1443
   }
1444 1444
 
1445 1445
   /**
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
    */
1452 1452
   public function prepend(string $string): Stringy
1453 1453
   {
1454
-    return static::create($string . $this->str, $this->encoding);
1454
+    return static::create($string.$this->str, $this->encoding);
1455 1455
   }
1456 1456
 
1457 1457
   /**
@@ -1558,7 +1558,7 @@  discard block
 block discarded – undo
1558 1558
    */
1559 1559
   public function replaceBeginning(string $search, string $replacement): Stringy
1560 1560
   {
1561
-    $str = $this->regexReplace('^' . \preg_quote($search, '/'), UTF8::str_replace('\\', '\\\\', $replacement));
1561
+    $str = $this->regexReplace('^'.\preg_quote($search, '/'), UTF8::str_replace('\\', '\\\\', $replacement));
1562 1562
 
1563 1563
     return static::create($str, $this->encoding);
1564 1564
   }
@@ -1573,7 +1573,7 @@  discard block
 block discarded – undo
1573 1573
    */
1574 1574
   public function replaceEnding(string $search, string $replacement): Stringy
1575 1575
   {
1576
-    $str = $this->regexReplace(\preg_quote($search, '/') . '$', UTF8::str_replace('\\', '\\\\', $replacement));
1576
+    $str = $this->regexReplace(\preg_quote($search, '/').'$', UTF8::str_replace('\\', '\\\\', $replacement));
1577 1577
 
1578 1578
     return static::create($str, $this->encoding);
1579 1579
   }
@@ -1710,11 +1710,11 @@  discard block
 block discarded – undo
1710 1710
       $lastPos = UTF8::strrpos($truncated, ' ', 0, $encoding);
1711 1711
 
1712 1712
       if ($lastPos !== false || $strPosSpace !== false) {
1713
-        $truncated = UTF8::substr($truncated, 0, (int)$lastPos, $encoding);
1713
+        $truncated = UTF8::substr($truncated, 0, (int) $lastPos, $encoding);
1714 1714
       }
1715 1715
     }
1716 1716
 
1717
-    $stringy->str = $truncated . $substring;
1717
+    $stringy->str = $truncated.$substring;
1718 1718
 
1719 1719
     return $stringy;
1720 1720
   }
@@ -1836,7 +1836,7 @@  discard block
 block discarded – undo
1836 1836
     $trimChars = "\t\r\n -_()!~?=+/*\\,.:;\"'[]{}`&";
1837 1837
 
1838 1838
     if ($length === null) {
1839
-      $length = (int)\round($this->length() / 2, 0);
1839
+      $length = (int) \round($this->length() / 2, 0);
1840 1840
     }
1841 1841
 
1842 1842
     if (empty($search)) {
@@ -1859,7 +1859,7 @@  discard block
 block discarded – undo
1859 1859
             \rtrim(
1860 1860
                 UTF8::substr($text, 0, $pos, $this->encoding),
1861 1861
                 $trimChars
1862
-            ) . $replacerForSkippedText,
1862
+            ).$replacerForSkippedText,
1863 1863
             $this->encoding
1864 1864
         );
1865 1865
       }
@@ -1873,7 +1873,7 @@  discard block
 block discarded – undo
1873 1873
         0,
1874 1874
         $this->encoding
1875 1875
     );
1876
-    $halfSide = (int)($wordPos - $length / 2 + UTF8::strlen($search, $this->encoding) / 2);
1876
+    $halfSide = (int) ($wordPos - $length / 2 + UTF8::strlen($search, $this->encoding) / 2);
1877 1877
 
1878 1878
     if ($halfSide > 0) {
1879 1879
 
@@ -1902,7 +1902,7 @@  discard block
 block discarded – undo
1902 1902
                  ) - $pos_start;
1903 1903
 
1904 1904
       if (!$pos_end || $pos_end <= 0) {
1905
-        $extract = $replacerForSkippedText . \ltrim(
1905
+        $extract = $replacerForSkippedText.\ltrim(
1906 1906
                 UTF8::substr(
1907 1907
                     $text,
1908 1908
                     $pos_start,
@@ -1912,7 +1912,7 @@  discard block
 block discarded – undo
1912 1912
                 $trimChars
1913 1913
             );
1914 1914
       } else {
1915
-        $extract = $replacerForSkippedText . \trim(
1915
+        $extract = $replacerForSkippedText.\trim(
1916 1916
                 UTF8::substr(
1917 1917
                     $text,
1918 1918
                     $pos_start,
@@ -1920,7 +1920,7 @@  discard block
 block discarded – undo
1920 1920
                     $this->encoding
1921 1921
                 ),
1922 1922
                 $trimChars
1923
-            ) . $replacerForSkippedText;
1923
+            ).$replacerForSkippedText;
1924 1924
       }
1925 1925
 
1926 1926
     } else {
@@ -1941,7 +1941,7 @@  discard block
 block discarded – undo
1941 1941
         $extract = \rtrim(
1942 1942
                        UTF8::substr($text, 0, $pos_end, $this->encoding),
1943 1943
                        $trimChars
1944
-                   ) . $replacerForSkippedText;
1944
+                   ).$replacerForSkippedText;
1945 1945
       } else {
1946 1946
         $extract = $text;
1947 1947
       }
@@ -1978,7 +1978,7 @@  discard block
 block discarded – undo
1978 1978
    */
1979 1979
   public function removeHtmlBreak(string $replacement = ''): Stringy
1980 1980
   {
1981
-    $str = (string)\preg_replace('#/\r\n|\r|\n|<br.*/?>#isU', $replacement, $this->str);
1981
+    $str = (string) \preg_replace('#/\r\n|\r|\n|<br.*/?>#isU', $replacement, $this->str);
1982 1982
 
1983 1983
     return static::create($str, $this->encoding);
1984 1984
   }
@@ -2057,7 +2057,7 @@  discard block
 block discarded – undo
2057 2057
       $limit = -1;
2058 2058
     }
2059 2059
 
2060
-    $array = \preg_split('/' . \preg_quote($pattern, '/') . '/u', $this->str, $limit);
2060
+    $array = \preg_split('/'.\preg_quote($pattern, '/').'/u', $this->str, $limit);
2061 2061
 
2062 2062
     if ($limit > 0 && \count($array) === $limit) {
2063 2063
       \array_pop($array);
@@ -2128,16 +2128,16 @@  discard block
 block discarded – undo
2128 2128
     $stringy = static::create($this->trim(), $this->encoding);
2129 2129
     $encoding = $this->encoding;
2130 2130
 
2131
-    $stringy->str = (string)\preg_replace_callback(
2131
+    $stringy->str = (string) \preg_replace_callback(
2132 2132
         '/([\S]+)/u',
2133
-        function ($match) use ($encoding, $ignore) {
2133
+        function($match) use ($encoding, $ignore) {
2134 2134
           if ($ignore && \in_array($match[0], $ignore, true)) {
2135 2135
             return $match[0];
2136 2136
           }
2137 2137
 
2138 2138
           $stringy = new static($match[0], $encoding);
2139 2139
 
2140
-          return (string)$stringy->toLowerCase()->upperCaseFirst();
2140
+          return (string) $stringy->toLowerCase()->upperCaseFirst();
2141 2141
         },
2142 2142
         $stringy->str
2143 2143
     );
@@ -2214,10 +2214,10 @@  discard block
 block discarded – undo
2214 2214
     }
2215 2215
 
2216 2216
     if (\is_numeric($this->str)) {
2217
-      return ((int)$this->str > 0);
2217
+      return ((int) $this->str > 0);
2218 2218
     }
2219 2219
 
2220
-    return (bool)$this->regexReplace('[[:space:]]', '')->str;
2220
+    return (bool) $this->regexReplace('[[:space:]]', '')->str;
2221 2221
   }
2222 2222
 
2223 2223
   /**
@@ -2227,7 +2227,7 @@  discard block
 block discarded – undo
2227 2227
    */
2228 2228
   public function toString(): string
2229 2229
   {
2230
-    return (string)$this->str;
2230
+    return (string) $this->str;
2231 2231
   }
2232 2232
 
2233 2233
   /**
@@ -2350,7 +2350,7 @@  discard block
 block discarded – undo
2350 2350
     $length -= $substringLength;
2351 2351
 
2352 2352
     $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2353
-    $stringy->str = $truncated . $substring;
2353
+    $stringy->str = $truncated.$substring;
2354 2354
 
2355 2355
     return $stringy;
2356 2356
   }
@@ -2391,11 +2391,11 @@  discard block
 block discarded – undo
2391 2391
   {
2392 2392
     $encoding = $this->encoding;
2393 2393
     $stringy = $this->trim()->lowerCaseFirst();
2394
-    $stringy->str = (string)\preg_replace('/^[-_]+/', '', $stringy->str);
2394
+    $stringy->str = (string) \preg_replace('/^[-_]+/', '', $stringy->str);
2395 2395
 
2396
-    $stringy->str = (string)\preg_replace_callback(
2396
+    $stringy->str = (string) \preg_replace_callback(
2397 2397
         '/[-_\s]+(.)?/u',
2398
-        function ($match) use ($encoding) {
2398
+        function($match) use ($encoding) {
2399 2399
           if (isset($match[1])) {
2400 2400
             return UTF8::strtoupper($match[1], $encoding);
2401 2401
           }
@@ -2405,9 +2405,9 @@  discard block
 block discarded – undo
2405 2405
         $stringy->str
2406 2406
     );
2407 2407
 
2408
-    $stringy->str = (string)\preg_replace_callback(
2408
+    $stringy->str = (string) \preg_replace_callback(
2409 2409
         '/[\d]+(.)?/u',
2410
-        function ($match) use ($encoding) {
2410
+        function($match) use ($encoding) {
2411 2411
           return UTF8::strtoupper($match[0], $encoding);
2412 2412
         },
2413 2413
         $stringy->str
@@ -2429,27 +2429,27 @@  discard block
 block discarded – undo
2429 2429
     $str = UTF8::normalize_whitespace($str);
2430 2430
     $str = \str_replace('-', '_', $str);
2431 2431
 
2432
-    $str = (string)\preg_replace_callback(
2432
+    $str = (string) \preg_replace_callback(
2433 2433
         '/([\d|A-Z])/u',
2434
-        function ($matches) use ($encoding) {
2434
+        function($matches) use ($encoding) {
2435 2435
           $match = $matches[1];
2436
-          $matchInt = (int)$match;
2436
+          $matchInt = (int) $match;
2437 2437
 
2438 2438
           if ("$matchInt" == $match) {
2439
-            return '_' . $match . '_';
2439
+            return '_'.$match.'_';
2440 2440
           }
2441 2441
 
2442
-          return '_' . UTF8::strtolower($match, $encoding);
2442
+          return '_'.UTF8::strtolower($match, $encoding);
2443 2443
         },
2444 2444
         $str
2445 2445
     );
2446 2446
 
2447
-    $str = (string)\preg_replace(
2447
+    $str = (string) \preg_replace(
2448 2448
         [
2449 2449
 
2450
-            '/\s+/',      // convert spaces to "_"
2451
-            '/^\s+|\s+$/',  // trim leading & trailing spaces
2452
-            '/_+/',         // remove double "_"
2450
+            '/\s+/', // convert spaces to "_"
2451
+            '/^\s+|\s+$/', // trim leading & trailing spaces
2452
+            '/_+/', // remove double "_"
2453 2453
         ],
2454 2454
         [
2455 2455
             '_',
@@ -2475,7 +2475,7 @@  discard block
 block discarded – undo
2475 2475
     $first = UTF8::substr($this->str, 0, 1, $this->encoding);
2476 2476
     $rest = UTF8::substr($this->str, 1, $this->length() - 1, $this->encoding);
2477 2477
 
2478
-    $str = UTF8::strtolower($first, $this->encoding) . $rest;
2478
+    $str = UTF8::strtolower($first, $this->encoding).$rest;
2479 2479
 
2480 2480
     return static::create($str, $this->encoding);
2481 2481
   }
@@ -2504,7 +2504,7 @@  discard block
 block discarded – undo
2504 2504
    */
2505 2505
   public function lineWrapAfterWord(int $limit): Stringy
2506 2506
   {
2507
-    $strings = (array)\preg_split('/\\r\\n|\\r|\\n/', $this->str);
2507
+    $strings = (array) \preg_split('/\\r\\n|\\r|\\n/', $this->str);
2508 2508
 
2509 2509
     $string = '';
2510 2510
     foreach ($strings as $value) {
@@ -2813,7 +2813,7 @@  discard block
 block discarded – undo
2813 2813
     $restOfWord = UTF8::substr($word, 1, null, $encoding);
2814 2814
     $firstCharacterUppercased = UTF8::strtoupper($firstCharacter, $encoding);
2815 2815
 
2816
-    return static::create($firstCharacterUppercased . $restOfWord, $encoding);
2816
+    return static::create($firstCharacterUppercased.$restOfWord, $encoding);
2817 2817
   }
2818 2818
 
2819 2819
   /**
Please login to merge, or discard this patch.