Skip to content

Commit

Permalink
qa: set Psalm baseline and apply autofixes
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
  • Loading branch information
weierophinney committed Mar 2, 2021
1 parent 41b1a4c commit e52c8df
Show file tree
Hide file tree
Showing 24 changed files with 1,763 additions and 108 deletions.
1,615 changes: 1,615 additions & 0 deletions psalm-baseline.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
>
<projectFiles>
<directory name="config"/>
Expand Down
4 changes: 2 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public function getCollectionRoute()
/**
* Collection Route Options
*
* @return string
* @return array
*/
public function getCollectionRouteOptions()
{
Expand All @@ -535,7 +535,7 @@ public function getCollectionRouteOptions()
/**
* Collection Route Params
*
* @return string
* @return array
*/
public function getCollectionRouteParams()
{
Expand Down
1 change: 1 addition & 0 deletions src/EntityHydratorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function getHydratorForEntity($entity)

if ($this->metadataMap->has($entity)) {
$metadata = $this->metadataMap->get($class);
/** @psalm-suppress PossiblyFalseReference */
$hydrator = $metadata->getHydrator();
if ($hydrator instanceof ExtractionInterface) {
$this->addHydrator($class, $hydrator);
Expand Down
3 changes: 3 additions & 0 deletions src/Extractor/LinkCollectionExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function getLinkExtractor()
return $this->linkExtractor;
}

/**
* @return void
*/
public function setLinkExtractor(LinkExtractorInterface $linkExtractor)
{
$this->linkExtractor = $linkExtractor;
Expand Down
14 changes: 7 additions & 7 deletions src/Link/PaginationInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function injectPaginationLinks(Collection $halCollection)
return true;
}

private function configureCollection(Collection $halCollection)
private function configureCollection(Collection $halCollection): void
{
$collection = $halCollection->getCollection();
$page = $halCollection->getPage();
Expand All @@ -55,7 +55,7 @@ private function configureCollection(Collection $halCollection)
$collection->setCurrentPageNumber($page);
}

private function injectLinks(Collection $halCollection)
private function injectLinks(Collection $halCollection): void
{
$this->injectSelfLink($halCollection);
$this->injectFirstLink($halCollection);
Expand All @@ -64,27 +64,27 @@ private function injectLinks(Collection $halCollection)
$this->injectNextLink($halCollection);
}

private function injectSelfLink(Collection $halCollection)
private function injectSelfLink(Collection $halCollection): void
{
$page = $halCollection->getPage();
$link = $this->createPaginationLink('self', $halCollection, $page);
$halCollection->getLinks()->add($link, true);
}

private function injectFirstLink(Collection $halCollection)
private function injectFirstLink(Collection $halCollection): void
{
$link = $this->createPaginationLink('first', $halCollection);
$halCollection->getLinks()->add($link);
}

private function injectLastLink(Collection $halCollection)
private function injectLastLink(Collection $halCollection): void
{
$page = $halCollection->getCollection()->count();
$link = $this->createPaginationLink('last', $halCollection, $page);
$halCollection->getLinks()->add($link);
}

private function injectPrevLink(Collection $halCollection)
private function injectPrevLink(Collection $halCollection): void
{
$page = $halCollection->getPage();
$prev = $page > 1 ? $page - 1 : false;
Expand All @@ -95,7 +95,7 @@ private function injectPrevLink(Collection $halCollection)
}
}

private function injectNextLink(Collection $halCollection)
private function injectNextLink(Collection $halCollection): void
{
$page = $halCollection->getPage();
$pageCount = $halCollection->getCollection()->count();
Expand Down
8 changes: 5 additions & 3 deletions src/Link/SelfLinkInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class SelfLinkInjector implements SelfLinkInjectorInterface
{
/**
* @inheritDoc
* {@inheritDoc}
*/
public function injectSelfLink(LinkCollectionAwareInterface $resource, $route, $routeIdentifier = 'id')
{
Expand Down Expand Up @@ -62,7 +62,8 @@ private function createSelfLink($resource, $route, $routeIdentifier)
/**
* @param null|array|Entity|Collection $resource
* @param string $routeIdentifier
* @return array
* @return array|string
* @psalm-return array<empty, empty>|array<array-key, mixed>|string
*/
private function getRouteParams($resource, $routeIdentifier)
{
Expand All @@ -86,7 +87,8 @@ private function getRouteParams($resource, $routeIdentifier)

/**
* @param null|array|Entity|Collection $resource
* @return array
* @return array|string
* @psalm-return array<empty, empty>|array<array-key, mixed>|string
*/
private function getRouteOptions($resource)
{
Expand Down
1 change: 1 addition & 0 deletions src/Link/SelfLinkInjectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface SelfLinkInjectorInterface
*
* @param string $route
* @param string $routeIdentifier
* @return void
*/
public function injectSelfLink(LinkCollectionAwareInterface $resource, $route, $routeIdentifier = 'id');
}
2 changes: 1 addition & 1 deletion src/Metadata/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public function setForceSelfLink($forceSelfLink)
* @param HydratorPluginManager|HydratorPluginManagerInterface $hydrators
* @throws Exception\InvalidArgumentException If $hydrators is an invaild type.
*/
private function setHydrators($hydrators)
private function setHydrators($hydrators): void
{
if ($hydrators instanceof HydratorPluginManagerInterface) {
$this->hydrators = $hydrators;
Expand Down
4 changes: 2 additions & 2 deletions src/Metadata/MetadataMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public function has($class)
*
* Lazy-loads the Metadata instance if one is not present for a matching class.
*
* @param object|string $class Object or classname for which to retrieve metadata
* @return Metadata
* @param object|string $class Object or classname for which to retrieve metadata
* @return Metadata|false
*/
public function get($class)
{
Expand Down
55 changes: 38 additions & 17 deletions src/Plugin/Hal.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ public function setLinkUrlBuilder(LinkUrlBuilder $builder)
* @deprecated Since 1.4.0; use setLinkUrlBuilder() instead.
*
* @throws Exception\DeprecatedMethodException
*
* @return void
*/
public function setServerUrlHelper(callable $helper)
{
Expand All @@ -326,6 +328,8 @@ public function setServerUrlHelper(callable $helper)
* @deprecated Since 1.4.0; use setLinkUrlBuilder() instead.
*
* @throws Exception\DeprecatedMethodException
*
* @return void
*/
public function setUrlHelper(callable $helper)
{
Expand Down Expand Up @@ -581,8 +585,10 @@ public function renderCollection(Collection $halCollection)

$metadataMap = $this->getMetadataMap();

$maxDepth = is_object($collection) && $metadataMap->has($collection) ?
$metadataMap->get($collection)->getMaxDepth() : null;
/** @psalm-suppress PossiblyFalseReference */
$maxDepth = is_object($collection) && $metadataMap->has($collection)
? $metadataMap->get($collection)->getMaxDepth()
: null;

$payload = $halCollection->getAttributes();
$payload['_links'] = $this->fromResource($halCollection);
Expand Down Expand Up @@ -660,6 +666,7 @@ public function renderEntity(Entity $halEntity, $renderEntity = true, $depth = 0

if (is_object($entity)) {
if ($maxDepth === null && $metadataMap->has($entity)) {
/** @psalm-suppress PossiblyFalseReference */
$maxDepth = $metadataMap->get($entity)->getMaxDepth();
}

Expand Down Expand Up @@ -690,6 +697,7 @@ public function renderEntity(Entity $halEntity, $renderEntity = true, $depth = 0

foreach ($entity as $key => $value) {
if (is_object($value) && $metadataMap->has($value)) {
/** @psalm-suppress PossiblyFalseArgument */
$value = $this->getResourceFactory()->createEntityFromMetadata(
$value,
$metadataMap->get($value),
Expand Down Expand Up @@ -856,7 +864,7 @@ public function createEntityFromMetadata($object, Metadata $metadata, $renderEmb
* @param Entity|array|object $resource
* @param string $route
* @param string $routeIdentifierName
* @return Entity
* @return Collection|Entity
*/
public function createResource($resource, $route, $routeIdentifierName)
{
Expand All @@ -871,16 +879,17 @@ public function createResource($resource, $route, $routeIdentifierName)
/**
* Create an Entity instance and inject it with a self relational link if necessary
*
* @param Entity|array|object $entity
* @param string $route
* @param string $routeIdentifierName
* @return Entity
* @param Entity|array|object $entity
* @param string $route
* @param string $routeIdentifierName
* @return Collection|Entity
*/
public function createEntity($entity, $route, $routeIdentifierName)
{
$metadataMap = $this->getMetadataMap();

if (is_object($entity) && $metadataMap->has($entity)) {
/** @psalm-suppress PossiblyFalseArgument */
$halEntity = $this->getResourceFactory()->createEntityFromMetadata(
$entity,
$metadataMap->get($entity)
Expand Down Expand Up @@ -914,6 +923,7 @@ public function createCollection($collection, $route = null)
{
$metadataMap = $this->getMetadataMap();
if (is_object($collection) && $metadataMap->has($collection)) {
/** @psalm-suppress PossiblyFalseArgument */
$collection = $this->getResourceFactory()->createCollectionFromMetadata(
$collection,
$metadataMap->get($collection)
Expand Down Expand Up @@ -944,8 +954,9 @@ public function createCollectionFromMetadata($object, Metadata $metadata)
/**
* Inject a "self" relational link based on the route and identifier
*
* @param string $route
* @param string $routeIdentifier
* @param string $route
* @param string $routeIdentifier
* @return void
*/
public function injectSelfLink(LinkCollectionAwareInterface $resource, $route, $routeIdentifier = 'id')
{
Expand All @@ -969,10 +980,11 @@ protected function injectPaginationLinks(Collection $halCollection)
* Removes the key from the parent representation, and creates a
* representation for the key in the _embedded object.
*
* @param array $parent
* @param string $key
* @param int $depth depth of the current rendering recursion
* @param int $maxDepth maximum rendering depth for the current metadata
* @param array $parent
* @param string $key
* @param int $depth depth of the current rendering recursion
* @param int $maxDepth maximum rendering depth for the current metadata
* @return void
*/
protected function extractEmbeddedEntity(array &$parent, $key, Entity $entity, $depth = 0, $maxDepth = null)
{
Expand All @@ -994,10 +1006,11 @@ protected function extractEmbeddedEntity(array &$parent, $key, Entity $entity, $
* Removes the key from the parent representation, and creates a
* representation for the key in the _embedded object.
*
* @param array $parent
* @param string $key
* @param int $depth depth of the current rendering recursion
* @param int $maxDepth maximum rendering depth for the current metadata
* @param array $parent
* @param string $key
* @param int $depth depth of the current rendering recursion
* @param int $maxDepth maximum rendering depth for the current metadata
* @return void
*/
protected function extractEmbeddedCollection(
array &$parent,
Expand Down Expand Up @@ -1050,6 +1063,7 @@ protected function extractCollection(Collection $halCollection, $depth = 0, $max
$entity = $eventParams['entity'];

if (is_object($entity) && $metadataMap->has($entity)) {
/** @psalm-suppress PossiblyFalseArgument */
$entity = $this->getResourceFactory()->createEntityFromMetadata($entity, $metadataMap->get($entity));
}

Expand All @@ -1065,6 +1079,7 @@ protected function extractCollection(Collection $halCollection, $depth = 0, $max

foreach ($entity as $key => $value) {
if (is_object($value) && $metadataMap->has($value)) {
/** @psalm-suppress PossiblyFalseArgument */
$value = $this->getResourceFactory()->createEntityFromMetadata($value, $metadataMap->get($value));
}

Expand Down Expand Up @@ -1136,6 +1151,10 @@ protected function getIdFromEntity($entity)
'resource' => $entity,
];

/**
* @param mixed $r
* @return bool
*/
$callback = function ($r) {
return null !== $r && false !== $r;
};
Expand Down Expand Up @@ -1218,6 +1237,8 @@ protected function marshalLinkFromMetadata(
* Inject any links found in the metadata into the resource's link collection
*
* @deprecated
*
* @return void
*/
protected function marshalMetadataLinks(Metadata $metadata, LinkCollection $links)
{
Expand Down
8 changes: 6 additions & 2 deletions src/RendererOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class RendererOptions extends AbstractOptions

/**
* @param string $hydrator
* @return void
*/
public function setDefaultHydrator($hydrator)
{
Expand All @@ -42,14 +43,15 @@ public function getDefaultHydrator()

/**
* @param bool $flag
* @return void
*/
public function setRenderEmbeddedEntities($flag)
{
$this->renderEmbeddedEntities = (bool) $flag;
}

/**
* @return string
* @return bool
*/
public function getRenderEmbeddedEntities()
{
Expand All @@ -58,14 +60,15 @@ public function getRenderEmbeddedEntities()

/**
* @param bool $flag
* @return void
*/
public function setRenderEmbeddedCollections($flag)
{
$this->renderEmbeddedCollections = (bool) $flag;
}

/**
* @return string
* @return bool
*/
public function getRenderEmbeddedCollections()
{
Expand All @@ -74,6 +77,7 @@ public function getRenderEmbeddedCollections()

/**
* @param array $hydrators
* @return void
*/
public function setHydrators(array $hydrators)
{
Expand Down
2 changes: 2 additions & 0 deletions src/ResourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ public function marshalLinkFromMetadata(

/**
* Inject any links found in the metadata into the resource's link collection
*
* @return void
*/
public function marshalMetadataLinks(Metadata $metadata, LinkCollection $links)
{
Expand Down
2 changes: 2 additions & 0 deletions src/View/HalJsonRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function __construct(ApiProblemRenderer $apiProblemRenderer)
* Set helper plugin manager instance.
*
* Also ensures that the 'Hal' helper is present.
*
* @return void
*/
public function setHelperPluginManager(HelperPluginManager $helpers)
{
Expand Down
Loading

0 comments on commit e52c8df

Please sign in to comment.