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

Merge release 3.5.0 into 4.0.x #141

Merged
merged 11 commits into from
Mar 14, 2023
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"php": "8.0.99"
},
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"webimpress/composer-extra-dependency": true
}
},
"extra": {
Expand Down
330 changes: 168 additions & 162 deletions composer.lock

Large diffs are not rendered by default.

28 changes: 10 additions & 18 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.27.0@faf106e717c37b8c81721845dba9de3d8deed8ff">
<files psalm-version="4.29.0@7ec5ffbd5f68ae03782d7fd33fff0c45a69f95b3">
<file src="src/Application.php">
<ImplementedReturnTypeMismatch occurrences="1">
<code>Application</code>
Expand Down Expand Up @@ -95,20 +95,16 @@
</ParamNameMismatch>
</file>
<file src="src/Controller/AbstractRestfulController.php">
<DocblockTypeContradiction occurrences="3">
<DocblockTypeContradiction occurrences="2">
<code>! $headerContentType</code>
<code>$headerContentType</code>
<code>is_object($handler)</code>
</DocblockTypeContradiction>
<PossiblyNullArgument occurrences="1">
<code>$contentType</code>
</PossiblyNullArgument>
<RedundantCastGivenDocblockType occurrences="1">
<code>(string) $name</code>
</RedundantCastGivenDocblockType>
<RedundantConditionGivenDocblockType occurrences="1">
<code>gettype($handler)</code>
</RedundantConditionGivenDocblockType>
<TypeDoesNotContainType occurrences="1">
<code>! is_array($parsedParams)</code>
</TypeDoesNotContainType>
Expand Down Expand Up @@ -327,13 +323,13 @@
<code>$name</code>
</ParamNameMismatch>
<UndefinedClass occurrences="7">
<code>AcceptableViewModelSelector</code>
<code>CreateHttpNotFoundModel</code>
<code>Forward</code>
<code>Layout</code>
<code>Params</code>
<code>Redirect</code>
<code>Url</code>
<code>\Zend\Mvc\Controller\Plugin\AcceptableViewModelSelector</code>
<code>\Zend\Mvc\Controller\Plugin\CreateHttpNotFoundModel</code>
<code>\Zend\Mvc\Controller\Plugin\Forward</code>
<code>\Zend\Mvc\Controller\Plugin\Layout</code>
<code>\Zend\Mvc\Controller\Plugin\Params</code>
<code>\Zend\Mvc\Controller\Plugin\Redirect</code>
<code>\Zend\Mvc\Controller\Plugin\Url</code>
</UndefinedClass>
</file>
<file src="src/DispatchListener.php">
Expand Down Expand Up @@ -811,8 +807,7 @@
</UndefinedThisPropertyFetch>
</file>
<file src="test/Controller/LazyControllerAbstractFactoryTest.php">
<PossiblyInvalidMethodCall occurrences="9">
<code>willReturn</code>
<PossiblyInvalidMethodCall occurrences="8">
<code>willReturn</code>
<code>willReturn</code>
<code>willReturn</code>
Expand All @@ -835,9 +830,6 @@
<code>reveal</code>
<code>reveal</code>
</PossiblyUndefinedMethod>
<UndefinedClass occurrences="1">
<code>SampleInterface</code>
</UndefinedClass>
</file>
<file src="test/Controller/Plugin/AcceptableViewModelSelectorTest.php">
<UndefinedThisPropertyAssignment occurrences="4">
Expand Down
9 changes: 1 addition & 8 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,12 @@ class Application implements
/** @var ResponseInterface */
protected $response;

/** @var ServiceManager */
protected $serviceManager;

/**
* Constructor
*/
public function __construct(
ServiceManager $serviceManager,
protected ServiceManager $serviceManager,
?EventManagerInterface $events = null,
?RequestInterface $request = null,
?ResponseInterface $response = null
) {
$this->serviceManager = $serviceManager;
$this->setEventManager($events ?: $serviceManager->get('EventManager'));
$this->request = $request ?: $serviceManager->get('Request');
$this->response = $response ?: $serviceManager->get('Response');
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/AbstractActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Laminas\Mvc\Controller;

use Laminas\Mvc\Exception;
use Laminas\Mvc\Exception\DomainException;
use Laminas\Mvc\MvcEvent;
use Laminas\View\Model\ViewModel;

Expand Down Expand Up @@ -61,7 +62,7 @@ public function onDispatch(MvcEvent $e)
* @todo Determine requirements for when route match is missing.
* Potentially allow pulling directly from request metadata?
*/
throw new Exception\DomainException('Missing route matches; unsure how to retrieve action');
throw new DomainException('Missing route matches; unsure how to retrieve action');
}

$action = $routeMatch->getParam('action', 'not-found');
Expand Down
6 changes: 4 additions & 2 deletions src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use Laminas\EventManager\EventManager;
use Laminas\EventManager\EventManagerAwareInterface;
use Laminas\EventManager\EventManagerInterface;
use Laminas\Http\Header\Accept\FieldValuePart\AbstractFieldValuePart;
use Laminas\Http\PhpEnvironment\Response as HttpResponse;
use Laminas\Http\Request as HttpRequest;
use Laminas\Mvc\Controller\Plugin\Forward;
use Laminas\Mvc\Controller\Plugin\Layout;
use Laminas\Mvc\Controller\Plugin\Params;
use Laminas\Mvc\Controller\Plugin\Redirect;
use Laminas\Mvc\Controller\Plugin\Url;
Expand Down Expand Up @@ -40,7 +42,7 @@
*
* Convenience methods for pre-built plugins (@see __call):
* @codingStandardsIgnoreStart
* @method \Laminas\View\Model\ModelInterface acceptableViewModelSelector(array $matchAgainst = null, bool $returnDefault = true, \Laminas\Http\Header\Accept\FieldValuePart\AbstractFieldValuePart $resultReference = null)
* @method ModelInterface acceptableViewModelSelector(array $matchAgainst = null, bool $returnDefault = true, AbstractFieldValuePart $resultReference = null)
* @codingStandardsIgnoreEnd
* @method Forward forward()
* @method Layout|ModelInterface layout(string $template = null)
Expand Down Expand Up @@ -99,7 +101,7 @@ public function dispatch(Request $request, ?Response $response = null)
$e->setResponse($response);
$e->setTarget($this);

$result = $this->getEventManager()->triggerEventUntil(static fn($test) => $test instanceof Response, $e);
$result = $this->getEventManager()->triggerEventUntil(static fn($test): bool => $test instanceof Response, $e);

if ($result->stopped()) {
return $result->last();
Expand Down
43 changes: 18 additions & 25 deletions src/Controller/AbstractRestfulController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Laminas\Http\Header\ContentType;
use Laminas\Http\Request as HttpRequest;
use Laminas\Mvc\Exception;
use Laminas\Mvc\Exception\DomainException;
use Laminas\Mvc\Exception\InvalidArgumentException;
use Laminas\Mvc\Exception\RuntimeException;
use Laminas\Mvc\MvcEvent;
use Laminas\Router\RouteMatch;
use Laminas\Stdlib\RequestInterface as Request;
Expand All @@ -17,17 +20,16 @@
use function array_shift;
use function count;
use function explode;
use function gettype;
use function get_debug_type;
use function is_array;
use function is_callable;
use function is_object;
use function json_decode;
use function method_exists;
use function parse_str;
use function reset;
use function sprintf;
use function str_contains;
use function stripos;
use function strpos;
use function strtolower;
use function trim;

Expand Down Expand Up @@ -104,10 +106,9 @@ public function getIdentifierName()
/**
* Create a new resource
*
* @param mixed $data
* @return mixed
*/
public function create($data)
public function create(mixed $data)
{
$this->response->setStatusCode(405);

Expand All @@ -119,10 +120,9 @@ public function create($data)
/**
* Delete an existing resource
*
* @param mixed $id
* @return mixed
*/
public function delete($id)
public function delete(mixed $id)
{
$this->response->setStatusCode(405);

Expand All @@ -149,10 +149,9 @@ public function deleteList($data)
/**
* Return single resource
*
* @param mixed $id
* @return mixed
*/
public function get($id)
public function get(mixed $id)
{
$this->response->setStatusCode(405);

Expand Down Expand Up @@ -238,10 +237,9 @@ public function patch($id, $data)
* Not marked as abstract, as that would introduce a BC break
* (introduced in 2.1.0); instead, raises an exception if not implemented.
*
* @param mixed $data
* @return mixed
*/
public function replaceList($data)
public function replaceList(mixed $data)
{
$this->response->setStatusCode(405);

Expand All @@ -256,10 +254,9 @@ public function replaceList($data)
* Not marked as abstract, as that would introduce a BC break
* (introduced in 2.2.0); instead, raises an exception if not implemented.
*
* @param mixed $data
* @return mixed
*/
public function patchList($data)
public function patchList(mixed $data)
{
$this->response->setStatusCode(405);

Expand All @@ -271,11 +268,9 @@ public function patchList($data)
/**
* Update an existing resource
*
* @param mixed $id
* @param mixed $data
* @return mixed
*/
public function update($id, $data)
public function update(mixed $id, mixed $data)
{
$this->response->setStatusCode(405);

Expand Down Expand Up @@ -312,7 +307,7 @@ public function notFoundAction()
public function dispatch(Request $request, ?Response $response = null)
{
if (! $request instanceof HttpRequest) {
throw new Exception\InvalidArgumentException('Expected an HTTP request');
throw new InvalidArgumentException('Expected an HTTP request');
}

return parent::dispatch($request, $response);
Expand All @@ -333,7 +328,7 @@ public function onDispatch(MvcEvent $e)
* @todo Determine requirements for when route match is missing.
* Potentially allow pulling directly from request metadata?
*/
throw new Exception\DomainException('Missing route matches; unsure how to retrieve action');
throw new DomainException('Missing route matches; unsure how to retrieve action');
}

$request = $e->getRequest();
Expand Down Expand Up @@ -421,7 +416,7 @@ public function onDispatch(MvcEvent $e)
try {
$action = 'patchList';
$return = $this->patchList($data);
} catch (Exception\RuntimeException $ex) {
} catch (RuntimeException) {
$response = $e->getResponse();
$response->setStatusCode(405);
return $response;
Expand Down Expand Up @@ -489,7 +484,7 @@ public function requestHasContentType(Request $request, $contentType = '')
}

$requestedContentType = $headerContentType->getFieldValue();
if (false !== strpos($requestedContentType, ';')) {
if (str_contains($requestedContentType, ';')) {
$headerData = explode(';', $requestedContentType);
$requestedContentType = array_shift($headerData);
}
Expand Down Expand Up @@ -534,9 +529,9 @@ public function requestHasContentType(Request $request, $contentType = '')
public function addHttpMethodHandler($method, $handler) /* Callable */
{
if (! is_callable($handler)) {
throw new Exception\InvalidArgumentException(sprintf(
throw new InvalidArgumentException(sprintf(
'Invalid HTTP method handler: must be a callable; received "%s"',
is_object($handler) ? $handler::class : gettype($handler)
get_debug_type($handler)
));
}
$method = strtolower($method);
Expand Down Expand Up @@ -579,12 +574,11 @@ protected function getIdentifier($routeMatch, $request)
* value, the method assumes that we have non-urlencoded content and
* returns the raw content; otherwise, the array created is returned.
*
* @param mixed $request
* @return object|string|array
* @throws Exception\DomainException If a JSON request was made, but no
* method for parsing JSON is available.
*/
protected function processBodyContent($request)
protected function processBodyContent(mixed $request)
{
$content = $request->getContent();

Expand Down Expand Up @@ -618,7 +612,6 @@ protected function processBodyContent($request)
*/
protected function jsonDecode(string $string)
{
// @TODO Drop as ext-json is included by default in 7.4 and can't be disabled in 8.0
return json_decode($string, $this->jsonDecodeType, 512, JSON_THROW_ON_ERROR);
}
}
13 changes: 4 additions & 9 deletions src/Controller/ControllerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
use Laminas\Stdlib\DispatchableInterface;
use Psr\Container\ContainerInterface;

use function gettype;
use function is_object;
use function get_debug_type;
use function method_exists;
use function sprintf;

Expand Down Expand Up @@ -56,17 +55,13 @@ public function __construct($configOrContainerInstance, array $config = [])
parent::__construct($configOrContainerInstance, $config);
}

/**
* Validate a plugin
*
* {@inheritDoc}
*/
public function validate($instance): void
/** {@inheritDoc} */
public function validate(mixed $instance): void
{
if (! $instance instanceof $this->instanceOf) {
throw new InvalidServiceException(sprintf(
'Plugin of type "%s" is invalid; must implement %s',
is_object($instance) ? $instance::class : gettype($instance),
get_debug_type($instance),
$this->instanceOf
));
}
Expand Down
11 changes: 4 additions & 7 deletions src/Controller/Plugin/Forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\EventManager\SharedEventManagerInterface as SharedEvents;
use Laminas\Mvc\Controller\ControllerManager;
use Laminas\Mvc\Exception;
use Laminas\Mvc\Exception\DomainException;
use Laminas\Mvc\InjectApplicationEventInterface;
use Laminas\Mvc\MvcEvent;
use Laminas\Mvc\View\Http\InjectViewModelListener;
Expand All @@ -23,9 +24,6 @@

class Forward extends AbstractPlugin
{
/** @var ControllerManager */
protected $controllers;

/** @var MvcEvent */
protected $event;

Expand All @@ -38,9 +36,8 @@ class Forward extends AbstractPlugin
/** @var array[]|null */
protected $listenersToDetach;

public function __construct(ControllerManager $controllers)
public function __construct(protected ControllerManager $controllers)
{
$this->controllers = $controllers;
}

/**
Expand Down Expand Up @@ -124,7 +121,7 @@ public function dispatch($name, ?array $params = null)
}

if ($this->numNestedForwards > $this->maxNestedForwards) {
throw new Exception\DomainException(
throw new DomainException(
"Circular forwarding detected: greater than $this->maxNestedForwards nested forwards"
);
}
Expand Down Expand Up @@ -235,7 +232,7 @@ protected function getEvent()

$controller = $this->getController();
if (! $controller instanceof InjectApplicationEventInterface) {
throw new Exception\DomainException(sprintf(
throw new DomainException(sprintf(
'Forward plugin requires a controller that implements InjectApplicationEventInterface; received %s',
is_object($controller) ? $controller::class : var_export($controller, true)
));
Expand Down
Loading