Skip to content

Commit

Permalink
Remove deprecated code and related code cleanup
Browse files Browse the repository at this point in the history
- `Logger`
- `Processors/InheritProperties'
- `Processors/InheritTraits'
- `Processors/MergeTraits'
- functions.php (includes UNDEFINED consts)
- processor list related code in `Analysis`
  • Loading branch information
DerManoMann committed Sep 7, 2021
1 parent a020a41 commit a953cb5
Show file tree
Hide file tree
Showing 42 changed files with 218 additions and 685 deletions.
6 changes: 4 additions & 2 deletions Examples/processors/schema-query-parameter/scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
// also load our custom processor...
require __DIR__ . '/SchemaQueryParameter.php';

$generator = new OpenApi\Generator();

// merge our custom processor
$processors = [];
foreach (\OpenApi\Analysis::processors() as $processor) {
foreach ($generator->getProcessors() as $processor) {
$processors[] = $processor;
if ($processor instanceof \OpenApi\Processors\BuildPaths) {
$processors[] = new \SchemaQueryParameterProcessor\SchemaQueryParameter();
Expand All @@ -17,7 +19,7 @@
'processors' => $processors,
];

$openapi = (new OpenApi\Generator())
$openapi = $generator
->setProcessors($processors)
->generate([__DIR__ . '/app']);
$spec = json_encode($openapi, JSON_PRETTY_PRINT);
Expand Down
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
"autoload": {
"psr-4": {
"OpenApi\\": "src"
},
"files": [
"src/functions.php"
]
}
},
"require-dev": {
"composer/package-versions-deprecated": "1.11.99.2",
Expand Down
79 changes: 0 additions & 79 deletions src/Analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@
use OpenApi\Annotations\AbstractAnnotation;
use OpenApi\Annotations\OpenApi;
use OpenApi\Annotations\Schema;
use OpenApi\Processors\AugmentParameters;
use OpenApi\Processors\AugmentProperties;
use OpenApi\Processors\AugmentSchemas;
use OpenApi\Processors\BuildPaths;
use OpenApi\Processors\CleanUnmerged;
use OpenApi\Processors\DocBlockDescriptions;
use OpenApi\Processors\ExpandInterfaces;
use OpenApi\Processors\ExpandClasses;
use OpenApi\Processors\ExpandTraits;
use OpenApi\Processors\MergeIntoComponents;
use OpenApi\Processors\MergeIntoOpenApi;
use OpenApi\Processors\MergeJsonContent;
use OpenApi\Processors\MergeXmlContent;
use OpenApi\Processors\OperationId;

/**
* Result of the analyser.
Expand Down Expand Up @@ -430,10 +416,6 @@ public function split()
*/
public function process($processors = null): void
{
if ($processors === null) {
// Use the default and registered processors.
$processors = self::processors();
}
if (is_array($processors) === false && is_callable($processors)) {
$processors = [$processors];
}
Expand All @@ -442,67 +424,6 @@ public function process($processors = null): void
}
}

/**
* Get direct access to the processors array.
*
* @return array reference
*
* @deprecated Superseded by `Generator` methods
*/
public static function &processors()
{
if (!self::$processors) {
// Add default processors.
self::$processors = [
new DocBlockDescriptions(),
new MergeIntoOpenApi(),
new MergeIntoComponents(),
new ExpandClasses(),
new ExpandInterfaces(),
new ExpandTraits(),
new AugmentSchemas(),
new AugmentProperties(),
new BuildPaths(),
new AugmentParameters(),
new MergeJsonContent(),
new MergeXmlContent(),
new OperationId(),
new CleanUnmerged(),
];
}

return self::$processors;
}

/**
* Register a processor.
*
* @param \Closure $processor
*
* @deprecated Superseded by `Generator` methods
*/
public static function registerProcessor($processor): void
{
array_push(self::processors(), $processor);
}

/**
* Unregister a processor.
*
* @param \Closure $processor
*
* @deprecated Superseded by `Generator` methods
*/
public static function unregisterProcessor($processor): void
{
$processors = &self::processors();
$key = array_search($processor, $processors, true);
if ($key === false) {
throw new \Exception('Given processor was not registered');
}
unset($processors[$key]);
}

public function validate(): bool
{
if ($this->openapi !== null) {
Expand Down
35 changes: 34 additions & 1 deletion src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
use OpenApi\Analysers\TokenAnalyser;
use OpenApi\Annotations\OpenApi;
use OpenApi\Loggers\DefaultLogger;
use OpenApi\Processors\AugmentParameters;
use OpenApi\Processors\AugmentProperties;
use OpenApi\Processors\AugmentSchemas;
use OpenApi\Processors\BuildPaths;
use OpenApi\Processors\CleanUnmerged;
use OpenApi\Processors\DocBlockDescriptions;
use OpenApi\Processors\ExpandClasses;
use OpenApi\Processors\ExpandInterfaces;
use OpenApi\Processors\ExpandTraits;
use OpenApi\Processors\MergeIntoComponents;
use OpenApi\Processors\MergeIntoOpenApi;
use OpenApi\Processors\MergeJsonContent;
use OpenApi\Processors\MergeXmlContent;
use OpenApi\Processors\OperationId;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -128,7 +142,26 @@ public function setAnalyser(?AnalyserInterface $analyser): Generator
*/
public function getProcessors(): array
{
return null !== $this->processors ? $this->processors : Analysis::processors();
if (null === $this->processors) {
$this->processors = [
new DocBlockDescriptions(),
new MergeIntoOpenApi(),
new MergeIntoComponents(),
new ExpandClasses(),
new ExpandInterfaces(),
new ExpandTraits(),
new AugmentSchemas(),
new AugmentProperties(),
new BuildPaths(),
new AugmentParameters(),
new MergeJsonContent(),
new MergeXmlContent(),
new OperationId(),
new CleanUnmerged(),
];
}

return $this->processors;
}

/**
Expand Down
84 changes: 0 additions & 84 deletions src/Logger.php

This file was deleted.

12 changes: 8 additions & 4 deletions src/Loggers/DefaultLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace OpenApi\Loggers;

use OpenApi\Logger;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
Expand All @@ -15,11 +14,16 @@ class DefaultLogger extends AbstractLogger implements LoggerInterface
{
public function log($level, $message, array $context = [])
{
// BC: delegate to the static instance
if ($message instanceof \Exception) {
$message = $message->getMessage();
}

if (in_array($level, [LogLevel::NOTICE, LogLevel::INFO, LogLevel::DEBUG])) {
Logger::notice($message);
$error_level = E_USER_NOTICE;
} else {
Logger::warning($message);
$error_level = E_USER_WARNING;
}

trigger_error($message, $error_level);
}
}
Loading

0 comments on commit a953cb5

Please sign in to comment.