mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-08 18:49:26 +03:00
Fix CS
This commit is contained in:
parent
f94d6403f5
commit
d7fd929379
@ -482,6 +482,7 @@ class ApiDoc
|
||||
public function setDeprecated($deprecated)
|
||||
{
|
||||
$this->deprecated = (bool) $deprecated;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
|
||||
class ExtractorHandlerCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
@ -25,13 +24,11 @@ class ExtractorHandlerCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
$handlers = array();
|
||||
foreach ($container->findTaggedServiceIds('nelmio_api_doc.extractor.handler') as $id => $attributes) {
|
||||
|
||||
// Adding handlers from tagged services
|
||||
$handlers[] = new Reference($id);
|
||||
}
|
||||
$definition = $container->getDefinition(
|
||||
'nelmio_api_doc.extractor.api_doc_extractor'
|
||||
);
|
||||
$definition->replaceArgument(4, $handlers);
|
||||
|
||||
$container
|
||||
->getDefinition('nelmio_api_doc.extractor.api_doc_extractor')
|
||||
->replaceArgument(4, $handlers);
|
||||
}
|
||||
}
|
||||
|
@ -46,12 +46,12 @@ class ApiDocExtractor
|
||||
private $commentExtractor;
|
||||
|
||||
/**
|
||||
* @var array ParserInterface
|
||||
* @var ParserInterface[]
|
||||
*/
|
||||
protected $parsers = array();
|
||||
|
||||
/**
|
||||
* @var array HandlerInterface
|
||||
* @var HandlerInterface[]
|
||||
*/
|
||||
protected $handlers;
|
||||
|
||||
@ -141,7 +141,7 @@ class ApiDocExtractor
|
||||
}
|
||||
|
||||
$methodOrder = array('GET', 'POST', 'PUT', 'DELETE');
|
||||
usort($array, function($a, $b) use ($methodOrder) {
|
||||
usort($array, function ($a, $b) use ($methodOrder) {
|
||||
if ($a['resource'] === $b['resource']) {
|
||||
if ($a['annotation']->getRoute()->getPattern() === $b['annotation']->getRoute()->getPattern()) {
|
||||
$methodA = array_search($a['annotation']->getRoute()->getRequirement('_method'), $methodOrder);
|
||||
@ -282,8 +282,8 @@ class ApiDocExtractor
|
||||
}
|
||||
}
|
||||
|
||||
foreach($supportedParsers as $parser) {
|
||||
if($parser instanceof PostParserInterface) {
|
||||
foreach ($supportedParsers as $parser) {
|
||||
if ($parser instanceof PostParserInterface) {
|
||||
$mp = $parser->postParse($normalizedInput, $parameters);
|
||||
$parameters = $this->mergeParameters($parameters, $mp);
|
||||
}
|
||||
@ -293,7 +293,7 @@ class ApiDocExtractor
|
||||
|
||||
if ('PUT' === $method) {
|
||||
// All parameters are optional with PUT (update)
|
||||
array_walk($parameters, function($val, $key) use (&$data) {
|
||||
array_walk($parameters, function ($val, $key) use (&$data) {
|
||||
$parameters[$key]['required'] = false;
|
||||
});
|
||||
}
|
||||
@ -409,24 +409,24 @@ class ApiDocExtractor
|
||||
{
|
||||
$params = $p1;
|
||||
|
||||
foreach($p2 as $propname => $propvalue) {
|
||||
if(!isset($p1[$propname])) {
|
||||
foreach ($p2 as $propname => $propvalue) {
|
||||
if (!isset($p1[$propname])) {
|
||||
$params[$propname] = $propvalue;
|
||||
} else {
|
||||
$v1 = $p1[$propname];
|
||||
|
||||
foreach($propvalue as $name => $value) {
|
||||
if(is_array($value)) {
|
||||
if(isset($v1[$name]) && is_array($v1[$name])) {
|
||||
foreach ($propvalue as $name => $value) {
|
||||
if (is_array($value)) {
|
||||
if (isset($v1[$name]) && is_array($v1[$name])) {
|
||||
$v1[$name] = $this->mergeParameters($v1[$name], $value);
|
||||
} else {
|
||||
$v1[$name] = $value;
|
||||
}
|
||||
} elseif(!is_null($value)) {
|
||||
if(in_array($name, array('required', 'readonly'))) {
|
||||
} elseif (!is_null($value)) {
|
||||
if (in_array($name, array('required', 'readonly'))) {
|
||||
$v1[$name] = $v1[$name] || $value;
|
||||
} elseif(in_array($name, array('requirement'))) {
|
||||
if(isset($v1[$name])) {
|
||||
} elseif (in_array($name, array('requirement'))) {
|
||||
if (isset($v1[$name])) {
|
||||
$v1[$name] .= ', ' . $value;
|
||||
} else {
|
||||
$v1[$name] = $value;
|
||||
@ -468,12 +468,13 @@ class ApiDocExtractor
|
||||
*/
|
||||
protected function clearClasses($array)
|
||||
{
|
||||
if(is_array($array)) {
|
||||
if (is_array($array)) {
|
||||
unset($array['class']);
|
||||
foreach($array as $name => $item) {
|
||||
foreach ($array as $name => $item) {
|
||||
$array[$name] = $this->clearClasses($item);
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class FosRestHandler implements HandlerInterface
|
||||
'dataType' => '',
|
||||
'description' => $annot->description,
|
||||
));
|
||||
} elseif($annot->default !== null) {
|
||||
} elseif ($annot->default !== null) {
|
||||
$annotation->addFilter($annot->name, array(
|
||||
'requirement' => $annot->requirements,
|
||||
'description' => $annot->description,
|
||||
|
@ -20,7 +20,7 @@ class MarkdownFormatter extends AbstractFormatter
|
||||
{
|
||||
$markdown = sprintf("### `%s` %s ###\n", $data['method'], $data['uri']);
|
||||
|
||||
if(isset($data['deprecated']) && false !== $data['deprecated']) {
|
||||
if (isset($data['deprecated']) && false !== $data['deprecated']) {
|
||||
$markdown .= "### This method is deprecated ###";
|
||||
$markdown .= "\n\n";
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class JmsMetadataParser implements ParserInterface
|
||||
'untilVersion' => $item->untilVersion,
|
||||
);
|
||||
|
||||
if(!is_null($dataType['class'])) {
|
||||
if (!is_null($dataType['class'])) {
|
||||
$params[$name]['class'] = $dataType['class'];
|
||||
}
|
||||
|
||||
|
@ -56,23 +56,23 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
$classdata = $this->factory->getMetadataFor($className);
|
||||
$properties = $classdata->getConstrainedProperties();
|
||||
|
||||
foreach($properties as $property) {
|
||||
foreach ($properties as $property) {
|
||||
$vparams = array();
|
||||
$pds = $classdata->getPropertyMetadata($property);
|
||||
foreach($pds as $propdata) {
|
||||
foreach ($pds as $propdata) {
|
||||
$constraints = $propdata->getConstraints();
|
||||
|
||||
foreach($constraints as $constraint) {
|
||||
foreach ($constraints as $constraint) {
|
||||
$vparams = $this->parseConstraint($constraint, $vparams, $className);
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($vparams['format'])) {
|
||||
if (isset($vparams['format'])) {
|
||||
$vparams['format'] = join(', ', $vparams['format']);
|
||||
}
|
||||
|
||||
foreach(array('dataType', 'readonly', 'required') as $reqprop) {
|
||||
if(!isset($vparams[$reqprop])) {
|
||||
foreach (array('dataType', 'readonly', 'required') as $reqprop) {
|
||||
if (!isset($vparams[$reqprop])) {
|
||||
$vparams[$reqprop] = null;
|
||||
}
|
||||
}
|
||||
@ -88,8 +88,8 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
*/
|
||||
public function postParse(array $input, array $parameters)
|
||||
{
|
||||
foreach($parameters as $param => $data) {
|
||||
if(isset($data['class']) && isset($data['children'])) {
|
||||
foreach ($parameters as $param => $data) {
|
||||
if (isset($data['class']) && isset($data['children'])) {
|
||||
$input = array('class' => $data['class']);
|
||||
$parameters[$param]['children'] = array_merge(
|
||||
$parameters[$param]['children'], $this->postParse($input, $parameters[$param]['children'])
|
||||
@ -123,7 +123,7 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
{
|
||||
$class = substr(get_class($constraint), strlen('Symfony\\Component\\Validator\\Constraints\\'));
|
||||
|
||||
switch($class) {
|
||||
switch ($class) {
|
||||
case 'NotBlank':
|
||||
case 'NotNull':
|
||||
$vparams['required'] = true;
|
||||
@ -142,10 +142,10 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
break;
|
||||
case 'Length':
|
||||
$messages = array();
|
||||
if(isset($constraint->min)) {
|
||||
if (isset($constraint->min)) {
|
||||
$messages[] = "min: {$constraint->min}";
|
||||
}
|
||||
if(isset($constraint->max)) {
|
||||
if (isset($constraint->max)) {
|
||||
$messages[] = "max: {$constraint->max}";
|
||||
}
|
||||
$vparams['format'][] = '{length: ' . join(', ', $messages) . '}';
|
||||
@ -153,12 +153,12 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
case 'Choice':
|
||||
$choices = $this->getChoices($constraint, $className);
|
||||
$format = '[' . join('|', $choices) . ']';
|
||||
if($constraint->multiple) {
|
||||
if ($constraint->multiple) {
|
||||
$messages = array();
|
||||
if(isset($constraint->min)) {
|
||||
if (isset($constraint->min)) {
|
||||
$messages[] = "min: {$constraint->min} ";
|
||||
}
|
||||
if(isset($constraint->max)) {
|
||||
if (isset($constraint->max)) {
|
||||
$messages[] = "max: {$constraint->max} ";
|
||||
}
|
||||
$vparams['format'][] = '{' . join ('', $messages) . 'choice of ' . $format . '}';
|
||||
@ -167,7 +167,7 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
}
|
||||
break;
|
||||
case 'Regex':
|
||||
if($constraint->match) {
|
||||
if ($constraint->match) {
|
||||
$vparams['format'][] = '{match: ' . $constraint->pattern . '}';
|
||||
} else {
|
||||
$vparams['format'][] = '{not match: ' . $constraint->pattern . '}';
|
||||
@ -186,7 +186,7 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
* @return array
|
||||
* @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
|
||||
*/
|
||||
protected function getChoices (Constraint $constraint, $className)
|
||||
protected function getChoices(Constraint $constraint, $className)
|
||||
{
|
||||
if ($constraint->callback) {
|
||||
if (is_callable(array($className, $constraint->callback))) {
|
||||
|
@ -7,7 +7,6 @@ use Nelmio\ApiDocBundle\Tests\Fixtures;
|
||||
use Symfony\Component\Form\Extension\Core\CoreExtension;
|
||||
use Symfony\Component\Form\FormFactory;
|
||||
use Symfony\Component\Form\FormFactoryBuilder;
|
||||
use Symfony\Component\Form\FormRegistry;
|
||||
use Symfony\Component\Form\ResolvedFormTypeFactory;
|
||||
|
||||
class FormTypeParserTest extends \PHPUnit_Framework_TestCase
|
||||
|
@ -4,7 +4,6 @@ namespace NelmioApiDocBundle\Tests\Parser;
|
||||
use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
||||
use Nelmio\ApiDocBundle\Parser\ValidationParser;
|
||||
|
||||
|
||||
class ValidationParserTest extends WebTestCase
|
||||
{
|
||||
protected $handler;
|
||||
@ -24,12 +23,11 @@ class ValidationParserTest extends WebTestCase
|
||||
{
|
||||
$result = $this->parser->parse(array('class' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\ValidatorTest'));
|
||||
|
||||
foreach($expected as $name => $value) {
|
||||
foreach ($expected as $name => $value) {
|
||||
$this->assertEquals($value, $expected[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function dataTestParser()
|
||||
{
|
||||
return array(
|
||||
|
@ -14,7 +14,6 @@ namespace Nelmio\ApiDocBundle\Tests;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
use Symfony\Component\DependencyInjection\Scope;
|
||||
|
||||
abstract class WebTestCase extends BaseWebTestCase
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user