Skip to content

Commit edb8b0a

Browse files
jzawadzkijrushlow
authored andcommitted
Changed behaviour of Str::addSuffix, so it doesn't care about duplicated suffixes
1 parent 08b21c3 commit edb8b0a

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/Str.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ public static function hasSuffix(string $value, string $suffix): bool
3232
}
3333

3434
/**
35-
* Ensures that the given string ends with the given suffix. If the string
36-
* already contains the suffix, it's not added twice. It's case-insensitive
37-
* (e.g. value: 'Foocommand' suffix: 'Command' -> result: 'FooCommand').
35+
* Ensures that the given string ends with the given suffix.
3836
*/
3937
public static function addSuffix(string $value, string $suffix): string
4038
{
41-
return self::removeSuffix($value, $suffix).$suffix;
39+
return $value.$suffix;
4240
}
4341

4442
/**

tests/GeneratorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,13 @@ public function getClassNameDetailsTests(): \Generator
100100
'Symfony\\Bundle\\MakerBundle\\Tests\\GeneratorTest',
101101
'Symfony\\Bundle\\MakerBundle\\Tests\\GeneratorTest',
102102
];
103+
104+
yield 'repository_fqcn' => [
105+
'Repository',
106+
'Repository\\',
107+
'Repository',
108+
'App\\Repository\\RepositoryRepository',
109+
'RepositoryRepository',
110+
];
103111
}
104112
}

tests/StrTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ public function provideAddSuffix()
6262
{
6363
yield ['', '', ''];
6464
yield ['GenerateCommand', '', 'GenerateCommand'];
65-
yield ['GenerateCommand', 'Command', 'GenerateCommand'];
66-
yield ['GenerateCommand', 'command', 'Generatecommand'];
67-
yield ['Generatecommand', 'Command', 'GenerateCommand'];
68-
yield ['Generatecommand', 'command', 'Generatecommand'];
69-
yield ['GenerateCommandCommand', 'Command', 'GenerateCommandCommand'];
70-
yield ['GenerateCommandcommand', 'Command', 'GenerateCommandCommand'];
65+
yield ['GenerateCommand', 'Command', 'GenerateCommandCommand'];
66+
yield ['GenerateCommand', 'command', 'GenerateCommandcommand'];
67+
yield ['Generatecommand', 'Command', 'GeneratecommandCommand'];
68+
yield ['Generatecommand', 'command', 'Generatecommandcommand'];
69+
yield ['GenerateCommandCommand', 'Command', 'GenerateCommandCommandCommand'];
70+
yield ['GenerateCommandcommand', 'Command', 'GenerateCommandcommandCommand'];
7171
yield ['Generate', 'command', 'Generatecommand'];
7272
yield ['Generate', 'Command', 'GenerateCommand'];
7373
}
@@ -95,7 +95,7 @@ public function provideAsClassName()
9595
yield ['gen-erate:Co-mman-d', '', 'GenErateCoMmanD'];
9696
yield ['generate', 'Command', 'GenerateCommand'];
9797
yield ['app:generate', 'Command', 'AppGenerateCommand'];
98-
yield ['app:generate:command', 'Command', 'AppGenerateCommand'];
98+
yield ['app:generate:command', 'Command', 'AppGenerateCommandCommand'];
9999
}
100100

101101
public function provideAsTwigVariable()

0 commit comments

Comments
 (0)