Skip to content

Commit 0b1c694

Browse files
committed
Cleanup styles, leave only Standard and Plural
1 parent a08a702 commit 0b1c694

29 files changed

+35
-896
lines changed

src/Styles/AbstractStyle.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Respect\Data\Styles;
66

7-
use function preg_match;
87
use function preg_quote;
98
use function preg_replace;
109
use function preg_replace_callback;
@@ -27,34 +26,4 @@ protected function separatorToCamelCase(string $name, string $separator = '_'):
2726
$name,
2827
);
2928
}
30-
31-
protected function pluralToSingular(string $name): string
32-
{
33-
$replacements = [
34-
'/^(.+)ies$/' => '$1y',
35-
'/^(.+)s$/' => '$1',
36-
];
37-
foreach ($replacements as $key => $value) {
38-
if (preg_match($key, $name)) {
39-
return (string) preg_replace($key, $value, $name);
40-
}
41-
}
42-
43-
return $name;
44-
}
45-
46-
protected function singularToPlural(string $name): string
47-
{
48-
$replacements = [
49-
'/^(.+)y$/' => '$1ies',
50-
'/^(.+)([^s])$/' => '$1$2s',
51-
];
52-
foreach ($replacements as $key => $value) {
53-
if (preg_match($key, $name)) {
54-
return (string) preg_replace($key, $value, $name);
55-
}
56-
}
57-
58-
return $name;
59-
}
6029
}

src/Styles/CakePHP.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/Styles/NorthWind.php

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/Styles/Plural.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use function array_map;
88
use function explode;
99
use function implode;
10+
use function preg_match;
11+
use function preg_replace;
1012
use function strtolower;
1113
use function substr;
1214
use function ucfirst;
@@ -52,4 +54,34 @@ public function composed(string $left, string $right): string
5254
{
5355
return $this->singularToPlural($left) . '_' . $this->singularToPlural($right);
5456
}
57+
58+
private function pluralToSingular(string $name): string
59+
{
60+
$replacements = [
61+
'/^(.+)ies$/' => '$1y',
62+
'/^(.+)s$/' => '$1',
63+
];
64+
foreach ($replacements as $key => $value) {
65+
if (preg_match($key, $name)) {
66+
return (string) preg_replace($key, $value, $name);
67+
}
68+
}
69+
70+
return $name;
71+
}
72+
73+
private function singularToPlural(string $name): string
74+
{
75+
$replacements = [
76+
'/^(.+)y$/' => '$1ies',
77+
'/^(.+)([^s])$/' => '$1$2s',
78+
];
79+
foreach ($replacements as $key => $value) {
80+
if (preg_match($key, $name)) {
81+
return (string) preg_replace($key, $value, $name);
82+
}
83+
}
84+
85+
return $name;
86+
}
5587
}

src/Styles/Sakila.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/AbstractMapperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use ReflectionObject;
1111
use Respect\Data\Collections\Collection;
1212
use Respect\Data\Hydrators\Nested;
13-
use Respect\Data\Styles\CakePHP;
13+
use Respect\Data\Styles\Plural;
1414
use Respect\Data\Styles\Standard;
1515
use SplObjectStorage;
1616

@@ -92,7 +92,7 @@ public function getStyleShouldReturnSameInstanceOnSubsequentCalls(): void
9292
#[Test]
9393
public function styleShouldComeFromEntityFactory(): void
9494
{
95-
$style = new CakePHP();
95+
$style = new Plural();
9696
$mapper = new class (new Nested(new EntityFactory(style: $style))) extends AbstractMapper {
9797
public function flush(): void
9898
{

tests/EntityFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function createAndCopySkipsUninitializedSourceProperties(): void
129129
#[Test]
130130
public function getStyleReturnsConfiguredStyle(): void
131131
{
132-
$style = new Styles\CakePHP();
132+
$style = new Styles\Plural();
133133
$factory = new EntityFactory(style: $style);
134134
$this->assertSame($style, $factory->style);
135135
}

tests/Styles/AbstractStyleTest.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,6 @@ public function isRelationProperty(string $name): bool
7474
};
7575
}
7676

77-
/** @return array<array{string, string}> */
78-
public static function singularPluralProvider(): array
79-
{
80-
return [
81-
['post', 'posts'],
82-
['comment', 'comments'],
83-
['category', 'categories'],
84-
['tag', 'tags'],
85-
['entity', 'entities'],
86-
];
87-
}
88-
8977
/** @return array<array{string, string, string}> */
9078
public static function camelCaseToSeparatorProvider(): array
9179
{
@@ -96,16 +84,6 @@ public static function camelCaseToSeparatorProvider(): array
9684
];
9785
}
9886

99-
#[DataProvider('singularPluralProvider')]
100-
public function testPluralToSingularAndViceVersa(string $singular, string $plural): void
101-
{
102-
$pluralToSingular = new ReflectionMethod($this->style, 'pluralToSingular');
103-
$this->assertEquals($singular, $pluralToSingular->invoke($this->style, $plural));
104-
105-
$singularToPlural = new ReflectionMethod($this->style, 'singularToPlural');
106-
$this->assertEquals($plural, $singularToPlural->invoke($this->style, $singular));
107-
}
108-
10987
#[DataProvider('camelCaseToSeparatorProvider')]
11088
public function testCamelCaseToSeparatorAndViceVersa(
11189
string $separator,
@@ -124,16 +102,4 @@ public function testCamelCaseToSeparatorAndViceVersa(
124102
$separatorToCamelCaseMethod->invoke($this->style, $separated, $separator),
125103
);
126104
}
127-
128-
public function testPluralToSingularReturnsUnchangedWhenNoMatch(): void
129-
{
130-
$method = new ReflectionMethod($this->style, 'pluralToSingular');
131-
$this->assertEquals('fox', $method->invoke($this->style, 'fox'));
132-
}
133-
134-
public function testSingularToPluralReturnsUnchangedWhenNoMatch(): void
135-
{
136-
$method = new ReflectionMethod($this->style, 'singularToPlural');
137-
$this->assertEquals('news', $method->invoke($this->style, 'news'));
138-
}
139105
}

tests/Styles/CakePHP/Author.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/Styles/CakePHP/CakePHPIntegrationTest.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)