Skip to content

Commit

Permalink
Fix some style
Browse files Browse the repository at this point in the history
  • Loading branch information
BigZ committed Jul 15, 2018
1 parent e0faaa1 commit ef71be9
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
bin/
composer.lock
.php_cs.cache
2 changes: 1 addition & 1 deletion src/Halapi/Annotation/Embeddable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Tell the serializer if a property embeddable in a representation.
*
* @Annotation
*
* @Target({"PROPERTY", "CLASS"})
*/
class Embeddable
Expand Down Expand Up @@ -74,5 +75,4 @@ public function setCollectionRouteName($collectionRouteName)
{
$this->collectionRouteName = $collectionRouteName;
}

}
5 changes: 3 additions & 2 deletions src/Halapi/AnnotationReader/AnnotationReaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Halapi\AnnotationReader;

/**
* Reads annotations
* Reads annotations.
*
* @author Romain Richard
*/
interface AnnotationReaderInterface
Expand Down Expand Up @@ -38,7 +39,7 @@ public function getResourceCollectionRouteName(\ReflectionClass $resource);
/**
* Does an entity's property have the @embeddable annotation ?
*
* @param $property
* @param $property \ReflectionProperty property
*
* @return bool
*/
Expand Down
19 changes: 13 additions & 6 deletions src/Halapi/AnnotationReader/DoctrineAnnotationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use Doctrine\Common\Annotations\Reader;

/**
* Reads annotations
* Reads annotations.
*
* @author Romain Richard
*/
class DoctrineAnnotationReader implements AnnotationReaderInterface
Expand All @@ -16,20 +17,26 @@ class DoctrineAnnotationReader implements AnnotationReaderInterface
*/
protected $annotationReader;

/**
* DoctrineAnnotationReader constructor.
* @param Reader $annotationReader
*/
public function __construct(Reader $annotationReader)
{
$this->annotationReader = $annotationReader;
}

/**
* @param \ReflectionProperty $property
*
* @return mixed
*
* @throws \ReflectionException
*/
private function getAssociationRouteName(\ReflectionProperty $property)
public function getAssociationRouteName(\ReflectionProperty $property)
{
/**
* @var $annotation Embeddable
* @var Embeddable
*/
$annotation = $this->annotationReader->getPropertyAnnotation($property, Embeddable::class);

Expand All @@ -49,10 +56,10 @@ private function getAssociationRouteName(\ReflectionProperty $property)
*
* @return string
*/
private function getResourceRouteName(\ReflectionClass $resource)
public function getResourceRouteName(\ReflectionClass $resource)
{
/**
* @var $annotation Embeddable
* @var Embeddable
*/
$annotation = $this->annotationReader->getClassAnnotation($resource, Embeddable::class);

Expand All @@ -73,7 +80,7 @@ private function getResourceRouteName(\ReflectionClass $resource)
public function getResourceCollectionRouteName(\ReflectionClass $resource)
{
/**
* @var $annotation Embeddable
* @var Embeddable
*/
$annotation = $this->annotationReader->getClassAnnotation($resource, Embeddable::class);

Expand Down
24 changes: 13 additions & 11 deletions src/Halapi/Factory/PaginationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ class PaginationFactory

/**
* PaginationFactory constructor.
* @param UrlGeneratorInterface $urlGenerator
* @param ObjectManagerInterface $objectManager
* @param ServerRequestInterface $request
* @param PagerInterface $pager
*
* @param UrlGeneratorInterface $urlGenerator
* @param ObjectManagerInterface $objectManager
* @param ServerRequestInterface $request
* @param PagerInterface $pager
* @param AnnotationReaderInterface $annotationReader
*/
public function __construct(
Expand All @@ -66,7 +67,8 @@ public function __construct(

/**
* Get a paginated representation of a collection of entities.
* Your repository for the object $className must implement the 'findAllSorted' method
* Your repository for the object $className must implement the 'findAllSorted' method.
*
* @param string $className
*
* @return PaginatedRepresentation
Expand Down Expand Up @@ -133,14 +135,14 @@ private function addPaginationParams()
}

/**
* Return the url of a resource based on the 'get_entity' route name convention.
* @param $name string
* @param $limit int
* @param $page int
* @param $sorting string
*
* @param string $name
* @param $limit
* @param $page
* @param $sorting
* @return string|null
*
* @return string
* @throws \ReflectionException
*/
private function getPaginatedRoute($name, $limit, $page, $sorting)
{
Expand Down
9 changes: 7 additions & 2 deletions src/Halapi/ObjectManager/DoctrineOrmObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use Doctrine\Common\Persistence\ObjectManager;

/**
* Interface ObjectManagerInterface
* Interface ObjectManagerInterface.
*
* @author Romain Richard
*/
class DoctrineOrmObjectManager implements ObjectManagerInterface
Expand All @@ -17,6 +18,7 @@ class DoctrineOrmObjectManager implements ObjectManagerInterface

/**
* DoctrineOrmObjectManager constructor.
*
* @param ObjectManager $objectManager
*/
public function __construct(ObjectManager $objectManager)
Expand All @@ -26,6 +28,7 @@ public function __construct(ObjectManager $objectManager)

/**
* @param object $resource
*
* @return mixed
*/
public function getIdentifierName($resource)
Expand All @@ -37,6 +40,7 @@ public function getIdentifierName($resource)

/**
* @param object $resource
*
* @return mixed
*/
public function getIdentifier($resource)
Expand All @@ -57,6 +61,7 @@ public function getIdentifier($resource)

/**
* @param string $className
*
* @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
*/
public function getClassMetadata($className)
Expand Down Expand Up @@ -85,7 +90,7 @@ public function findAllSorted($className, array $sorting, array $filterValues, a

foreach ($fields as $field) {
if (isset($sorting[$field])) {
$direction = ($sorting[$field] === 'asc') ? 'asc' : 'desc';
$direction = ('asc' === $sorting[$field]) ? 'asc' : 'desc';
$queryBuilder->addOrderBy('e.'.$field, $direction);
}

Expand Down
6 changes: 5 additions & 1 deletion src/Halapi/ObjectManager/ObjectManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
namespace Halapi\ObjectManager;

/**
* Interface ObjectManagerInterface
* Interface ObjectManagerInterface.
*
* @author Romain Richard
*/
interface ObjectManagerInterface
{
/**
* @param object $resource
*
* @return mixed
*/
public function getIdentifier($resource);

/**
* @param object $resource
*
* @return mixed
*/
public function getIdentifierName($resource);
Expand All @@ -32,6 +35,7 @@ public function findAllSorted($className, array $sorting, array $filterValues, a

/**
* @param string $className
*
* @return mixed
*/
public function getClassMetadata($className);
Expand Down
26 changes: 17 additions & 9 deletions src/Halapi/Pager/PagerFanta.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use Pagerfanta\Adapter\AdapterInterface;

/**
* Class PagerFanta
* Class PagerFanta.
*
* @author Romain Richard
*/
class PagerFanta implements PagerInterface
Expand All @@ -22,7 +23,9 @@ class PagerFanta implements PagerInterface

/**
* PagerFanta constructor.
*
* @param string $pagerStrategy
*
* @return PagerFanta
*/
public function __construct($pagerStrategy)
Expand All @@ -31,7 +34,8 @@ public function __construct($pagerStrategy)
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @return array
*/
public function getCurrentPageResults()
Expand All @@ -40,15 +44,16 @@ public function getCurrentPageResults()
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function getPageCount()
{
$this->pager->getNbPages();
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @param mixed $results
*/
public function setResults($results)
Expand All @@ -58,7 +63,8 @@ public function setResults($results)
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @param int $max
*/
public function setMaxPerPage($max)
Expand All @@ -67,7 +73,8 @@ public function setMaxPerPage($max)
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @param int $page
*/
public function setCurrentPage($page)
Expand All @@ -80,10 +87,11 @@ public function setCurrentPage($page)
*/
public function setPagerStrategy($pagerStrategy)
{
if (!class_exists('Pagerfanta\Adapter\\'.$pagerStrategy.'Adapter')) {
$pagerAdapter = sprintf('%sAdapter', $pagerStrategy);
if (!class_exists(sprintf('Pagerfanta\Adapter\\%s', $pagerAdapter))) {
throw new \InvalidArgumentException(sprintf(
'No adapter named %s found in %s namespace',
$pagerStrategy.'Adapter',
$pagerAdapter,
'Pagerfanta\Adapter'
));
}
Expand All @@ -98,7 +106,7 @@ public function setPagerStrategy($pagerStrategy)
*/
private function getPagerAdapter($results)
{
$adapterClassName = 'Pagerfanta\Adapter\\'.$this->pagerStrategy.'Adapter';
$adapterClassName = sprintf('Pagerfanta\Adapter\\%sAdapter', $this->pagerStrategy);

return new $adapterClassName(...$results);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Halapi/Pager/PagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Halapi\Pager;

/**
* Class PagerInterface
* Class PagerInterface.
*
* @author Romain Richard
*/
interface PagerInterface
Expand All @@ -28,6 +29,7 @@ public function getPageCount();
* depending on which adapter you use.
*
* @param mixed $results
*
* @return mixed
*/
public function setResults($results);
Expand All @@ -36,15 +38,13 @@ public function setResults($results);
* Set the maximum number of results per page (aka limit).
*
* @param int $max
* @return void
*/
public function setMaxPerPage($max);

/**
* Set the page to display.
*
* @param int $page
* @return void
*/
public function setCurrentPage($page);
}
3 changes: 1 addition & 2 deletions src/Halapi/Relation/EmbeddedRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public function getRelation($resource)
foreach ($reflectionClass->getProperties() as $property) {
$propertyName = $property->getName();

if (
$this->annotationReader->isEmbeddable($property)
if ($this->annotationReader->isEmbeddable($property)
&& $this->isEmbeddedRequested($propertyName, $requestedEmbedded)
) {
$embedded[$property->getName()] = $this->getEmbeddedContent($resource, $property);
Expand Down
Loading

0 comments on commit ef71be9

Please sign in to comment.