Skip to content

Commit ef71be9

Browse files
committed
Fix some style
1 parent e0faaa1 commit ef71be9

17 files changed

Lines changed: 82 additions & 61 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor/
22
bin/
33
composer.lock
4+
.php_cs.cache

src/Halapi/Annotation/Embeddable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Tell the serializer if a property embeddable in a representation.
77
*
88
* @Annotation
9+
*
910
* @Target({"PROPERTY", "CLASS"})
1011
*/
1112
class Embeddable
@@ -74,5 +75,4 @@ public function setCollectionRouteName($collectionRouteName)
7475
{
7576
$this->collectionRouteName = $collectionRouteName;
7677
}
77-
7878
}

src/Halapi/AnnotationReader/AnnotationReaderInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Halapi\AnnotationReader;
44

55
/**
6-
* Reads annotations
6+
* Reads annotations.
7+
*
78
* @author Romain Richard
89
*/
910
interface AnnotationReaderInterface
@@ -38,7 +39,7 @@ public function getResourceCollectionRouteName(\ReflectionClass $resource);
3839
/**
3940
* Does an entity's property have the @embeddable annotation ?
4041
*
41-
* @param $property
42+
* @param $property \ReflectionProperty property
4243
*
4344
* @return bool
4445
*/

src/Halapi/AnnotationReader/DoctrineAnnotationReader.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use Doctrine\Common\Annotations\Reader;
77

88
/**
9-
* Reads annotations
9+
* Reads annotations.
10+
*
1011
* @author Romain Richard
1112
*/
1213
class DoctrineAnnotationReader implements AnnotationReaderInterface
@@ -16,20 +17,26 @@ class DoctrineAnnotationReader implements AnnotationReaderInterface
1617
*/
1718
protected $annotationReader;
1819

20+
/**
21+
* DoctrineAnnotationReader constructor.
22+
* @param Reader $annotationReader
23+
*/
1924
public function __construct(Reader $annotationReader)
2025
{
2126
$this->annotationReader = $annotationReader;
2227
}
2328

2429
/**
2530
* @param \ReflectionProperty $property
31+
*
2632
* @return mixed
33+
*
2734
* @throws \ReflectionException
2835
*/
29-
private function getAssociationRouteName(\ReflectionProperty $property)
36+
public function getAssociationRouteName(\ReflectionProperty $property)
3037
{
3138
/**
32-
* @var $annotation Embeddable
39+
* @var Embeddable
3340
*/
3441
$annotation = $this->annotationReader->getPropertyAnnotation($property, Embeddable::class);
3542

@@ -49,10 +56,10 @@ private function getAssociationRouteName(\ReflectionProperty $property)
4956
*
5057
* @return string
5158
*/
52-
private function getResourceRouteName(\ReflectionClass $resource)
59+
public function getResourceRouteName(\ReflectionClass $resource)
5360
{
5461
/**
55-
* @var $annotation Embeddable
62+
* @var Embeddable
5663
*/
5764
$annotation = $this->annotationReader->getClassAnnotation($resource, Embeddable::class);
5865

@@ -73,7 +80,7 @@ private function getResourceRouteName(\ReflectionClass $resource)
7380
public function getResourceCollectionRouteName(\ReflectionClass $resource)
7481
{
7582
/**
76-
* @var $annotation Embeddable
83+
* @var Embeddable
7784
*/
7885
$annotation = $this->annotationReader->getClassAnnotation($resource, Embeddable::class);
7986

src/Halapi/Factory/PaginationFactory.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ class PaginationFactory
4444

4545
/**
4646
* PaginationFactory constructor.
47-
* @param UrlGeneratorInterface $urlGenerator
48-
* @param ObjectManagerInterface $objectManager
49-
* @param ServerRequestInterface $request
50-
* @param PagerInterface $pager
47+
*
48+
* @param UrlGeneratorInterface $urlGenerator
49+
* @param ObjectManagerInterface $objectManager
50+
* @param ServerRequestInterface $request
51+
* @param PagerInterface $pager
5152
* @param AnnotationReaderInterface $annotationReader
5253
*/
5354
public function __construct(
@@ -66,7 +67,8 @@ public function __construct(
6667

6768
/**
6869
* Get a paginated representation of a collection of entities.
69-
* Your repository for the object $className must implement the 'findAllSorted' method
70+
* Your repository for the object $className must implement the 'findAllSorted' method.
71+
*
7072
* @param string $className
7173
*
7274
* @return PaginatedRepresentation
@@ -133,14 +135,14 @@ private function addPaginationParams()
133135
}
134136

135137
/**
136-
* Return the url of a resource based on the 'get_entity' route name convention.
138+
* @param $name string
139+
* @param $limit int
140+
* @param $page int
141+
* @param $sorting string
137142
*
138-
* @param string $name
139-
* @param $limit
140-
* @param $page
141-
* @param $sorting
143+
* @return string|null
142144
*
143-
* @return string
145+
* @throws \ReflectionException
144146
*/
145147
private function getPaginatedRoute($name, $limit, $page, $sorting)
146148
{

src/Halapi/ObjectManager/DoctrineOrmObjectManager.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
use Doctrine\Common\Persistence\ObjectManager;
66

77
/**
8-
* Interface ObjectManagerInterface
8+
* Interface ObjectManagerInterface.
9+
*
910
* @author Romain Richard
1011
*/
1112
class DoctrineOrmObjectManager implements ObjectManagerInterface
@@ -17,6 +18,7 @@ class DoctrineOrmObjectManager implements ObjectManagerInterface
1718

1819
/**
1920
* DoctrineOrmObjectManager constructor.
21+
*
2022
* @param ObjectManager $objectManager
2123
*/
2224
public function __construct(ObjectManager $objectManager)
@@ -26,6 +28,7 @@ public function __construct(ObjectManager $objectManager)
2628

2729
/**
2830
* @param object $resource
31+
*
2932
* @return mixed
3033
*/
3134
public function getIdentifierName($resource)
@@ -37,6 +40,7 @@ public function getIdentifierName($resource)
3740

3841
/**
3942
* @param object $resource
43+
*
4044
* @return mixed
4145
*/
4246
public function getIdentifier($resource)
@@ -57,6 +61,7 @@ public function getIdentifier($resource)
5761

5862
/**
5963
* @param string $className
64+
*
6065
* @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
6166
*/
6267
public function getClassMetadata($className)
@@ -85,7 +90,7 @@ public function findAllSorted($className, array $sorting, array $filterValues, a
8590

8691
foreach ($fields as $field) {
8792
if (isset($sorting[$field])) {
88-
$direction = ($sorting[$field] === 'asc') ? 'asc' : 'desc';
93+
$direction = ('asc' === $sorting[$field]) ? 'asc' : 'desc';
8994
$queryBuilder->addOrderBy('e.'.$field, $direction);
9095
}
9196

src/Halapi/ObjectManager/ObjectManagerInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
namespace Halapi\ObjectManager;
44

55
/**
6-
* Interface ObjectManagerInterface
6+
* Interface ObjectManagerInterface.
7+
*
78
* @author Romain Richard
89
*/
910
interface ObjectManagerInterface
1011
{
1112
/**
1213
* @param object $resource
14+
*
1315
* @return mixed
1416
*/
1517
public function getIdentifier($resource);
1618

1719
/**
1820
* @param object $resource
21+
*
1922
* @return mixed
2023
*/
2124
public function getIdentifierName($resource);
@@ -32,6 +35,7 @@ public function findAllSorted($className, array $sorting, array $filterValues, a
3235

3336
/**
3437
* @param string $className
38+
*
3539
* @return mixed
3640
*/
3741
public function getClassMetadata($className);

src/Halapi/Pager/PagerFanta.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
use Pagerfanta\Adapter\AdapterInterface;
66

77
/**
8-
* Class PagerFanta
8+
* Class PagerFanta.
9+
*
910
* @author Romain Richard
1011
*/
1112
class PagerFanta implements PagerInterface
@@ -22,7 +23,9 @@ class PagerFanta implements PagerInterface
2223

2324
/**
2425
* PagerFanta constructor.
26+
*
2527
* @param string $pagerStrategy
28+
*
2629
* @return PagerFanta
2730
*/
2831
public function __construct($pagerStrategy)
@@ -31,7 +34,8 @@ public function __construct($pagerStrategy)
3134
}
3235

3336
/**
34-
* @inheritdoc
37+
* {@inheritdoc}
38+
*
3539
* @return array
3640
*/
3741
public function getCurrentPageResults()
@@ -40,15 +44,16 @@ public function getCurrentPageResults()
4044
}
4145

4246
/**
43-
* @inheritdoc
47+
* {@inheritdoc}
4448
*/
4549
public function getPageCount()
4650
{
4751
$this->pager->getNbPages();
4852
}
4953

5054
/**
51-
* @inheritdoc
55+
* {@inheritdoc}
56+
*
5257
* @param mixed $results
5358
*/
5459
public function setResults($results)
@@ -58,7 +63,8 @@ public function setResults($results)
5863
}
5964

6065
/**
61-
* @inheritdoc
66+
* {@inheritdoc}
67+
*
6268
* @param int $max
6369
*/
6470
public function setMaxPerPage($max)
@@ -67,7 +73,8 @@ public function setMaxPerPage($max)
6773
}
6874

6975
/**
70-
* @inheritdoc
76+
* {@inheritdoc}
77+
*
7178
* @param int $page
7279
*/
7380
public function setCurrentPage($page)
@@ -80,10 +87,11 @@ public function setCurrentPage($page)
8087
*/
8188
public function setPagerStrategy($pagerStrategy)
8289
{
83-
if (!class_exists('Pagerfanta\Adapter\\'.$pagerStrategy.'Adapter')) {
90+
$pagerAdapter = sprintf('%sAdapter', $pagerStrategy);
91+
if (!class_exists(sprintf('Pagerfanta\Adapter\\%s', $pagerAdapter))) {
8492
throw new \InvalidArgumentException(sprintf(
8593
'No adapter named %s found in %s namespace',
86-
$pagerStrategy.'Adapter',
94+
$pagerAdapter,
8795
'Pagerfanta\Adapter'
8896
));
8997
}
@@ -98,7 +106,7 @@ public function setPagerStrategy($pagerStrategy)
98106
*/
99107
private function getPagerAdapter($results)
100108
{
101-
$adapterClassName = 'Pagerfanta\Adapter\\'.$this->pagerStrategy.'Adapter';
109+
$adapterClassName = sprintf('Pagerfanta\Adapter\\%sAdapter', $this->pagerStrategy);
102110

103111
return new $adapterClassName(...$results);
104112
}

src/Halapi/Pager/PagerInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Halapi\Pager;
44

55
/**
6-
* Class PagerInterface
6+
* Class PagerInterface.
7+
*
78
* @author Romain Richard
89
*/
910
interface PagerInterface
@@ -28,6 +29,7 @@ public function getPageCount();
2829
* depending on which adapter you use.
2930
*
3031
* @param mixed $results
32+
*
3133
* @return mixed
3234
*/
3335
public function setResults($results);
@@ -36,15 +38,13 @@ public function setResults($results);
3638
* Set the maximum number of results per page (aka limit).
3739
*
3840
* @param int $max
39-
* @return void
4041
*/
4142
public function setMaxPerPage($max);
4243

4344
/**
4445
* Set the page to display.
4546
*
4647
* @param int $page
47-
* @return void
4848
*/
4949
public function setCurrentPage($page);
5050
}

src/Halapi/Relation/EmbeddedRelation.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public function getRelation($resource)
6363
foreach ($reflectionClass->getProperties() as $property) {
6464
$propertyName = $property->getName();
6565

66-
if (
67-
$this->annotationReader->isEmbeddable($property)
66+
if ($this->annotationReader->isEmbeddable($property)
6867
&& $this->isEmbeddedRequested($propertyName, $requestedEmbedded)
6968
) {
7069
$embedded[$property->getName()] = $this->getEmbeddedContent($resource, $property);

0 commit comments

Comments
 (0)