Skip to content

Commit

Permalink
Merge pull request #22 from retailcrm/remove-unused-params
Browse files Browse the repository at this point in the history
Remove unused params
  • Loading branch information
muxx authored Oct 1, 2024
2 parents 49f4161 + 5db9636 commit 8135dec
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 3,401 deletions.
109 changes: 0 additions & 109 deletions Annotation/ApiDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,6 @@ class ApiDoc
*/
private $route;

/**
* @var bool
*/
private $https = false;

/**
* @var bool
*/
private $authentication = false;

/**
* @var array
*/
private $authenticationRoles = [];

/**
* @var int
*/
private $cache;

/**
* @var bool
*/
Expand Down Expand Up @@ -272,20 +252,6 @@ public function __construct(array $data)
}
}

if (isset($data['authentication'])) {
$this->setAuthentication((bool) $data['authentication']);
}

if (isset($data['authenticationRoles'])) {
foreach ($data['authenticationRoles'] as $key => $role) {
$this->authenticationRoles[] = $role;
}
}

if (isset($data['cache'])) {
$this->setCache($data['cache']);
}

if (isset($data['section'])) {
$this->section = $data['section'];
}
Expand All @@ -308,10 +274,6 @@ public function __construct(array $data)
}
}

if (isset($data['https'])) {
$this->https = $data['https'];
}

if (isset($data['resourceDescription'])) {
$this->resourceDescription = $data['resourceDescription'];
}
Expand Down Expand Up @@ -542,70 +504,6 @@ public function setHost($host): void
$this->host = $host;
}

/**
* @return bool
*/
public function getHttps()
{
return $this->https;
}

/**
* @param bool $https
*/
public function setHttps($https): void
{
$this->https = $https;
}

/**
* @return bool
*/
public function getAuthentication()
{
return $this->authentication;
}

/**
* @param bool $authentication
*/
public function setAuthentication($authentication): void
{
$this->authentication = $authentication;
}

/**
* @return array
*/
public function getAuthenticationRoles()
{
return $this->authenticationRoles;
}

/**
* @param array $authenticationRoles
*/
public function setAuthenticationRoles($authenticationRoles): void
{
$this->authenticationRoles = $authenticationRoles;
}

/**
* @return int
*/
public function getCache()
{
return $this->cache;
}

/**
* @param int $cache
*/
public function setCache($cache): void
{
$this->cache = (int) $cache;
}

/**
* @return bool
*/
Expand Down Expand Up @@ -738,10 +636,6 @@ public function toArray()
$data['section'] = $section;
}

if ($cache = $this->cache) {
$data['cache'] = $cache;
}

if ($tags = $this->tags) {
$data['tags'] = $tags;
}
Expand All @@ -750,9 +644,6 @@ public function toArray()
$data['resourceDescription'] = $resourceDescription;
}

$data['https'] = $this->https;
$data['authentication'] = $this->authentication;
$data['authenticationRoles'] = $this->authenticationRoles;
$data['deprecated'] = $this->deprecated;
$data['scope'] = $this->scope;

Expand Down
3 changes: 1 addition & 2 deletions Extractor/ApiDocExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,8 @@ protected function mergeParameters($p1, $p2)
*/
protected function parseAnnotations(ApiDoc $annotation, Route $route, \ReflectionMethod $method): void
{
$annots = $this->reader->getMethodAnnotations($method);
foreach ($this->handlers as $handler) {
$handler->handle($annotation, $annots, $route, $method);
$handler->handle($annotation, $route, $method);
}
}

Expand Down
11 changes: 1 addition & 10 deletions Extractor/Handler/PhpDocHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(DocCommentExtractor $commentExtractor)
$this->commentExtractor = $commentExtractor;
}

public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method): void
public function handle(ApiDoc $annotation, Route $route, \ReflectionMethod $method): void
{
// description
if (null === $annotation->getDescription()) {
Expand All @@ -54,15 +54,6 @@ public function handle(ApiDoc $annotation, array $annotations, Route $route, \Re
'description' => '',
];
}

if ('_scheme' === $name) {
$https = ('https' == $value);
$annotation->setHttps($https);
}
}

if (method_exists($route, 'getSchemes')) {
$annotation->setHttps(in_array('https', $route->getSchemes()));
}

$paramDocs = [];
Expand Down
2 changes: 1 addition & 1 deletion Extractor/HandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ interface HandlerInterface
/**
* Parse route parameters in order to populate ApiDoc.
*/
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method);
public function handle(ApiDoc $annotation, Route $route, \ReflectionMethod $method);
}
2 changes: 0 additions & 2 deletions Resources/doc/the-apidoc-annotation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ The following properties are available:
* ``resource``: whether the method describes a main resource or not (default:
``false``);
* ``description``: a description of the API method;
* ``https``: whether the method described requires the https protocol (default:
``false``);
* ``deprecated``: allow to set method as deprecated (default: ``false``);
* ``tags``: allow to tag a method (e.g. ``beta`` or ``in-development``). Either
a single tag or an array of tags. Each tag can have an optional hex colorcode
Expand Down
11 changes: 2 additions & 9 deletions Resources/views/method.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
</span>
{% endif %}

{% if data.https %}
<span class="icon lock" title="HTTPS"></span>
{% endif %}
{% if data.authentication %}
<span class="icon keys" title="Needs {{ data.authenticationRoles|length > 0 ? data.authenticationRoles|join(', ') : 'authentication' }}"></span>
{% endif %}

<span class="path">
{% if data.host is defined -%}
{{ data.https ? 'https://' : 'http://' -}}
Expand Down Expand Up @@ -234,9 +227,9 @@
{% if enableSandbox %}
<div class="pane sandbox">
{% if app.request is not null and data.https and app.request.secure != data.https %}
Please reload the documentation using the scheme {% if data.https %}HTTPS{% else %}HTTP{% endif %} if you want to use the sandbox.
Please reload the documentation using the scheme HTTP if you want to use the sandbox.
{% else %}
<form method="" action="{% if data.host is defined %}{{ data.https ? 'https://' : 'http://' }}{{ data.host }}{% endif %}{{ data.uri }}">
<form method="" action="{% if data.host is defined %}http://{{ data.host }}{% endif %}{{ data.uri }}">
<fieldset class="parameters">
<legend>Input</legend>
{% if data.requirements is defined %}
Expand Down
26 changes: 0 additions & 26 deletions Tests/Annotation/ApiDocTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public function testConstructWithoutData(): void
$this->assertFalse(isset($array['requirements']));
$this->assertFalse(isset($array['parameters']));
$this->assertNull($annot->getInput());
$this->assertFalse($array['authentication']);
$this->assertFalse(isset($array['headers']));
$this->assertTrue(is_array($array['authenticationRoles']));
}

public function testConstructWithInvalidData(): void
Expand Down Expand Up @@ -205,30 +203,6 @@ public function testConstructWithStatusCodes(): void
}
}

public function testConstructWithAuthentication(): void
{
$data = [
'authentication' => true,
];

$annot = new ApiDoc($data);
$array = $annot->toArray();

$this->assertTrue($array['authentication']);
}

public function testConstructWithCache(): void
{
$data = [
'cache' => '60',
];

$annot = new ApiDoc($data);
$array = $annot->toArray();

$this->assertEquals($data['cache'], $array['cache']);
}

public function testConstructWithRequirements(): void
{
$data = [
Expand Down
17 changes: 1 addition & 16 deletions Tests/Extractor/ApiDocExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class ApiDocExtractorTest extends WebTestCase
{
private static $ROUTES_QUANTITY_DEFAULT = 28; // Routes in the default view
private static $ROUTES_QUANTITY_DEFAULT = 26; // Routes in the default view
private static $ROUTES_QUANTITY_PREMIUM = 5; // Routes in the premium view
private static $ROUTES_QUANTITY_TEST = 2; // Routes in the test view

Expand Down Expand Up @@ -161,21 +161,6 @@ public function testGetWithDocComment(): void
);
}

public function testGetWithAuthentication(): void
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::AuthenticatedAction', 'test_route_13');

$this->assertNotNull($annotation);
$this->assertTrue(
$annotation->getAuthentication()
);
$this->assertContains('ROLE_USER', $annotation->getAuthenticationRoles());
$this->assertContains('ROLE_FOOBAR', $annotation->getAuthenticationRoles());
$this->assertCount(2, $annotation->getAuthenticationRoles());
}

public function testGetWithDeprecated(): void
{
$container = $this->getContainer();
Expand Down
17 changes: 0 additions & 17 deletions Tests/Fixtures/Controller/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,6 @@ public function jmsReturnTestAction(): void
{
}

/**
* @ApiDoc()
*/
public function secureRouteAction(): void
{
}

/**
* @ApiDoc(
* authentication=true,
* authenticationRoles={"ROLE_USER","ROLE_FOOBAR"}
* )
*/
public function authenticatedAction(): void
{
}

/**
* @ApiDoc()
*/
Expand Down
9 changes: 0 additions & 9 deletions Tests/Fixtures/app/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ test_route_10:
methods: [GET]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::jmsReturnTestAction }

test_route_12:
path: /secure-route
schemes: [https]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::secureRouteAction }

test_route_13:
path: /authenticated
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::authenticatedAction }

test_service_route_1:
path: /tests.{_format}
methods: [GET]
Expand Down
3 changes: 0 additions & 3 deletions Tests/Formatter/SimpleFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public function testFormatOne(): void
'requirements' => [
'_format' => ['dataType' => '', 'description' => '', 'requirement' => ''],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [],
'deprecated' => false,
'scope' => null,
];
Expand Down
Loading

0 comments on commit 8135dec

Please sign in to comment.