Commit cf237102 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

CS.

parent dcb7d97d
No related merge requests found
Showing with 32 additions and 32 deletions
+32 -32
......@@ -21,7 +21,6 @@
namespace Irstea\ApiMetadata\Bridge\Symfony\Serializer;
use Assert\Assertion;
use Irstea\ApiMetadata\JSON\AbsolutePointer;
use Irstea\ApiMetadata\JSON\ClassMapping;
use Irstea\ApiMetadata\JSON\ClassMappingInterface;
use Irstea\ApiMetadata\JSON\Document;
......@@ -79,20 +78,20 @@ class ObjectMetadataNormalizer implements NormalizerAwareInterface, NormalizerIn
Assertion::isInstanceOf($object, ObjectMetadata::class);
if ($object instanceof ResourceMetadata && !isset($context[self::CLASS_MAPPING_KEY])) {
return (object)$this->normalizeRoot($object, $format, $context);
return (object) $this->normalizeRoot($object, $format, $context);
}
return (object)$this->normalizeNonRoot($object, $format, $context);
return (object) $this->normalizeNonRoot($object, $format, $context);
}
/**
* @param ResourceMetadata $root
* @param string|null $format
* @param array $context
* @param string|null $format
* @param array $context
*
* @return mixed
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*
* @return mixed
*/
private function normalizeRoot(ResourceMetadata $root, $format, array $context)
{
......@@ -124,7 +123,7 @@ class ObjectMetadataNormalizer implements NormalizerAwareInterface, NormalizerIn
/**
* @param mixed $resource
* @param array $context
* @param bool $relative
* @param bool $relative
*
* @return string
*/
......@@ -137,19 +136,18 @@ class ObjectMetadataNormalizer implements NormalizerAwareInterface, NormalizerIn
/**
* @param ObjectMetadata $object
* @param string|null $format
* @param array $context
* @param string|null $format
* @param array $context
*
* @return array
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*
* @return array
*/
private function normalizeNonRoot(ObjectMetadata $object, $format, array $context)
{
$mapping = $context[self::CLASS_MAPPING_KEY];
Assertion::isInstanceOf($mapping, ClassMappingInterface::class);
/** @var ClassMappingInterface $mapping */
$ref = $mapping->resolve(
$object,
function () use ($object, $format, $context) {
......@@ -162,12 +160,12 @@ class ObjectMetadataNormalizer implements NormalizerAwareInterface, NormalizerIn
/**
* @param ObjectMetadata $object
* @param string|null $format
* @param array $context
* @param string|null $format
* @param array $context
*
* @return array
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*
* @return array
*/
private function doNormalize(ObjectMetadata $object, $format, array $context): array
{
......@@ -188,9 +186,9 @@ class ObjectMetadataNormalizer implements NormalizerAwareInterface, NormalizerIn
}
return [
'type' => $object->getBaseType(),
'required' => $required,
'properties' => $properties ?: (object)[],
'type' => $object->getBaseType(),
'required' => $required,
'properties' => $properties ?: (object) [],
] + $normalizedAttrs;
}
}
......@@ -22,7 +22,6 @@ namespace Irstea\ApiMetadata\JSON;
use Irstea\ApiMetadata\URI\URIGeneratorInterface;
use Irstea\ApiMetadata\URI\Util;
use Webmozart\PathUtil\Path;
/**
* Class ClassMapping.
......@@ -52,8 +51,8 @@ class ClassMapping implements ClassMappingInterface
/**
* ClassMapping constructor.
*
* @param Document $document
* @param string $base
* @param Document $document
* @param string $base
* @param URIGeneratorInterface $uriGenerator
*/
public function __construct(Document $document, string $base, URIGeneratorInterface $uriGenerator)
......
......@@ -21,9 +21,7 @@
namespace Irstea\ApiMetadata\URI;
use function Sabre\Uri\build;
use function Sabre\Uri\normalize;
use function Sabre\Uri\parse;
use function Sabre\Uri\resolve;
/**
* Class Util.
......@@ -32,6 +30,7 @@ final class Util
{
/**
* @param string $uri
*
* @return [string, string]
*/
private static function split(string $uri): array
......@@ -39,22 +38,26 @@ final class Util
$parts = parse($uri);
$fragment = $parts['fragment'] ?: '';
unset($parts['fragment']);
return [build($parts), $fragment];
}
/**
* @param string $uri
*
* @return string
*/
public static function getDocumentURI(string $uri): string
{
[$document, ] = self::split($uri);
return $document;
}
/**
* @param string $document
* @param string $target
*
* @return string|null
*/
public static function getFragmentInDocument(string $document, string $target): ?string
......@@ -71,6 +74,7 @@ final class Util
/**
* @param string $base
* @param string $target
*
* @return string
*/
public static function getRelativeURI(string $base, string $target): string
......
......@@ -60,6 +60,7 @@ class Address
/**
* Address constructor.
*
* @param string|null $street
* @param string|null $postalCode
* @param string|null $city
......@@ -118,6 +119,7 @@ class Address
* @param string|null $postalCode
* @param string|null $city
* @param string|null $country
*
* @return Address
*/
public static function create(string $street = null, ?string $postalCode = null, ?string $city = null, ?string $country = null): Address
......@@ -128,6 +130,7 @@ class Address
if (!$null) {
$null = new self(null, null, null, null);
}
return $null;
}
......
......@@ -22,7 +22,6 @@ namespace Irstea\ApiMetadata\Tests;
use Hautelook\AliceBundle\PhpUnit\RefreshDatabaseTrait;
use Swaggest\JsonSchema\Context;
use Swaggest\JsonSchema\Exception as JsonException;
use Swaggest\JsonSchema\InvalidValue;
use Swaggest\JsonSchema\Schema;
use Swaggest\JsonSchema\SchemaContract;
......@@ -108,9 +107,9 @@ class FunctionalTest extends WebTestCase
self::assertEquals(
[
'$id' => 'http://localhost/metadata',
'$id' => 'http://localhost/metadata',
'resources' => [
'User' => ['$ref' => 'http://localhost/metadata/User#'],
'User' => ['$ref' => 'http://localhost/metadata/User#'],
'Person' => ['$ref' => 'http://localhost/metadata/Person#'],
],
],
......@@ -119,9 +118,9 @@ class FunctionalTest extends WebTestCase
}
/**
* @return SchemaContract
* @throws \Exception
*
* @return SchemaContract
*/
public function testJsonSchemaValidity(): SchemaContract
{
......@@ -135,14 +134,12 @@ class FunctionalTest extends WebTestCase
return $schema;
}
/**
* @depends testJsonSchemaValidity
* @dataProvider fetchPeople
*
* @param $person
* @param SchemaContract $schema
*
*/
public function testValidateData($person, SchemaContract $schema)
{
......@@ -162,6 +159,7 @@ class FunctionalTest extends WebTestCase
{
$this->client = self::createClient();
$json = $this->fetchRawJson('GET', '/people');
return array_map(function ($data) {
return [$data];
}, json_decode($json, false));
......
......@@ -21,7 +21,6 @@
namespace Irstea\ApiMetadata\Tests\JSON;
use Irstea\ApiMetadata\JSON\Document;
use Irstea\ApiMetadata\JSON\AbsolutePointer;
use PHPUnit\Framework\TestCase;
/**
......
......@@ -22,7 +22,6 @@ namespace Irstea\ApiMetadata\Tests\URI;
use Irstea\ApiMetadata\URI\Util;
use PHPUnit\Framework\TestCase;
use function Sabre\Uri\resolve;
/**
* Class UtilTest.
......@@ -33,8 +32,8 @@ class UtilTest extends TestCase
{
/**
* @param string|null $expected
* @param string $documentURI
* @param string $targetURI
* @param string $documentURI
* @param string $targetURI
*
* @dataProvider getFragmentInDocumentTestCases
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment