Skip to content

Commit

Permalink
Merge 718c862 into 298c893
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenalinkin committed Feb 6, 2023
2 parents 298c893 + 718c862 commit 3ab829f
Show file tree
Hide file tree
Showing 39 changed files with 207 additions and 88 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/lint.yaml

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Static analysis

on: [push, pull_request]

jobs:
static-analysis:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none
tools: php-cs-fixer:3.x, composer-normalize:2.x

- name: Run PHP-CS-Fixer
run: php-cs-fixer fix --dry-run

- name: Run composer normalize
run: composer-normalize --dry-run
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: UnitTests
name: Tests

on: [push, pull_request]

Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
composer.lock
composer.phar
phpunit.xml
.php_cs
.php_cs.cache
4 changes: 3 additions & 1 deletion .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

$fileHeaderComment = <<<COMMENT
This file is part of the SwaggerResolverBundle package.
Expand All @@ -13,7 +15,7 @@
->in(__DIR__)
->exclude('Resources/config')
->exclude('var')
->notPath('Tests/Functional/src/swagger.php'); // PHPCS-Fixer does not recognising the DocBlock inside swagger.php.
->notPath('Tests/Functional/src/swagger.php'); // PHPCS-Fixer does not recognise the DocBlock inside swagger.php.

return (new PhpCsFixer\Config())
->setRules([
Expand Down
8 changes: 3 additions & 5 deletions Collection/SchemaDefinitionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Collection;

use ArrayIterator;
use EXSyst\Component\Swagger\Schema;
use IteratorAggregate;
use Linkin\Bundle\SwaggerResolverBundle\Exception\DefinitionNotFoundException;
use Symfony\Component\Config\Resource\FileResource;

/**
* @author Viktor Linkin <adrenalinkin@gmail.com>
*/
class SchemaDefinitionCollection implements IteratorAggregate
class SchemaDefinitionCollection implements \IteratorAggregate
{
/**
* @var Schema[]
Expand All @@ -37,9 +35,9 @@ class SchemaDefinitionCollection implements IteratorAggregate
/**
* {@inheritdoc}
*/
public function getIterator(): ArrayIterator
public function getIterator(): \ArrayIterator
{
return new ArrayIterator($this->schemaCollection);
return new \ArrayIterator($this->schemaCollection);
}

public function addSchema(string $definitionName, Schema $schema): self
Expand Down
8 changes: 3 additions & 5 deletions Collection/SchemaOperationCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Collection;

use ArrayIterator;
use EXSyst\Component\Swagger\Schema;
use IteratorAggregate;
use Linkin\Bundle\SwaggerResolverBundle\Exception\OperationNotFoundException;
use Symfony\Component\Config\Resource\FileResource;

/**
* @author Viktor Linkin <adrenalinkin@gmail.com>
*/
class SchemaOperationCollection implements IteratorAggregate
class SchemaOperationCollection implements \IteratorAggregate
{
/**
* @var Schema[][]
Expand All @@ -37,9 +35,9 @@ class SchemaOperationCollection implements IteratorAggregate
/**
* {@inheritdoc}
*/
public function getIterator(): ArrayIterator
public function getIterator(): \ArrayIterator
{
return new ArrayIterator($this->schemaCollection);
return new \ArrayIterator($this->schemaCollection);
}

public function addSchema(string $routeName, string $method, Schema $schema): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Linkin\Bundle\SwaggerResolverBundle\DependencyInjection\Compiler;

use Linkin\Bundle\SwaggerResolverBundle\Builder\SwaggerResolverBuilder;
use SplPriorityQueue;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -35,7 +34,7 @@ public function process(ContainerBuilder $container): void
return;
}

$normalizerQueue = new SplPriorityQueue();
$normalizerQueue = new \SplPriorityQueue();

foreach ($container->findTaggedServiceIds(self::TAG) as $id => $attributes) {
$normalizerQueue->insert(new Reference($id), $attributes[0]['priority'] ?? 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Linkin\Bundle\SwaggerResolverBundle\DependencyInjection\Compiler;

use Linkin\Bundle\SwaggerResolverBundle\Builder\SwaggerResolverBuilder;
use SplPriorityQueue;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -35,7 +34,7 @@ public function process(ContainerBuilder $container): void
return;
}

$validatorQueue = new SplPriorityQueue();
$validatorQueue = new \SplPriorityQueue();

foreach ($container->findTaggedServiceIds(self::TAG) as $id => $attributes) {
$validatorQueue->insert(new Reference($id), $attributes[0]['priority'] ?? 0);
Expand Down
5 changes: 2 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Linkin\Bundle\SwaggerResolverBundle\DependencyInjection;

use Closure;
use Linkin\Bundle\SwaggerResolverBundle\Enum\ParameterLocationEnum;
use Linkin\Bundle\SwaggerResolverBundle\Loader\SwaggerConfigurationLoaderInterface;
use Linkin\Bundle\SwaggerResolverBundle\Merger\MergeStrategyInterface;
Expand Down Expand Up @@ -84,7 +83,7 @@ public function getConfigTreeBuilder(): TreeBuilder
return $treeBuilder;
}

private function validationForConfigurationLoader(): Closure
private function validationForConfigurationLoader(): \Closure
{
return static function ($className) {
if (!is_subclass_of($className, SwaggerConfigurationLoaderInterface::class)) {
Expand All @@ -95,7 +94,7 @@ private function validationForConfigurationLoader(): Closure
};
}

private function validationForPathMergeStrategy(): Closure
private function validationForPathMergeStrategy(): \Closure
{
return static function ($className) {
if (!is_subclass_of($className, MergeStrategyInterface::class)) {
Expand Down
4 changes: 1 addition & 3 deletions Enum/ParameterCollectionFormatEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Enum;

use RuntimeException;

/**
* @author Viktor Linkin <adrenalinkin@gmail.com>
*/
Expand Down Expand Up @@ -45,7 +43,7 @@ public static function getDelimiter(string $collectionFormat): string
case self::MULTI:
return '&';
default:
throw new RuntimeException(sprintf('Unexpected collection format: %s', $collectionFormat));
throw new \RuntimeException(sprintf('Unexpected collection format: %s', $collectionFormat));
}
}
}
4 changes: 1 addition & 3 deletions Exception/DefinitionNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Exception;

use RuntimeException;

/**
* @author Viktor Linkin <adrenalinkin@gmail.com>
*/
class DefinitionNotFoundException extends RuntimeException
class DefinitionNotFoundException extends \RuntimeException
{
public function __construct(string $className)
{
Expand Down
4 changes: 1 addition & 3 deletions Exception/OperationNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Exception;

use RuntimeException;

/**
* @author Viktor Linkin <adrenalinkin@gmail.com>
*/
class OperationNotFoundException extends RuntimeException
class OperationNotFoundException extends \RuntimeException
{
public function __construct(string $path, string $method)
{
Expand Down
4 changes: 1 addition & 3 deletions Exception/UndefinedPropertyTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Exception;

use RuntimeException;

/**
* @author Viktor Linkin <adrenalinkin@gmail.com>
*/
class UndefinedPropertyTypeException extends RuntimeException
class UndefinedPropertyTypeException extends \RuntimeException
{
public function __construct(string $definitionName, string $propertyName, string $type)
{
Expand Down
3 changes: 1 addition & 2 deletions Loader/AbstractSwaggerConfigurationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Linkin\Bundle\SwaggerResolverBundle\Collection\SchemaOperationCollection;
use Linkin\Bundle\SwaggerResolverBundle\Exception\OperationNotFoundException;
use Linkin\Bundle\SwaggerResolverBundle\Merger\OperationParameterMerger;
use ReflectionClass;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Routing\RouterInterface;

Expand Down Expand Up @@ -178,7 +177,7 @@ private function initRouteMaps(): void
$defaults = $route->getDefaults();
$exploded = explode('::', $defaults['_controller']);
$controllerName = reset($exploded);
$fullClassName = (new ReflectionClass($controllerName))->getFileName();
$fullClassName = (new \ReflectionClass($controllerName))->getFileName();

$this->mapPathToRouteName[$route->getPath()][$this->normalizeMethod($method)] = $routeName;
$this->mapRouteNameToSourceFile[$routeName] = new FileResource($fullClassName);
Expand Down
4 changes: 1 addition & 3 deletions Merger/Strategy/StrictMergeStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Merger\Strategy;

use RuntimeException;

/**
* @author Viktor Linkin <adrenalinkin@gmail.com>
*/
Expand All @@ -26,7 +24,7 @@ class StrictMergeStrategy extends AbstractMergeStrategy
public function addParameter(string $parameterSource, string $name, array $data, bool $isRequired): void
{
if (isset($this->parameters[$name])) {
throw new RuntimeException(sprintf('Parameter "%s" has duplicate. Rename parameter or use another merger strategy', $name));
throw new \RuntimeException(sprintf('Parameter "%s" has duplicate. Rename parameter or use another merger strategy', $name));
}

if ($isRequired) {
Expand Down
3 changes: 1 addition & 2 deletions Normalizer/BooleanNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Normalizer;

use Closure;
use EXSyst\Component\Swagger\Schema;
use Linkin\Bundle\SwaggerResolverBundle\Enum\ParameterTypeEnum;
use Linkin\Bundle\SwaggerResolverBundle\Exception\NormalizationFailedException;
Expand All @@ -35,7 +34,7 @@ public function supports(Schema $propertySchema, string $propertyName, bool $isR
/**
* {@inheritdoc}
*/
public function getNormalizer(Schema $propertySchema, string $propertyName, bool $isRequired): Closure
public function getNormalizer(Schema $propertySchema, string $propertyName, bool $isRequired): \Closure
{
return static function (Options $options, $value) use ($isRequired, $propertyName) {
if ('true' === $value || '1' === $value || 1 === $value || true === $value) {
Expand Down
3 changes: 1 addition & 2 deletions Normalizer/IntegerNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Normalizer;

use Closure;
use EXSyst\Component\Swagger\Schema;
use Linkin\Bundle\SwaggerResolverBundle\Enum\ParameterTypeEnum;
use Linkin\Bundle\SwaggerResolverBundle\Exception\NormalizationFailedException;
Expand All @@ -35,7 +34,7 @@ public function supports(Schema $propertySchema, string $propertyName, bool $isR
/**
* {@inheritdoc}
*/
public function getNormalizer(Schema $propertySchema, string $propertyName, bool $isRequired): Closure
public function getNormalizer(Schema $propertySchema, string $propertyName, bool $isRequired): \Closure
{
return static function (Options $options, $value) use ($isRequired, $propertyName) {
if (is_numeric($value)) {
Expand Down
3 changes: 1 addition & 2 deletions Normalizer/NumberNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Normalizer;

use Closure;
use EXSyst\Component\Swagger\Schema;
use Linkin\Bundle\SwaggerResolverBundle\Enum\ParameterTypeEnum;
use Linkin\Bundle\SwaggerResolverBundle\Exception\NormalizationFailedException;
Expand All @@ -35,7 +34,7 @@ public function supports(Schema $propertySchema, string $propertyName, bool $isR
/**
* {@inheritdoc}
*/
public function getNormalizer(Schema $propertySchema, string $propertyName, bool $isRequired): Closure
public function getNormalizer(Schema $propertySchema, string $propertyName, bool $isRequired): \Closure
{
return static function (Options $options, $value) use ($isRequired, $propertyName) {
if (is_numeric($value)) {
Expand Down
3 changes: 1 addition & 2 deletions Normalizer/SwaggerNormalizerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Linkin\Bundle\SwaggerResolverBundle\Normalizer;

use Closure;
use EXSyst\Component\Swagger\Schema;

/**
Expand All @@ -32,5 +31,5 @@ public function supports(Schema $propertySchema, string $propertyName, bool $isR
*
* Returns closure for normalizing property
*/
public function getNormalizer(Schema $propertySchema, string $propertyName, bool $isRequired): Closure;
public function getNormalizer(Schema $propertySchema, string $propertyName, bool $isRequired): \Closure;
}
30 changes: 30 additions & 0 deletions README.RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,36 @@ $data = $swaggerResolver->resolve(json_decode($request->getContent(), true));
класс, реализующий интерфейс [SwaggerNormalizerInterface](./Normalizer/SwaggerNormalizerInterface.php) и
зарегистрировать его с тегом `linkin_swagger_resolver.normalizer`.

### Запуск тестов и инструментов статического анализа
Скачать проект:
```bash
git clone git@github.com:adrenalinkin/swagger-resolver-bundle.git
cd swagger-resolver-bundle
```

Пройти [по инструкции](https://gist.github.com/adrenalinkin/35176a7b52b996666c4a36384fd536ad#file-an-instruction-md)
для настройки простого docker контейнера.

Установить Composer зависимости:
```bash
composer update
```

Для запуска тестов выполнить:
```bash
bin/simple-phpunit
```

Для запуска [PHP-CS-Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) выполнить:
```bash
php-cs-fixer fix --diff
```

Для запуска [composer-normalize](https://github.com/ergebnis/composer-normalize) выполнить:
```bash
composer-normalize --dry-run
```

Лицензия
--------

Expand Down

0 comments on commit 3ab829f

Please sign in to comment.