|
18 | 18 | final class Str
|
19 | 19 | {
|
20 | 20 | /**
|
21 |
| - * Looks for suffixes in a case-insensitive way. |
| 21 | + * Looks for suffixes in strings in a case-insensitive way. |
22 | 22 | */
|
23 | 23 | public static function hasSuffix(string $value, string $suffix): bool
|
24 | 24 | {
|
25 | 25 | return 0 === strcasecmp($suffix, substr($value, -strlen($suffix)));
|
26 | 26 | }
|
27 | 27 |
|
28 | 28 | /**
|
29 |
| - * Ensures that the given string ends with the given suffix. It works in a |
30 |
| - * case-insensitive way (e.g. value: 'Foocommand' suffix: 'Command' -> result: 'FooCommand' |
| 29 | + * Ensures that the given string ends with the given suffix. If the string |
| 30 | + * already contains the suffix, it's not added twice. It's case-insensitive |
| 31 | + * (e.g. value: 'Foocommand' suffix: 'Command' -> result: 'FooCommand') |
31 | 32 | */
|
32 | 33 | public static function addSuffix(string $value, string $suffix): string
|
33 | 34 | {
|
34 | 35 | return self::removeSuffix($value, $suffix).$suffix;
|
35 | 36 | }
|
36 | 37 |
|
37 | 38 | /**
|
38 |
| - * Ensures that the given string doesn't end with the given suffix. It works in a |
39 |
| - * case-insensitive way (e.g. value: 'Foocommand' suffix: 'Command' -> result: 'Foo' |
| 39 | + * Ensures that the given string doesn't end with the given suffix. If the |
| 40 | + * string contains the suffix multiple times, only the last one is removed. |
| 41 | + * It's case-insensitive (e.g. value: 'Foocommand' suffix: 'Command' -> result: 'Foo' |
40 | 42 | */
|
41 | 43 | public static function removeSuffix(string $value, string $suffix): string
|
42 | 44 | {
|
43 | 45 | return self::hasSuffix($value, $suffix) ? substr($value, 0, -strlen($suffix)) : $value;
|
44 | 46 | }
|
45 | 47 |
|
46 | 48 | /**
|
47 |
| - * Transforms the given string into the format commonly used by PHP classes |
48 |
| - * (e.g. `app:do_this-and_that` -> `AppDoThisAndThat`) |
| 49 | + * Transforms the given string into the format commonly used by PHP classes, |
| 50 | + * (e.g. `app:do_this-and_that` -> `AppDoThisAndThat`) but it doesn't check |
| 51 | + * the validity of the class name. |
49 | 52 | */
|
50 | 53 | public static function asClassName(string $value, string $suffix = ''): string
|
51 | 54 | {
|
|
0 commit comments