diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 92dc0323..7d6d1f74 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6,8 +6,26 @@ parameters: count: 2 path: src/Client.php + - + message: '#^Instanceof between ArrayAccess and ArrayAccess will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/Client.php + + - + message: '#^Instanceof between Joomla\\Application\\WebApplicationInterface and Joomla\\Application\\WebApplicationInterface will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/Client.php + - message: '#^Method Joomla\\OAuth2\\Client\:\:query\(\) should return Joomla\\Http\\Response but returns false\.$#' identifier: return.type count: 1 path: src/Client.php + + - + message: '#^Result of && is always false\.$#' + identifier: booleanAnd.alwaysFalse + count: 1 + path: src/Client.php diff --git a/src/Client.php b/src/Client.php index a6d98fd1..bb904a58 100644 --- a/src/Client.php +++ b/src/Client.php @@ -7,8 +7,6 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -declare(strict_types=1); - namespace Joomla\OAuth2; use Joomla\Application\WebApplicationInterface; @@ -67,8 +65,14 @@ class Client * * @since 1.0 */ - public function __construct(array|\ArrayAccess $options = [], ?Http $http = null, ?Input $input = null, ?WebApplicationInterface $application = null) + public function __construct($options = [], ?Http $http = null, ?Input $input = null, ?WebApplicationInterface $application = null) { + if (!\is_array($options) && !($options instanceof \ArrayAccess)) { + throw new \InvalidArgumentException( + 'The options param must be an array or implement the ArrayAccess interface.' + ); + } + $this->options = $options; $this->http = $http ?: (new HttpFactory())->getHttp($this->options); $this->input = $input ?: ($application ? $application->getInput() : new Input()); @@ -123,6 +127,12 @@ public function authenticate() } if ($this->getOption('sendheaders')) { + if (!($this->application instanceof WebApplicationInterface)) { + throw new \RuntimeException( + \sprintf('A "%s" implementation is required to process authentication.', WebApplicationInterface::class) + ); + } + $this->application->redirect($this->createUrl()); }