From ce2ba9b3fca493b349c6144adc50257abd5dc929 Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Tue, 11 Jun 2024 17:15:38 +1200 Subject: [PATCH] Remove `deprecated` features --- src/Context.php | 43 -------------------- src/Generator.php | 89 ----------------------------------------- src/Pipeline.php | 8 ---- tests/ContextTest.php | 12 ------ tests/GeneratorTest.php | 50 ----------------------- 5 files changed, 202 deletions(-) diff --git a/src/Context.php b/src/Context.php index 616b1f4a..da4e6cbc 100644 --- a/src/Context.php +++ b/src/Context.php @@ -50,14 +50,6 @@ class Context */ private ?Context $parent; - /** - * @deprecated - */ - public function clone() - { - return new Context(get_object_vars($this), $this->parent); - } - public function __construct(array $properties = [], ?Context $parent = null) { foreach ($properties as $property => $value) { @@ -208,41 +200,6 @@ public function __debugInfo() return ['-' => $this->getDebugLocation()]; } - /** - * Create a Context based on `debug_backtrace`. - * - * @deprecated - */ - public static function detect(int $index = 0): Context - { - $context = new Context(); - $backtrace = debug_backtrace(); - $position = $backtrace[$index]; - if (isset($position['file'])) { - $context->filename = $position['file']; - } - if (isset($position['line'])) { - $context->line = $position['line']; - } - $caller = $backtrace[$index + 1] ?? null; - if (isset($caller['function'])) { - $context->method = $caller['function']; - if (isset($caller['type']) && $caller['type'] === '::') { - $context->static = true; - } - } - if (isset($caller['class'])) { - $fqn = explode('\\', $caller['class']); - $context->class = array_pop($fqn); - if ($fqn !== []) { - $context->namespace = implode('\\', $fqn); - } - } - - // @todo extract namespaces and use statements - return $context; - } - /** * Resolve the fully qualified name. */ diff --git a/src/Generator.php b/src/Generator.php index becc085c..ee46aeee 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -12,7 +12,6 @@ use OpenApi\Analysers\ReflectionAnalyser; use OpenApi\Annotations as OA; use OpenApi\Loggers\DefaultLogger; -use OpenApi\Processors\ProcessorInterface; use Psr\Log\LoggerInterface; /** @@ -252,94 +251,6 @@ public function withProcessor(callable $with): Generator return $this; } - /** - * @return array - * - * @deprecated - */ - public function getProcessors(): array - { - return $this->getProcessorPipeline()->pipes(); - } - - /** - * @param array|null $processors - * - * @deprecated - */ - public function setProcessors(?array $processors): Generator - { - $this->processorPipeline = null !== $processors ? new Pipeline($processors) : null; - - return $this; - } - - /** - * @param callable|ProcessorInterface $processor - * @param class-string|null $before - * - * @deprecated - */ - public function addProcessor($processor, ?string $before = null): Generator - { - $processors = $this->processorPipeline ?: $this->getProcessorPipeline(); - if (!$before) { - $processors->add($processor); - } else { - $matcher = function (array $pipes) use ($before) { - foreach ($pipes as $ii => $current) { - if ($current instanceof $before) { - return $ii; - } - } - - return null; - }; - $processors->insert($processor, $matcher); - } - - $this->processorPipeline = $processors; - - return $this; - } - - /** - * @param callable|ProcessorInterface $processor - * - * @deprecated - */ - public function removeProcessor($processor, bool $silent = false): Generator - { - $processors = $this->processorPipeline ?: $this->getProcessorPipeline(); - $processors->remove($processor); - $this->processorPipeline = $processors; - - return $this; - } - - /** - * Update/replace an existing processor with a new one. - * - * @param ProcessorInterface|callable $processor the new processor - * @param null|callable $matcher Optional matcher callable to identify the processor to replace. - * If none given, matching is based on the processors class. - * - * @deprecated - */ - public function updateProcessor($processor, ?callable $matcher = null): Generator - { - $matcher = $matcher ?: function ($other) use ($processor): bool { - $otherClass = get_class($other); - - return $processor instanceof $otherClass; - }; - - $processors = array_map(fn ($other) => $matcher($other) ? $processor : $other, $this->getProcessors()); - $this->setProcessors($processors); - - return $this; - } - public function getLogger(): ?LoggerInterface { return $this->logger ?: new DefaultLogger(); diff --git a/src/Pipeline.php b/src/Pipeline.php index a6fe60aa..3909868b 100644 --- a/src/Pipeline.php +++ b/src/Pipeline.php @@ -18,14 +18,6 @@ public function __construct(array $pipes = []) $this->pipes = $pipes; } - /** - * @deprecated This will be removed in 5.0 - */ - public function pipes(): array - { - return $this->pipes; - } - public function add(callable $pipe): Pipeline { $this->pipes[] = $pipe; diff --git a/tests/ContextTest.php b/tests/ContextTest.php index 229ee243..4f11ba7c 100644 --- a/tests/ContextTest.php +++ b/tests/ContextTest.php @@ -14,18 +14,6 @@ class ContextTest extends OpenApiTestCase { - public function testDetect(): void - { - $context = Context::detect(); - $line = __LINE__ - 1; - $this->assertSame('ContextTest', $context->class); - $this->assertSame('\\OpenApi\\Tests\\ContextTest', $context->fullyQualifiedName($context->class)); - $this->assertSame('testDetect', $context->method); - $this->assertSame(__FILE__, $context->filename); - $this->assertSame($line, $context->line); - $this->assertSame('OpenApi\\Tests', $context->namespace); - } - public function testFullyQualifiedName(): void { $this->assertOpenApiLogEntryContains('Required @OA\PathItem() not found'); diff --git a/tests/GeneratorTest.php b/tests/GeneratorTest.php index 09d1b97f..8afe629b 100644 --- a/tests/GeneratorTest.php +++ b/tests/GeneratorTest.php @@ -6,7 +6,6 @@ namespace OpenApi\Tests; -use OpenApi\Analysis; use OpenApi\Generator; use OpenApi\Processors\OperationId; use OpenApi\Util; @@ -55,30 +54,6 @@ public static function processorCases(): iterable ]; } - /** - * @dataProvider processorCases - */ - public function testUpdateProcessor($p, bool $expected): void - { - $generator = (new Generator()) - ->updateProcessor($p); - foreach ($generator->getProcessors() as $processor) { - if ($processor instanceof OperationId) { - $this->assertEquals($expected, $processor->isHash()); - } - } - } - - public function testAddProcessor(): void - { - $generator = new Generator(); - $processors = $generator->getProcessors(); - $generator->addProcessor(function (Analysis $analysis) { - }); - - $this->assertLessThan(count($generator->getProcessors()), count($processors)); - } - public function testAddAlias(): void { $generator = new Generator(); @@ -95,18 +70,6 @@ public function testAddNamespace(): void $this->assertEquals(['OpenApi\\Annotations\\', 'Foo\\Bar\\'], $generator->getNamespaces()); } - public function testRemoveProcessor(): void - { - $generator = new Generator(); - $processors = $generator->getProcessors(); - $processor = function (Analysis $analysis): void { - }; - $generator->addProcessor($processor); - $generator->removeProcessor($processor); - - $this->assertEquals($processors, $generator->getProcessors()); - } - protected function assertOperationIdHash(Generator $generator, bool $expected): void { $generator->getProcessorPipeline()->walk(function ($processor) use ($expected) { @@ -137,17 +100,4 @@ public function testConfig(array $config, bool $expected): void $generator->setConfig($config); $this->assertOperationIdHash($generator, $expected); } - - public function testCallableProcessor(): void - { - $generator = new Generator(); - // not the default - $operationId = new OperationId(false); - $generator->addProcessor(function (Analysis $analysis) use ($operationId) { - $operationId($analysis); - }); - - $this->assertOperationIdHash($generator, true); - $this->assertFalse($operationId->isHash()); - } }