Skip to content

Commit f970452

Browse files
committed
Give ignoreOtherAttributes a dedicated method
1 parent 85e0641 commit f970452

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/Analysers/AttributeAnnotationFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function build(\Reflector $reflector, Context $context): array
3636
/** @var OA\AbstractAnnotation[] $annotations */
3737
$annotations = [];
3838
try {
39-
$attributeArgs = $this->generator->getSetting('ignoreOtherAttributes')
39+
$attributeArgs = $this->generator->isIgnoreOtherAttributes()
4040
? [OA\AbstractAnnotation::class, \ReflectionAttribute::IS_INSTANCEOF]
4141
: [];
4242

src/Generator.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
*
2222
* This is an object-oriented alternative to using the now deprecated <code>\OpenApi\scan()</code> function and
2323
* static class properties of the <code>Analyzer</code> and <code>Analysis</code> classes.
24+
*
25+
* Supported generator config:
26+
* <code>
27+
* [
28+
* 'generator' => [
29+
* 'ignoreOtherAttributes' => true|false,
30+
* ]
31+
* ]
32+
* </code>
2433
*/
2534
class Generator
2635
{
@@ -156,12 +165,9 @@ public function getConfig(): array
156165
];
157166
}
158167

159-
/**
160-
* Get the value of a `Generator` setting.
161-
*/
162-
public function getSetting(string $name)
168+
public function isIgnoreOtherAttributes(): bool
163169
{
164-
return $this->getConfig()['generator'][$name] ?? null;
170+
return $this->getConfig()['generator']['ignoreOtherAttributes'];
165171
}
166172

167173
protected function normaliseConfig(array $config): array

tests/GeneratorTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,13 @@ public function testConfig(array $config, bool $expected): void
122122
$this->assertOperationIdHash($generator, $expected);
123123
}
124124

125-
public function testGetSetting(): void
125+
public function testIsIgnoreOtherAttributes(): void
126126
{
127127
$generator = new Generator();
128128

129-
// valid; default
130-
$this->assertFalse($generator->getSetting('ignoreOtherAttributes'));
129+
$this->assertFalse($generator->isIgnoreOtherAttributes());
131130

132-
// invalid
133-
$this->assertNull($generator->getSetting('invalid'));
131+
$generator->setConfig(['generator' => ['ignoreOtherAttributes' => true]]);
132+
$this->assertTrue($generator->isIgnoreOtherAttributes());
134133
}
135134
}

0 commit comments

Comments
 (0)