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

CS.

parent 70731770
No related merge requests found
Showing with 73 additions and 49 deletions
+73 -49
<?php declare(strict_types=1);
/**
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 2019 IRSTEA
* All rights reserved.
*
* @copyright 2019 IRSTEA
* @author guillaume.perreal
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
namespace Irstea\ApiMetadata\Bridge\RamseyUuid;
use Irstea\ApiMetadata\Factory\ContextInterface;
use Irstea\ApiMetadata\Factory\Type\AbstractClassTypeFactory;
use Irstea\ApiMetadata\Factory\Type\TypeFactoryDecorator;
use Irstea\ApiMetadata\Model\BaseTypeMetadata;
use Irstea\ApiMetadata\Model\TypeMetadata;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\PropertyInfo\Type;
/**
* Class UuidTypeFactory
* Class UuidTypeFactory.
*/
class UuidTypeFactory extends AbstractClassTypeFactory
{
/**
* @inheritDoc
* {@inheritdoc}
*/
protected function supportsClass(string $className, ContextInterface $context): bool
{
......@@ -33,13 +40,11 @@ class UuidTypeFactory extends AbstractClassTypeFactory
}
/**
* @inheritDoc
* {@inheritdoc}
*/
protected function createClass(string $className, ContextInterface $context): TypeMetadata
{
// @TODO: faire mieux
return BaseTypeMetadata::create('uuid');
}
}
......@@ -38,8 +38,8 @@ class IrsteaApiMetadataExtension extends Extension
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
/** @noinspection ClassConstantCanBeUsedInspection */
if(\class_exists('\Ramsey\Uuid\Uuid')) {
/* @noinspection ClassConstantCanBeUsedInspection */
if (\class_exists('\Ramsey\Uuid\Uuid')) {
$loader->load('ramsey_uuid.xml');
}
}
......
<?php declare(strict_types=1);
/**
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 2019 IRSTEA
* All rights reserved.
*
* @copyright 2019 IRSTEA
* @author guillaume.perreal
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
namespace Irstea\ApiMetadata\Factory\Type;
use Irstea\ApiMetadata\Factory\ContextInterface;
use Irstea\ApiMetadata\Model\TypeMetadata;
use Symfony\Component\PropertyInfo\Type;
/**
* Class AbstractClassTypeFactory
* Class AbstractClassTypeFactory.
*/
abstract class AbstractClassTypeFactory extends TypeFactoryDecorator
{
......@@ -25,7 +34,7 @@ abstract class AbstractClassTypeFactory extends TypeFactoryDecorator
*/
public function create(?Type $type, ContextInterface $context): TypeMetadata
{
$className = $type ? $type->getClassName() : null;
$className = $type ? $type->getClassName() : null;
if (!$className || !$this->supportsClass($className, $context)) {
return parent::create($type, $context);
}
......@@ -35,14 +44,15 @@ abstract class AbstractClassTypeFactory extends TypeFactoryDecorator
/**
* @param string $className
*
* @return bool
*/
protected abstract function supportsClass(string $className, ContextInterface $context): bool;
abstract protected function supportsClass(string $className, ContextInterface $context): bool;
/**
* @param string $className
*
* @return TypeMetadata
*/
protected abstract function createClass(string $className, ContextInterface $context): TypeMetadata;
abstract protected function createClass(string $className, ContextInterface $context): TypeMetadata;
}
<?php declare(strict_types=1);
/**
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 2019 IRSTEA
* All rights reserved.
*
* @copyright 2019 IRSTEA
* @author guillaume.perreal
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
namespace Irstea\ApiMetadata\Factory\Type;
use Irstea\ApiMetadata\Factory\ContextInterface;
use Irstea\ApiMetadata\Model\BaseTypeMetadata;
use Irstea\ApiMetadata\Model\TypeMetadata;
/**
* Class BuiltinClassTypeFactory
* Class BuiltinClassTypeFactory.
*/
class BuiltinClassTypeFactory extends AbstractClassTypeFactory
{
......@@ -27,7 +36,7 @@ class BuiltinClassTypeFactory extends AbstractClassTypeFactory
];
/**
* @inheritDoc
* {@inheritdoc}
*/
protected function supportsClass(string $className, ContextInterface $context): bool
{
......@@ -36,23 +45,23 @@ class BuiltinClassTypeFactory extends AbstractClassTypeFactory
return true;
}
}
return false;
}
/**
* @inheritDoc
* {@inheritdoc}
*/
protected function createClass(string $className, ContextInterface $context): TypeMetadata
{
if (is_a($className, \DateTimeInterface::class, true)) {
return BaseTypeMetadata::create("string");
return BaseTypeMetadata::create('string');
}
if (is_a($className, \Iterator::class, true)) {
return BaseTypeMetadata::create("array");
return BaseTypeMetadata::create('array');
}
if (is_a($className, \stdClass::class, true)) {
return BaseTypeMetadata::create("object");
return BaseTypeMetadata::create('object');
}
}
}
......@@ -56,7 +56,7 @@ class ObjectTypeFactory extends AbstractClassTypeFactory
}
/**
* @inheritDoc
* {@inheritdoc}
*/
protected function supportsClass(string $className, ContextInterface $context): bool
{
......@@ -64,7 +64,7 @@ class ObjectTypeFactory extends AbstractClassTypeFactory
}
/**
* @inheritDoc
* {@inheritdoc}
*/
protected function createClass(string $className, ContextInterface $context): TypeMetadata
{
......
......@@ -28,7 +28,6 @@ use Irstea\ApiMetadata\Factory\Operation\OperationFactoryInterface;
use Irstea\ApiMetadata\Factory\Property\PropertyFactoryInterface;
use Irstea\ApiMetadata\Model\ResourceMetadata;
use Irstea\ApiMetadata\Model\TypeMetadata;
use Symfony\Component\PropertyInfo\Type;
/**
* Class ResourceTypeFactory.
......@@ -65,12 +64,13 @@ class ResourceTypeFactory extends AbstractClassTypeFactory
}
/**
* @inheritDoc
* {@inheritdoc}
*/
protected function supportsClass(string $className, ContextInterface $context): bool
{
try {
try {
$this->metadataFactory->create($className);
return true;
} catch (ResourceClassNotFoundException $ex) {
return false;
......@@ -78,7 +78,7 @@ class ResourceTypeFactory extends AbstractClassTypeFactory
}
/**
* @inheritDoc
* {@inheritdoc}
*/
protected function createClass(string $className, ContextInterface $context): TypeMetadata
{
......
......@@ -222,7 +222,8 @@ class Person
*
* @param \DateTime|null $birthDate
*/
public function setBirthDate(?\DateTime $birthDate): void {
public function setBirthDate(?\DateTime $birthDate): void
{
$this->birthDate = $birthDate;
}
......@@ -231,12 +232,11 @@ class Person
*/
public function getInitials(): \Generator
{
foreach(preg_split("\W+", $this->firstName) as $parts) {
foreach (preg_split("\W+", $this->firstName) as $parts) {
yield \strtoupper($parts[0]);
}
foreach(preg_split("\W+", $this->lastName) as $parts) {
foreach (preg_split("\W+", $this->lastName) as $parts) {
yield \strtoupper($parts[0]);
}
}
}
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