From 61195154aa2eaa9b6b8ce0cd43369e2248ed06af Mon Sep 17 00:00:00 2001 From: Wilmer Arambula <42547589+terabytesoftw@users.noreply.github.com> Date: Tue, 18 Jul 2023 10:54:55 -0400 Subject: [PATCH] Remove deprecated `InvalidParamException::class` in branch `2.2`. (#19896) --- framework/base/InvalidArgumentException.php | 2 +- framework/base/InvalidParamException.php | 26 ------------------- framework/classes.php | 1 - .../console/controllers/FixtureController.php | 4 +-- framework/db/BaseActiveRecord.php | 5 ++-- .../db/conditions/ConditionInterface.php | 4 +-- framework/rbac/CheckAccessInterface.php | 2 +- framework/rbac/ManagerInterface.php | 2 +- framework/web/ErrorHandler.php | 2 +- tests/framework/base/SecurityTest.php | 2 +- tests/framework/console/RequestTest.php | 2 +- .../controllers/DbMessageControllerTest.php | 6 ++--- tests/framework/db/CommandTest.php | 2 +- .../framework/db/GetTablesAliasTestTrait.php | 2 +- tests/framework/helpers/ArrayHelperTest.php | 12 ++++----- tests/framework/helpers/FileHelperTest.php | 4 +-- tests/framework/helpers/JsonTest.php | 2 +- tests/framework/helpers/MarkdownTest.php | 4 +-- tests/framework/helpers/UrlTest.php | 4 +-- tests/framework/i18n/DbMessageSourceTest.php | 2 +- tests/framework/i18n/FormatterDateTest.php | 4 +-- tests/framework/i18n/FormatterNumberTest.php | 4 +-- tests/framework/i18n/FormatterTest.php | 10 +++---- tests/framework/log/DbTargetTest.php | 2 +- tests/framework/rbac/DbManagerTestCase.php | 2 +- tests/framework/rbac/ManagerTestCase.php | 2 +- tests/framework/rbac/PhpManagerTest.php | 2 +- 27 files changed, 44 insertions(+), 72 deletions(-) delete mode 100644 framework/base/InvalidParamException.php diff --git a/framework/base/InvalidArgumentException.php b/framework/base/InvalidArgumentException.php index 20a7c6c759e..428d73b58bb 100644 --- a/framework/base/InvalidArgumentException.php +++ b/framework/base/InvalidArgumentException.php @@ -13,7 +13,7 @@ * @author Qiang Xue * @since 2.0.14 */ -class InvalidArgumentException extends InvalidParamException +class InvalidArgumentException extends \BadMethodCallException { /** * @return string the user-friendly name of this exception diff --git a/framework/base/InvalidParamException.php b/framework/base/InvalidParamException.php deleted file mode 100644 index 0024602eca5..00000000000 --- a/framework/base/InvalidParamException.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @since 2.0 - * @deprecated since 2.0.14. Use [[InvalidArgumentException]] instead. - */ -class InvalidParamException extends \BadMethodCallException -{ - /** - * @return string the user-friendly name of this exception - */ - public function getName() - { - return 'Invalid Parameter'; - } -} diff --git a/framework/classes.php b/framework/classes.php index 3d4759ed421..4f52f31baa0 100644 --- a/framework/classes.php +++ b/framework/classes.php @@ -37,7 +37,6 @@ 'yii\base\InvalidArgumentException' => YII2_PATH . '/base/InvalidArgumentException.php', 'yii\base\InvalidCallException' => YII2_PATH . '/base/InvalidCallException.php', 'yii\base\InvalidConfigException' => YII2_PATH . '/base/InvalidConfigException.php', - 'yii\base\InvalidParamException' => YII2_PATH . '/base/InvalidParamException.php', 'yii\base\InvalidRouteException' => YII2_PATH . '/base/InvalidRouteException.php', 'yii\base\InvalidValueException' => YII2_PATH . '/base/InvalidValueException.php', 'yii\base\Model' => YII2_PATH . '/base/Model.php', diff --git a/framework/console/controllers/FixtureController.php b/framework/console/controllers/FixtureController.php index a210034b7e9..9187ea5175a 100644 --- a/framework/console/controllers/FixtureController.php +++ b/framework/console/controllers/FixtureController.php @@ -8,8 +8,8 @@ namespace yii\console\controllers; use Yii; +use yii\base\InvalidArgumentException; use yii\base\InvalidConfigException; -use yii\base\InvalidParamException; use yii\console\Controller; use yii\console\Exception; use yii\console\ExitCode; @@ -536,7 +536,7 @@ private function getFixturePath() { try { return Yii::getAlias('@' . str_replace('\\', '/', $this->namespace)); - } catch (InvalidParamException $e) { + } catch (InvalidArgumentException $e) { throw new InvalidConfigException('Invalid fixture namespace: "' . $this->namespace . '". Please, check your FixtureController::namespace parameter'); } } diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index 88fb2f11d7c..42271a14464 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -11,7 +11,6 @@ use yii\base\InvalidArgumentException; use yii\base\InvalidCallException; use yii\base\InvalidConfigException; -use yii\base\InvalidParamException; use yii\base\Model; use yii\base\ModelEvent; use yii\base\NotSupportedException; @@ -1632,7 +1631,7 @@ public function getAttributeLabel($attribute) } else { try { $relation = $relatedModel->getRelation($relationName); - } catch (InvalidParamException $e) { + } catch (InvalidArgumentException $e) { return $this->generateAttributeLabel($attribute); } /* @var $modelClass ActiveRecordInterface */ @@ -1674,7 +1673,7 @@ public function getAttributeHint($attribute) } else { try { $relation = $relatedModel->getRelation($relationName); - } catch (InvalidParamException $e) { + } catch (InvalidArgumentException $e) { return ''; } /* @var $modelClass ActiveRecordInterface */ diff --git a/framework/db/conditions/ConditionInterface.php b/framework/db/conditions/ConditionInterface.php index fc8146940cf..96d63548c94 100644 --- a/framework/db/conditions/ConditionInterface.php +++ b/framework/db/conditions/ConditionInterface.php @@ -7,7 +7,7 @@ namespace yii\db\conditions; -use yii\base\InvalidParamException; +use InvalidArgumentException; use yii\db\ExpressionInterface; /** @@ -27,7 +27,7 @@ interface ConditionInterface extends ExpressionInterface * @param array $operands array of corresponding operands * * @return $this - * @throws InvalidParamException if input parameters are not suitable for this condition + * @throws InvalidArgumentException if input parameters are not suitable for this condition */ public static function fromArrayDefinition($operator, $operands); } diff --git a/framework/rbac/CheckAccessInterface.php b/framework/rbac/CheckAccessInterface.php index 38d86ee7a06..7f4dce00b0b 100644 --- a/framework/rbac/CheckAccessInterface.php +++ b/framework/rbac/CheckAccessInterface.php @@ -23,7 +23,7 @@ interface CheckAccessInterface * @param array $params name-value pairs that will be passed to the rules associated * with the roles and permissions assigned to the user. * @return bool whether the user has the specified permission. - * @throws \yii\base\InvalidParamException if $permissionName does not refer to an existing permission + * @throws \yii\base\InvalidArgumentException if $permissionName does not refer to an existing permission */ public function checkAccess($userId, $permissionName, $params = []); } diff --git a/framework/rbac/ManagerInterface.php b/framework/rbac/ManagerInterface.php index e4d2c7029e7..fec06fdc004 100644 --- a/framework/rbac/ManagerInterface.php +++ b/framework/rbac/ManagerInterface.php @@ -83,7 +83,7 @@ public function getRolesByUser($userId); * @param string $roleName name of the role to file child roles for * @return Role[] Child roles. The array is indexed by the role names. * First element is an instance of the parent Role itself. - * @throws \yii\base\InvalidParamException if Role was not found that are getting by $roleName + * @throws \yii\base\InvalidArgumentException if Role was not found that are getting by $roleName * @since 2.0.10 */ public function getChildRoles($roleName); diff --git a/framework/web/ErrorHandler.php b/framework/web/ErrorHandler.php index 3806c576ce9..cf97936e027 100644 --- a/framework/web/ErrorHandler.php +++ b/framework/web/ErrorHandler.php @@ -487,7 +487,7 @@ public function argumentsToString($args) */ public function getExceptionName($exception) { - if ($exception instanceof \yii\base\Exception || $exception instanceof \yii\base\InvalidCallException || $exception instanceof \yii\base\InvalidParamException || $exception instanceof \yii\base\UnknownMethodException) { + if ($exception instanceof \yii\base\Exception || $exception instanceof \yii\base\InvalidCallException || $exception instanceof \yii\base\InvalidArgumentException || $exception instanceof \yii\base\UnknownMethodException) { return $exception->getName(); } diff --git a/tests/framework/base/SecurityTest.php b/tests/framework/base/SecurityTest.php index a38fd386328..24a89454ae3 100644 --- a/tests/framework/base/SecurityTest.php +++ b/tests/framework/base/SecurityTest.php @@ -1121,7 +1121,7 @@ public function testUnMaskingInvalidStrings() public function testMaskingInvalidStrings() { - $this->expectException('\yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->expectExceptionMessage('First parameter ($length) must be greater than 0'); $this->security->maskToken(''); diff --git a/tests/framework/console/RequestTest.php b/tests/framework/console/RequestTest.php index 8e83f3bce75..331c494eb0f 100644 --- a/tests/framework/console/RequestTest.php +++ b/tests/framework/console/RequestTest.php @@ -163,7 +163,7 @@ public static function provider(): array ], [ // PHP does not allow variable name, starting with digit. - // InvalidParamException must be thrown during request resolving: + // InvalidArgumentException must be thrown during request resolving: 'params' => [ 'controller/route', '--0=test', diff --git a/tests/framework/console/controllers/DbMessageControllerTest.php b/tests/framework/console/controllers/DbMessageControllerTest.php index e8b1004df64..82a6b0c076a 100644 --- a/tests/framework/console/controllers/DbMessageControllerTest.php +++ b/tests/framework/console/controllers/DbMessageControllerTest.php @@ -82,10 +82,10 @@ public function tearDown(): void } /** - * @throws \yii\base\InvalidParamException - * @throws \yii\db\Exception - * @throws \yii\base\InvalidConfigException * @return \yii\db\Connection + * @throws \yii\base\InvalidArgumentException + * @throws \yii\base\InvalidConfigException + * @throws \yii\db\Exception */ public static function getConnection() { diff --git a/tests/framework/db/CommandTest.php b/tests/framework/db/CommandTest.php index 350d70da04b..587864d90fb 100644 --- a/tests/framework/db/CommandTest.php +++ b/tests/framework/db/CommandTest.php @@ -655,7 +655,7 @@ public function testInsertSelectFailed(array|string $invalidSelectColumns): void $db = $this->getConnection(); $command = $db->createCommand(); - $this->expectException('yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->expectExceptionMessage('Expected select query object with enumerated (named) parameters'); $command->insert('{{customer}}', $query)->execute(); diff --git a/tests/framework/db/GetTablesAliasTestTrait.php b/tests/framework/db/GetTablesAliasTestTrait.php index a3a00a10ea1..8090c110da7 100644 --- a/tests/framework/db/GetTablesAliasTestTrait.php +++ b/tests/framework/db/GetTablesAliasTestTrait.php @@ -132,7 +132,7 @@ public function testGetTableNames_isFromAliasedExpression() $expression = new \yii\db\Expression('(SELECT id FROM user)'); $query->from = $expression; - $this->expectException('yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->expectExceptionMessage('To use Expression in from() method, pass it in array format with alias.'); $tables = $query->getTablesUsedInFrom(); diff --git a/tests/framework/helpers/ArrayHelperTest.php b/tests/framework/helpers/ArrayHelperTest.php index 33b105173f4..d5d468a072f 100644 --- a/tests/framework/helpers/ArrayHelperTest.php +++ b/tests/framework/helpers/ArrayHelperTest.php @@ -325,16 +325,16 @@ public function testMultisortClosure() ], $changelog); } - public function testMultisortInvalidParamExceptionDirection() + public function testMultisortInvalidArgumentExceptionDirection() { - $this->expectException('yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $data = ['foo' => 'bar']; ArrayHelper::multisort($data, ['foo'], []); } - public function testMultisortInvalidParamExceptionSortFlag() + public function testMultisortInvalidArgumentExceptionSortFlag() { - $this->expectException('yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $data = ['foo' => 'bar']; ArrayHelper::multisort($data, ['foo'], ['foo'], []); } @@ -1243,7 +1243,7 @@ public function testIsInStrict() public function testInException() { - $this->expectException('yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->expectExceptionMessage('Argument $haystack must be an array or implement Traversable'); ArrayHelper::isIn('value', null); } @@ -1262,7 +1262,7 @@ public function testIsSubset() public function testIsSubsetException() { - $this->expectException('yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->expectExceptionMessage('Argument $needles must be an array or implement Traversable'); ArrayHelper::isSubset('a', new \ArrayObject(['a', 'b'])); } diff --git a/tests/framework/helpers/FileHelperTest.php b/tests/framework/helpers/FileHelperTest.php index 1417a2e3293..236055d299b 100644 --- a/tests/framework/helpers/FileHelperTest.php +++ b/tests/framework/helpers/FileHelperTest.php @@ -313,7 +313,7 @@ public function testCopyDirectoryToItself() $dirName => [], ]); - $this->expectException('yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $dirName = $this->testFilePath . DIRECTORY_SEPARATOR . 'test_dir'; FileHelper::copyDirectory($dirName, $dirName); @@ -329,7 +329,7 @@ public function testCopyDirToSubdirOfItself() 'backup' => ['data' => []], ]); - $this->expectException('yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); FileHelper::copyDirectory( $this->testFilePath . DIRECTORY_SEPARATOR . 'backup', diff --git a/tests/framework/helpers/JsonTest.php b/tests/framework/helpers/JsonTest.php index 03041ab1a20..00e6b6846a2 100644 --- a/tests/framework/helpers/JsonTest.php +++ b/tests/framework/helpers/JsonTest.php @@ -205,7 +205,7 @@ public function testDecode() /** * @covers ::decode */ - public function testDecodeInvalidParamException() + public function testDecodeInvalidArgumentException() { $this->expectException(\yii\base\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid JSON data.'); diff --git a/tests/framework/helpers/MarkdownTest.php b/tests/framework/helpers/MarkdownTest.php index eb01e38cbc2..6cf18bda3ed 100644 --- a/tests/framework/helpers/MarkdownTest.php +++ b/tests/framework/helpers/MarkdownTest.php @@ -43,9 +43,9 @@ public function testOriginalFlavor() $this->assertEquals(Markdown::process($text), Markdown::process($text, 'gfm-comment')); } - public function testProcessInvalidParamException() + public function testProcessInvalidArgumentException() { - $this->expectException(\yii\base\InvalidParamException::class); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->expectExceptionMessage("Markdown flavor 'undefined' is not defined."); Markdown::process('foo', 'undefined'); diff --git a/tests/framework/helpers/UrlTest.php b/tests/framework/helpers/UrlTest.php index f33a26c970e..68e0f3dfc5a 100644 --- a/tests/framework/helpers/UrlTest.php +++ b/tests/framework/helpers/UrlTest.php @@ -114,7 +114,7 @@ public function testToRoute() // In case there is no controller, an exception should be thrown for relative route $this->removeMockedAction(); - $this->expectException('yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); Url::toRoute('site/view'); } @@ -234,7 +234,7 @@ public function testTo() //In case there is no controller, throw an exception $this->removeMockedAction(); - $this->expectException('yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); Url::to(['site/view']); } diff --git a/tests/framework/i18n/DbMessageSourceTest.php b/tests/framework/i18n/DbMessageSourceTest.php index 94ddd9cdca2..698561f55c5 100644 --- a/tests/framework/i18n/DbMessageSourceTest.php +++ b/tests/framework/i18n/DbMessageSourceTest.php @@ -117,8 +117,8 @@ public static function tearDownAfterClass(): void /** * @return \yii\db\Connection * @throws \yii\db\Exception + * @throws \yii\base\InvalidArgumentException * @throws \yii\base\InvalidConfigException - * @throws \yii\base\InvalidParamException */ public static function getConnection() { diff --git a/tests/framework/i18n/FormatterDateTest.php b/tests/framework/i18n/FormatterDateTest.php index d6fa0fa2ff2..75bf3abef9f 100644 --- a/tests/framework/i18n/FormatterDateTest.php +++ b/tests/framework/i18n/FormatterDateTest.php @@ -49,7 +49,7 @@ public function testFormat() $this->assertSame(date('M j, Y', $value), $this->formatter->format($value, 'date')); $this->assertSame(date('M j, Y', $value), $this->formatter->format($value, 'DATE')); $this->assertSame(date('Y/m/d', $value), $this->formatter->format($value, ['date', 'php:Y/m/d'])); - $this->expectException('\yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, 'data')); } @@ -542,7 +542,7 @@ public static function dateInputs() { return [ ['2015-01-01 00:00:00', '2014-13-01 00:00:00'], - [false, 'asdfg', 'yii\base\InvalidParamException'], + [false, 'asdfg', \yii\base\InvalidArgumentException::class], // [(string)strtotime('now'), 'now'], // fails randomly ]; } diff --git a/tests/framework/i18n/FormatterNumberTest.php b/tests/framework/i18n/FormatterNumberTest.php index 5da02ffe099..62f2aa706a1 100755 --- a/tests/framework/i18n/FormatterNumberTest.php +++ b/tests/framework/i18n/FormatterNumberTest.php @@ -142,13 +142,13 @@ public function testIntlAsIntegerOptions() public function testAsIntegerException() { - $this->expectException('\yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->formatter->asInteger('a'); } public function testAsIntegerException2() { - $this->expectException('\yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->formatter->asInteger('-123abc'); } diff --git a/tests/framework/i18n/FormatterTest.php b/tests/framework/i18n/FormatterTest.php index 3fd7b516fa6..6cdd89370d8 100644 --- a/tests/framework/i18n/FormatterTest.php +++ b/tests/framework/i18n/FormatterTest.php @@ -56,7 +56,7 @@ public function testFormat() public function testInvalidFormat() { $value = time(); - $this->expectException('\yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->expectExceptionMessage('Unknown format type: data'); $this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, 'data')); } @@ -64,7 +64,7 @@ public function testInvalidFormat() public function testInvalidFormatArray() { $value = time(); - $this->expectException('\yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->expectExceptionMessage('Unknown format type: data'); $this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, ['data'])); } @@ -72,7 +72,7 @@ public function testInvalidFormatArray() public function testFormatArrayInvalidStructure() { $value = time(); - $this->expectException('\yii\base\InvalidParamException'); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->expectExceptionMessage('The $format array must contain at least one element.'); $this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, [])); } @@ -358,7 +358,7 @@ public static function lengthDataProvider() [ 'Wrong value is casted properly', ['NaN'], '0 millimeters', '0 mm', - ['yii\base\InvalidParamException', "'NaN' is not a numeric value"], + [\yii\base\InvalidArgumentException::class, "'NaN' is not a numeric value"], ], [ 'Negative value works', @@ -457,7 +457,7 @@ public static function weightDataProvider() [ 'Wrong value is casted properly', ['NaN'], '0 grams', '0 g', - ['yii\base\InvalidParamException', "'NaN' is not a numeric value"], + [\yii\base\InvalidArgumentException::class, "'NaN' is not a numeric value"], ], [ 'Negative value works', diff --git a/tests/framework/log/DbTargetTest.php b/tests/framework/log/DbTargetTest.php index 878045895e2..9825c0c99c4 100644 --- a/tests/framework/log/DbTargetTest.php +++ b/tests/framework/log/DbTargetTest.php @@ -89,8 +89,8 @@ public function tearDown(): void } /** - * @throws \yii\base\InvalidParamException * @throws \yii\db\Exception + * @throws \yii\base\InvalidArgumentException * @throws \yii\base\InvalidConfigException * @return \yii\db\Connection */ diff --git a/tests/framework/rbac/DbManagerTestCase.php b/tests/framework/rbac/DbManagerTestCase.php index 79500c8026a..b315030c53d 100644 --- a/tests/framework/rbac/DbManagerTestCase.php +++ b/tests/framework/rbac/DbManagerTestCase.php @@ -121,8 +121,8 @@ protected function tearDown(): void } /** - * @throws \yii\base\InvalidParamException * @throws \yii\db\Exception + * @throws \yii\base\InvalidArgumentException * @throws \yii\base\InvalidConfigException * @return \yii\db\Connection */ diff --git a/tests/framework/rbac/ManagerTestCase.php b/tests/framework/rbac/ManagerTestCase.php index 54a4e5dc3a0..4d972fa2e80 100644 --- a/tests/framework/rbac/ManagerTestCase.php +++ b/tests/framework/rbac/ManagerTestCase.php @@ -7,7 +7,7 @@ namespace yiiunit\framework\rbac; -use yii\base\InvalidParamException; +use yii\base\InvalidArgumentException; use yii\rbac\BaseManager; use yii\rbac\Item; use yii\rbac\Permission; diff --git a/tests/framework/rbac/PhpManagerTest.php b/tests/framework/rbac/PhpManagerTest.php index 95306f2fa2e..51c77bff027 100644 --- a/tests/framework/rbac/PhpManagerTest.php +++ b/tests/framework/rbac/PhpManagerTest.php @@ -143,7 +143,7 @@ public function testOverwriteName() $permission = $this->auth->getPermission($name); $permission->name = 'createPost'; - $this->expectException(\yii\base\InvalidParamException::class); + $this->expectException(\yii\base\InvalidArgumentException::class); $this->auth->update($name, $permission); }