From fe125a85bbda8a6e78f9b2e2154552414fe75144 Mon Sep 17 00:00:00 2001 From: Mike Russell <3056352+MichaelJ2324@users.noreply.github.com> Date: Tue, 20 May 2025 10:58:17 -0400 Subject: [PATCH] Fix `Undefined array key 0` Error --- rector.php | 6 ++++++ src/Endpoint/Abstracts/AbstractEndpoint.php | 1 + src/Endpoint/Abstracts/AbstractModelEndpoint.php | 1 + .../Provider/AbstractMultiVersionEndpointProvider.php | 6 ++++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/rector.php b/rector.php index 5f3c0c8..cfcc3ba 100644 --- a/rector.php +++ b/rector.php @@ -4,6 +4,7 @@ use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector; use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector; +use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; use Rector\Set\ValueObject\SetList; return RectorConfig::configure() @@ -12,9 +13,14 @@ DisallowedEmptyRuleFixerRector::class, IssetOnPropertyObjectToPropertyExistsRector::class, SimplifyEmptyCheckOnEmptyArrayRector::class, + EncapsedStringsToSprintfRector::class ]) ->withSets([ SetList::PHP_80, + SetList::PHP_81, + SetList::PHP_82, + SetList::PHP_83, + SetList::PHP_84, SetList::DEAD_CODE, SetList::CODE_QUALITY, SetList::CODING_STYLE, diff --git a/src/Endpoint/Abstracts/AbstractEndpoint.php b/src/Endpoint/Abstracts/AbstractEndpoint.php index 975cd2c..bc795e6 100644 --- a/src/Endpoint/Abstracts/AbstractEndpoint.php +++ b/src/Endpoint/Abstracts/AbstractEndpoint.php @@ -157,6 +157,7 @@ protected function normalizeUrlArgs(array $urlArgs): array } } } + $argNum++; } } diff --git a/src/Endpoint/Abstracts/AbstractModelEndpoint.php b/src/Endpoint/Abstracts/AbstractModelEndpoint.php index 8e71a3b..a4eb5e6 100644 --- a/src/Endpoint/Abstracts/AbstractModelEndpoint.php +++ b/src/Endpoint/Abstracts/AbstractModelEndpoint.php @@ -132,6 +132,7 @@ protected function setIdFromUrlArgs(): void if ($id != $this->_urlArgs[static::MODEL_ID_VAR] && !empty($id)) { $this->clear(); } + $prop = $this->getKeyProperty(); $this->set($prop, $this->_urlArgs[static::MODEL_ID_VAR]); unset($this->_urlArgs[static::MODEL_ID_VAR]); diff --git a/src/Endpoint/Provider/AbstractMultiVersionEndpointProvider.php b/src/Endpoint/Provider/AbstractMultiVersionEndpointProvider.php index ef6104e..bc1c5af 100644 --- a/src/Endpoint/Provider/AbstractMultiVersionEndpointProvider.php +++ b/src/Endpoint/Provider/AbstractMultiVersionEndpointProvider.php @@ -9,8 +9,9 @@ protected function addEndpointRegistry(string $name, array $properties): void if (isset($properties[self::ENDPOINT_NAME])) { $properties[self::ENDPOINT_NAME] = $name; } + $next = count($this->registry); - parent::addEndpointRegistry("$next", $properties); + parent::addEndpointRegistry((string)$next, $properties); } protected function getEndpointDefinition(string $name, string $version = null): array @@ -28,6 +29,7 @@ protected function getEndpointDefinition(string $name, string $version = null): return $valid; }); rsort($eps); - return $eps[0]; + + return $eps[0] ?? []; } }