Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop PHP 7, add PHP 8.2 Support #39

Merged
merged 7 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
},
"config": {
"sort-packages": true,
"platform": {
"php": "8.0.99"
},
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"composer/package-versions-deprecated": true
Expand All @@ -32,9 +35,9 @@
}
},
"require": {
"php": "^7.3 || ~8.0.0 || ~8.1.0",
"php": "~8.0.0 || ~8.1.0 || ~8.2.0",
"ext-json": "*",
"laminas-api-tools/api-tools-api-problem": "^1.2.1",
"laminas-api-tools/api-tools-api-problem": "^1.6.0",
"laminas/laminas-eventmanager": "^3.0.1",
"laminas/laminas-filter": "^2.7.1",
"laminas/laminas-http": "^2.5.4",
Expand All @@ -50,11 +53,12 @@
"require-dev": {
"laminas/laminas-coding-standard": "~2.3.0",
"laminas/laminas-modulemanager": "^2.10.1",
"laminas/laminas-router": "^3.11",
"phpdocumentor/reflection-docblock": "^5.2.2",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3",
"psalm/plugin-phpunit": "^0.15.1",
"vimeo/psalm": "^4.6"
"phpunit/phpunit": "^9.5.27",
"psalm/plugin-phpunit": "^0.16.1",
"vimeo/psalm": "^4.30"
},
"autoload": {
"psr-4": {
Expand Down
1,985 changes: 1,045 additions & 940 deletions composer.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
<!-- Include all rules from Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>

<rule ref="WebimpressCodingStandard.PHP.CorrectClassNameCase.Invalid">
<exclude-pattern>src/Plugin/Hal.php</exclude-pattern>
<exclude-pattern>test/ResourceFactoryTest.php</exclude-pattern>
</rule>
<rule ref="WebimpressCodingStandard.PHP.CorrectClassNameCase.Invalid"/>

<rule ref="WebimpressCodingStandard.PHP.CorrectClassNameCase.InvalidInPhpDocs">
<exclude-pattern>src/Plugin/Hal.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Variables.UselessVariable.UselessVariable">
<exclude-pattern>src/View/HalJsonRenderer.php</exclude-pattern>
<exclude-pattern>src/Metadata/MetadataMap.php</exclude-pattern>
</rule>
</ruleset>
5 changes: 2 additions & 3 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
errorLevel="1"
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"/>
<directory name="src"/>
<directory name="test"/>
<ignoreFiles>
<directory name="config"/>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
Expand Down
21 changes: 11 additions & 10 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
use Laminas\Stdlib\ArrayUtils;
use Traversable;

use function get_class;
use function get_debug_type;
use function gettype;
use function is_array;
use function is_int;
use function is_numeric;
use function is_object;
use function sprintf;
use function trigger_error;

Expand All @@ -36,7 +35,7 @@ class Collection implements Link\LinkCollectionAwareInterface
*/
protected $attributes = [];

/** @var array|Traversable|Paginator */
/** @var Paginator|Traversable|array<array-key, mixed> */
protected $collection;

/**
Expand Down Expand Up @@ -96,22 +95,24 @@ class Collection implements Link\LinkCollectionAwareInterface
protected $entityRouteParams = [];

/**
* @param array|Traversable|Paginator $collection
* @param Paginator|Traversable|array<array-key, mixed> $collection
* @param string $entityRoute
* @param array|Traversable $entityRouteParams
* @param array|Traversable $entityRouteOptions
* @throws InvalidCollectionException
*/
public function __construct($collection, $entityRoute = null, $entityRouteParams = null, $entityRouteOptions = null)
{
if (! is_array($collection) && ! $collection instanceof Traversable) {
/** @psalm-suppress DocblockTypeContradiction */
if (! is_array($collection) && ! $collection instanceof Traversable && ! $collection instanceof Paginator) {
throw new InvalidCollectionException(sprintf(
'%s expects an array or Traversable; received "%s"',
__METHOD__,
is_object($collection) ? get_class($collection) : gettype($collection)
get_debug_type($collection)
));
}

/** @psalm-suppress PossiblyInvalidPropertyAssignmentValue */
$this->collection = $collection;

if (null !== $entityRoute) {
Expand Down Expand Up @@ -189,7 +190,7 @@ public function setCollectionRouteOptions($options)
throw new InvalidArgumentException(sprintf(
'%s expects an array or Traversable; received "%s"',
__METHOD__,
is_object($options) ? get_class($options) : gettype($options)
get_debug_type($options)
));
}
$this->collectionRouteOptions = $options;
Expand All @@ -212,7 +213,7 @@ public function setCollectionRouteParams($params)
throw new InvalidArgumentException(sprintf(
'%s expects an array or Traversable; received "%s"',
__METHOD__,
is_object($params) ? get_class($params) : gettype($params)
get_debug_type($params)
));
}
$this->collectionRouteParams = $params;
Expand Down Expand Up @@ -377,7 +378,7 @@ public function setEntityRouteOptions($options)
throw new InvalidArgumentException(sprintf(
'%s expects an array or Traversable; received "%s"',
__METHOD__,
is_object($options) ? get_class($options) : gettype($options)
get_debug_type($options)
));
}
$this->entityRouteOptions = $options;
Expand Down Expand Up @@ -421,7 +422,7 @@ public function setEntityRouteParams($params)
throw new InvalidArgumentException(sprintf(
'%s expects an array or Traversable; received "%s"',
__METHOD__,
is_object($params) ? get_class($params) : gettype($params)
get_debug_type($params)
));
}
$this->entityRouteParams = $params;
Expand Down
17 changes: 9 additions & 8 deletions src/EntityHydratorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
use Laminas\Hydrator\HydratorPluginManager;
use Laminas\Hydrator\HydratorPluginManagerInterface;

use function get_class;
use function gettype;
use function is_object;
use function get_debug_type;
use function is_string;
use function sprintf;
use function strtolower;

Expand Down Expand Up @@ -53,7 +52,7 @@ public function __construct($hydrators, MetadataMap $map)
self::class,
HydratorPluginManagerInterface::class,
HydratorPluginManager::class,
is_object($hydrators) ? get_class($hydrators) : gettype($hydrators)
get_debug_type($hydrators)
));
}
$this->hydrators = $hydrators;
Expand All @@ -72,13 +71,15 @@ public function getHydratorManager()
* Map an entity class to a specific hydrator instance
*
* @param string $class
* @param ExtractionInterface $hydrator
* @param ExtractionInterface|string $hydrator
* @return self
*/
public function addHydrator($class, $hydrator)
{
if (! $hydrator instanceof ExtractionInterface) {
$hydrator = $this->hydrators->get($hydrator);
if (is_string($hydrator)) {
/** @var ExtractionInterface $hydratorInstance */
$hydratorInstance = $this->hydrators->get($hydrator);
$hydrator = $hydratorInstance;
}

$filteredClass = strtolower($class);
Expand Down Expand Up @@ -109,7 +110,7 @@ public function setDefaultHydrator(ExtractionInterface $hydrator)
*/
public function getHydratorForEntity($entity)
{
$class = get_class($entity);
$class = $entity::class;
$classLower = strtolower($class);

if (isset($this->hydratorMap[$classLower])) {
Expand Down
13 changes: 8 additions & 5 deletions src/Extractor/EntityExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ public function __construct(EntityHydratorManager $entityHydratorManager)
/**
* @inheritDoc
*/
public function extract(object $entity): array
public function extract(object $object): array
{
if (isset($this->serializedEntities[$entity])) {
return $this->serializedEntities[$entity];
if (isset($this->serializedEntities[$object])) {
/** @psalm-var array<array-key, mixed> */
return $this->serializedEntities[$object];
}

$this->serializedEntities[$entity] = $this->extractEntity($entity);
$this->serializedEntities[$object] = $this->extractEntity($object);

return $this->serializedEntities[$entity];
/** @psalm-var array<array-key, mixed> */
return $this->serializedEntities[$object];
}

private function extractEntity(object $entity): array
Expand All @@ -56,6 +58,7 @@ private function extractEntity(object $entity): array
}

if ($entity instanceof JsonSerializable) {
/** @psalm-var array<array-key, mixed> */
return $entity->jsonSerialize();
}

Expand Down
1 change: 1 addition & 0 deletions src/Extractor/LinkCollectionExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function extract(LinkCollection $collection)
}

$aggregate = [];
/** @var mixed $subLink */
foreach ($linkDefinition as $subLink) {
if (! $subLink instanceof Link) {
throw new DomainException(sprintf(
Expand Down
2 changes: 2 additions & 0 deletions src/Factory/HalConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Laminas\ApiTools\Hal\Factory;

use ArrayAccess;
// phpcs:ignore WebimpressCodingStandard.PHP.CorrectClassNameCase.Invalid
use Interop\Container\ContainerInterface;

use function is_array;
Expand All @@ -16,6 +17,7 @@ class HalConfigFactory
*/
public function __invoke(ContainerInterface $container)
{
/** @var array<string,mixed> $config */
$config = $container->has('config')
? $container->get('config')
: [];
Expand Down
12 changes: 8 additions & 4 deletions src/Factory/HalControllerPluginFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Laminas\ApiTools\Hal\Factory;

// phpcs:ignore WebimpressCodingStandard.PHP.CorrectClassNameCase.Invalid
use Interop\Container\ContainerInterface;
use Laminas\ApiTools\Hal\Plugin\Hal;
use Laminas\ServiceManager\AbstractPluginManager;
Expand All @@ -20,6 +21,7 @@ class HalControllerPluginFactory implements FactoryInterface
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
{
$helpers = $container->get('ViewHelperManager');
/** @psalm-var Hal */
return $helpers->get('Hal');
}

Expand All @@ -28,11 +30,13 @@ public function __invoke(ContainerInterface $container, $requestedName, ?array $
*
* @return Hal
*/
public function createService(ServiceLocatorInterface $container)
public function createService(ServiceLocatorInterface $serviceLocator)
{
if ($container instanceof AbstractPluginManager) {
$container = $container->getServiceLocator() ?: $container;
if ($serviceLocator instanceof AbstractPluginManager) {
/** @psalm-suppress RedundantConditionGivenDocblockType */
$serviceLocator = $serviceLocator->getServiceLocator() ?: $serviceLocator;
}
return $this($container, Hal::class);
/** @psalm-var Hal */
return $this($serviceLocator, Hal::class);
}
}
8 changes: 7 additions & 1 deletion src/Factory/HalJsonRendererFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

namespace Laminas\ApiTools\Hal\Factory;

// phpcs:ignore WebimpressCodingStandard.PHP.CorrectClassNameCase.Invalid
use Interop\Container\ContainerInterface;
use Laminas\ApiTools\ApiProblem\View\ApiProblemRenderer;
use Laminas\ApiTools\Hal\View\HalJsonRenderer;
use Laminas\View\HelperPluginManager;

use function assert;

class HalJsonRendererFactory
{
Expand All @@ -15,8 +19,10 @@ class HalJsonRendererFactory
*/
public function __invoke(ContainerInterface $container)
{
$helpers = $container->get('ViewHelperManager');
$helpers = $container->get('ViewHelperManager');
assert($helpers instanceof HelperPluginManager);
$apiProblemRenderer = $container->get(ApiProblemRenderer::class);
assert($apiProblemRenderer instanceof ApiProblemRenderer);

$renderer = new HalJsonRenderer($apiProblemRenderer);
$renderer->setHelperPluginManager($helpers);
Expand Down
9 changes: 8 additions & 1 deletion src/Factory/HalJsonStrategyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@

namespace Laminas\ApiTools\Hal\Factory;

// phpcs:ignore WebimpressCodingStandard.PHP.CorrectClassNameCase.Invalid
use Interop\Container\ContainerInterface;
use Laminas\ApiTools\Hal\View\HalJsonRenderer;
use Laminas\ApiTools\Hal\View\HalJsonStrategy;

use function assert;

class HalJsonStrategyFactory
{
/**
* @return HalJsonStrategy
*/
public function __invoke(ContainerInterface $container)
{
return new HalJsonStrategy($container->get('Laminas\ApiTools\Hal\JsonRenderer'));
$renderer = $container->get('Laminas\ApiTools\Hal\JsonRenderer');
rogervila marked this conversation as resolved.
Show resolved Hide resolved
assert($renderer instanceof HalJsonRenderer);

return new HalJsonStrategy($renderer);
}
}
Loading