Skip to content

Commit 68ea60b

Browse files
authored
Remove configuration class (#80)
1 parent 29b045b commit 68ea60b

File tree

4 files changed

+12
-176
lines changed

4 files changed

+12
-176
lines changed

src/Parser/Configuration.php

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

src/Parser/Parser.php

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace webignition\InternetMediaType\Parser;
44

55
use webignition\InternetMediaType\InternetMediaType;
6-
use webignition\InternetMediaType\Parameter\Parameter;
76
use webignition\InternetMediaType\Parameter\Parser\AttributeFixer;
87
use webignition\InternetMediaType\Parameter\Parser\AttributeParser;
98
use webignition\InternetMediaType\Parameter\Parser\AttributeParserException;
@@ -24,7 +23,8 @@ class Parser
2423
public const TYPE_SUBTYPE_SEPARATOR = '/';
2524
public const TYPE_PARAMETER_SEPARATOR = ';';
2625

27-
private Configuration $configuration;
26+
private bool $ignoreInvalidAttributes = false;
27+
private bool $attemptToRecoverFromInvalidInternalCharacter = false;
2828
private bool $hasAttemptedToFixSubtypeInvalidInternalCharacter = false;
2929
private bool $hasAttemptedToFixAttributeInvalidInternalCharacter = false;
3030

@@ -35,7 +35,6 @@ public function __construct(
3535
private TypeFixer $typeFixer,
3636
private AttributeFixer $attributeFixer,
3737
) {
38-
$this->configuration = new Configuration();
3938
}
4039

4140
public static function create(): Parser
@@ -110,33 +109,15 @@ public function parse(string $internetMediaTypeString): ?InternetMediaTypeInterf
110109
}
111110
}
112111

113-
public function setConfiguration(Configuration $configuration): void
114-
{
115-
$this->configuration = $configuration;
116-
}
117-
118-
public function getConfiguration(): Configuration
119-
{
120-
return $this->configuration;
121-
}
122-
123112
public function setIgnoreInvalidAttributes(bool $ignoreInvalidAttributes): void
124113
{
125-
if (filter_var($ignoreInvalidAttributes, FILTER_VALIDATE_BOOLEAN)) {
126-
$this->getConfiguration()->enableIgnoreInvalidAttributes();
127-
} else {
128-
$this->getConfiguration()->disableIgnoreInvalidAttributes();
129-
}
114+
$this->ignoreInvalidAttributes = $ignoreInvalidAttributes;
130115
}
131116

132117
public function setAttemptToRecoverFromInvalidInternalCharacter(
133118
bool $attemptToRecoverFromInvalidInternalCharacter
134119
): void {
135-
if (filter_var($attemptToRecoverFromInvalidInternalCharacter, FILTER_VALIDATE_BOOLEAN)) {
136-
$this->getConfiguration()->enableAttemptToRecoverFromInvalidInternalCharacter();
137-
} else {
138-
$this->getConfiguration()->disableAttemptToRecoverFromInvalidInternalCharacter();
139-
}
120+
$this->attemptToRecoverFromInvalidInternalCharacter = $attemptToRecoverFromInvalidInternalCharacter;
140121
}
141122

142123
private function createParameterString(string $inputString, string $type, string $subtype): string
@@ -205,7 +186,7 @@ private function parseSubtype(string $inputString): string
205186
return $this->subtypeParser->parse($inputString);
206187
} catch (SubtypeParserException $subtypeParserException) {
207188
$shouldAttemptToFixInvalidInternalCharacter =
208-
$this->getConfiguration()->attemptToRecoverFromInvalidInternalCharacter()
189+
$this->attemptToRecoverFromInvalidInternalCharacter
209190
&& !$this->hasAttemptedToFixSubtypeInvalidInternalCharacter;
210191

211192
if ($shouldAttemptToFixInvalidInternalCharacter) {
@@ -218,6 +199,8 @@ private function parseSubtype(string $inputString): string
218199
}
219200
}
220201

202+
$this->hasAttemptedToFixSubtypeInvalidInternalCharacter = false;
203+
221204
throw $subtypeParserException;
222205
}
223206
}
@@ -232,13 +215,12 @@ private function parseParameterString(string $parameterString): ?ParameterInterf
232215
try {
233216
return $this->parameterParser->parse($parameterString);
234217
} catch (AttributeParserException $attributeParserException) {
235-
$shouldIgnoreInvalidAttributes = $this->getConfiguration()->ignoreInvalidAttributes();
236-
if ($shouldIgnoreInvalidAttributes) {
218+
if ($this->ignoreInvalidAttributes) {
237219
return null;
238220
}
239221

240222
$shouldAttemptToFixInvalidInternalCharacter =
241-
$this->getConfiguration()->attemptToRecoverFromInvalidInternalCharacter()
223+
$this->attemptToRecoverFromInvalidInternalCharacter
242224
&& !$this->hasAttemptedToFixAttributeInvalidInternalCharacter;
243225

244226
if ($shouldAttemptToFixInvalidInternalCharacter) {
@@ -249,6 +231,8 @@ private function parseParameterString(string $parameterString): ?ParameterInterf
249231
return $this->parameterParser->parse($fixedInputString);
250232
}
251233

234+
$this->hasAttemptedToFixAttributeInvalidInternalCharacter = false;
235+
252236
throw $attributeParserException;
253237
}
254238
}

tests/Parser/ConfigurationTest.php

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

tests/Parser/ParserTest.php

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPUnit\Framework\TestCase;
66
use webignition\InternetMediaType\Parameter\Parser\AttributeParserException;
7-
use webignition\InternetMediaType\Parser\Configuration;
87
use webignition\InternetMediaType\Parser\ParseException;
98
use webignition\InternetMediaType\Parser\Parser;
109
use webignition\InternetMediaType\Parser\SubtypeParserException;
@@ -137,7 +136,7 @@ public function testParseAndFixInvalidMediaType(
137136
string $expectedSubtype,
138137
array $expectedParameters
139138
): void {
140-
$this->parser->getConfiguration()->enableAttemptToRecoverFromInvalidInternalCharacter();
139+
$this->parser->setAttemptToRecoverFromInvalidInternalCharacter(true);
141140
$internetMediaType = $this->parser->parse($internetMediaTypeString);
142141
self::assertInstanceOf(InternetMediaTypeInterface::class, $internetMediaType);
143142

@@ -199,68 +198,6 @@ public function parseAndFixInvalidMediaTypeDataProvider(): array
199198
];
200199
}
201200

202-
public function testSetConfiguration(): void
203-
{
204-
$configuration = new Configuration();
205-
206-
$this->assertNotEquals(spl_object_hash($configuration), spl_object_hash($this->parser->getConfiguration()));
207-
208-
$this->parser->setConfiguration($configuration);
209-
$this->assertEquals(spl_object_hash($configuration), spl_object_hash($this->parser->getConfiguration()));
210-
}
211-
212-
/**
213-
* @dataProvider setIgnoreInvalidAttributesDataProvider
214-
*/
215-
public function testSetIgnoreInvalidAttributes(bool $ignoreInvalidAttributes): void
216-
{
217-
$this->parser->setIgnoreInvalidAttributes($ignoreInvalidAttributes);
218-
$this->assertEquals($ignoreInvalidAttributes, $this->parser->getConfiguration()->ignoreInvalidAttributes());
219-
}
220-
221-
/**
222-
* @return array<mixed>
223-
*/
224-
public function setIgnoreInvalidAttributesDataProvider(): array
225-
{
226-
return [
227-
'true' => [
228-
'ignoreInvalidAttributes' => true,
229-
],
230-
'false' => [
231-
'ignoreInvalidAttributes' => false,
232-
],
233-
];
234-
}
235-
236-
/**
237-
* @dataProvider setAttemptToRecoverFromInvalidInternalCharacterDataProvider
238-
*/
239-
public function testSetAttemptToRecoverFromInvalidInternalCharacter(
240-
bool $attemptToRecoverFromInvalidInternalCharacter
241-
): void {
242-
$this->parser->setAttemptToRecoverFromInvalidInternalCharacter($attemptToRecoverFromInvalidInternalCharacter);
243-
$this->assertEquals(
244-
$attemptToRecoverFromInvalidInternalCharacter,
245-
$this->parser->getConfiguration()->attemptToRecoverFromInvalidInternalCharacter()
246-
);
247-
}
248-
249-
/**
250-
* @return array<mixed>
251-
*/
252-
public function setAttemptToRecoverFromInvalidInternalCharacterDataProvider(): array
253-
{
254-
return [
255-
'true' => [
256-
'attemptToRecoverFromInvalidInternalCharacter' => true,
257-
],
258-
'false' => [
259-
'attemptToRecoverFromInvalidInternalCharacter' => false,
260-
],
261-
];
262-
}
263-
264201
/**
265202
* @dataProvider parseThrowsExceptionDataProvider
266203
*

0 commit comments

Comments
 (0)