Skip to content

Commit

Permalink
Remove deprecated features
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Jul 16, 2024
1 parent 1e2757c commit 4c2bbe2
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 202 deletions.
43 changes: 0 additions & 43 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
*/
Expand Down
89 changes: 0 additions & 89 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -267,94 +266,6 @@ public function withProcessor(callable $with): Generator
return $this;
}

/**
* @return array<ProcessorInterface|callable>
*
* @deprecated
*/
public function getProcessors(): array
{
return $this->getProcessorPipeline()->pipes();
}

/**
* @param array<ProcessorInterface|callable>|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();
Expand Down
8 changes: 0 additions & 8 deletions src/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 0 additions & 12 deletions tests/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
50 changes: 0 additions & 50 deletions tests/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace OpenApi\Tests;

use OpenApi\Analysis;
use OpenApi\Generator;
use OpenApi\Processors\OperationId;
use OpenApi\Util;
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 4c2bbe2

Please sign in to comment.