From e81d91cd455bb70b91d61b924e433b011fc2fed7 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 2 Nov 2020 13:14:21 +0100 Subject: [PATCH] Add and use InvalidObjectArgument (#3672) Close #3664 --- ...tractObjectTextPropertyCondition.class.php | 5 +++-- .../AbstractTimestampCondition.class.php | 5 +++-- .../condition/UserAvatarCondition.class.php | 3 ++- .../UserCoverPhotoCondition.class.php | 3 ++- .../condition/UserEmailCondition.class.php | 3 ++- .../UserIntegerPropertyCondition.class.php | 3 ++- .../condition/UserLanguageCondition.class.php | 3 ++- .../condition/UserOptionsCondition.class.php | 3 ++- .../UserRegistrationDateCondition.class.php | 3 ++- ...egistrationDateIntervalCondition.class.php | 3 ++- .../UserSignatureCondition.class.php | 3 ++- .../condition/UserStateCondition.class.php | 3 ++- .../condition/UserTrophyCondition.class.php | 3 ++- .../condition/UserUserIDCondition.class.php | 3 ++- .../condition/UserUsernameCondition.class.php | 3 ++- .../ArticleCategoryCondition.class.php | 3 ++- ...ctivityTimeIntervalDaysCondition.class.php | 5 +++-- ...EventExcludedObjectTypeCondition.class.php | 3 ++- ...rTrophyExcludedTrophiesCondition.class.php | 3 ++- ...xcludedTrophyCategoriesCondition.class.php | 3 ++- .../exception/InvalidObjectArgument.class.php | 21 +++++++++++++++++++ 21 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/exception/InvalidObjectArgument.class.php diff --git a/wcfsetup/install/files/lib/system/condition/AbstractObjectTextPropertyCondition.class.php b/wcfsetup/install/files/lib/system/condition/AbstractObjectTextPropertyCondition.class.php index 5991536f46..9df56bd01d 100644 --- a/wcfsetup/install/files/lib/system/condition/AbstractObjectTextPropertyCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/AbstractObjectTextPropertyCondition.class.php @@ -3,6 +3,7 @@ namespace wcf\system\condition; use wcf\data\condition\Condition; use wcf\data\DatabaseObject; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; /** * Abstract condition implementation for check a text-typed property of a database @@ -40,7 +41,7 @@ abstract class AbstractObjectTextPropertyCondition extends AbstractTextCondition public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { $className = $this->getListClassName(); if (!($objectList instanceof $className)) { - throw new \InvalidArgumentException("Object list is no instance of '{$className}', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, $className, 'Object list'); } if ($this->supportsMultipleValues) { @@ -57,7 +58,7 @@ abstract class AbstractObjectTextPropertyCondition extends AbstractTextCondition public function checkObject(DatabaseObject $object, array $conditionData) { $className = $this->getClassName(); if (!($object instanceof $className)) { - throw new \InvalidArgumentException("Object is no instance of '{$className}', instance of '".get_class($object)."' given."); + throw new InvalidObjectArgument($object, $className); } return in_array($object->{$this->getPropertyName()}, $conditionData[$this->fieldName]); diff --git a/wcfsetup/install/files/lib/system/condition/AbstractTimestampCondition.class.php b/wcfsetup/install/files/lib/system/condition/AbstractTimestampCondition.class.php index dc80ba5b58..500554a1cf 100644 --- a/wcfsetup/install/files/lib/system/condition/AbstractTimestampCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/AbstractTimestampCondition.class.php @@ -3,6 +3,7 @@ namespace wcf\system\condition; use wcf\data\condition\Condition; use wcf\data\DatabaseObject; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\exception\UserInputException; use wcf\system\WCF; @@ -47,7 +48,7 @@ abstract class AbstractTimestampCondition extends AbstractSingleFieldCondition i public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { $className = $this->getListClassName(); if (!($objectList instanceof $className)) { - throw new \InvalidArgumentException("Object list is no instance of '{$className}', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, $className, 'Object list'); } /** @noinspection PhpUndefinedFieldInspection */ @@ -68,7 +69,7 @@ abstract class AbstractTimestampCondition extends AbstractSingleFieldCondition i public function checkObject(DatabaseObject $object, array $conditionData) { $className = $this->getClassName(); if (!($object instanceof $className)) { - throw new \InvalidArgumentException("Object is no instance of '{$className}', instance of '".get_class($object)."' given."); + throw new InvalidObjectArgument($object, $className); } if (isset($conditionData['startTime']) && $object->{$this->getPropertyName()} < strtotime($conditionData['startTime'])) { diff --git a/wcfsetup/install/files/lib/system/condition/UserAvatarCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserAvatarCondition.class.php index 0abeaa4685..6fe7af969d 100644 --- a/wcfsetup/install/files/lib/system/condition/UserAvatarCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserAvatarCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\WCF; /** @@ -50,7 +51,7 @@ class UserAvatarCondition extends AbstractSelectCondition implements IContentCon */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } switch ($conditionData['userAvatar']) { diff --git a/wcfsetup/install/files/lib/system/condition/UserCoverPhotoCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserCoverPhotoCondition.class.php index 02eb0b0efe..d72861b792 100644 --- a/wcfsetup/install/files/lib/system/condition/UserCoverPhotoCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserCoverPhotoCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\WCF; /** @@ -45,7 +46,7 @@ class UserCoverPhotoCondition extends AbstractSelectCondition implements IConten */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } switch ($conditionData['userCoverPhoto']) { diff --git a/wcfsetup/install/files/lib/system/condition/UserEmailCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserEmailCondition.class.php index 69bebfd185..528219b81b 100644 --- a/wcfsetup/install/files/lib/system/condition/UserEmailCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserEmailCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\WCF; /** @@ -32,7 +33,7 @@ class UserEmailCondition extends AbstractTextCondition implements IContentCondit */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } $objectList->getConditionBuilder()->add('user_table.email LIKE ?', ['%'.addcslashes($conditionData['email'], '_%').'%']); diff --git a/wcfsetup/install/files/lib/system/condition/UserIntegerPropertyCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserIntegerPropertyCondition.class.php index 5a42dea876..680d30d741 100644 --- a/wcfsetup/install/files/lib/system/condition/UserIntegerPropertyCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserIntegerPropertyCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\WCF; /** @@ -22,7 +23,7 @@ class UserIntegerPropertyCondition extends AbstractIntegerCondition implements I */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } if (isset($conditionData['greaterThan'])) { diff --git a/wcfsetup/install/files/lib/system/condition/UserLanguageCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserLanguageCondition.class.php index b5b2f66925..e9abf20892 100644 --- a/wcfsetup/install/files/lib/system/condition/UserLanguageCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserLanguageCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\exception\UserInputException; use wcf\system\language\LanguageFactory; use wcf\system\WCF; @@ -36,7 +37,7 @@ class UserLanguageCondition extends AbstractSingleFieldCondition implements ICon */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } $objectList->getConditionBuilder()->add('user_table.languageID IN (?)', [$conditionData['languageIDs']]); diff --git a/wcfsetup/install/files/lib/system/condition/UserOptionsCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserOptionsCondition.class.php index cb40e75fb0..0aadd74a00 100644 --- a/wcfsetup/install/files/lib/system/condition/UserOptionsCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserOptionsCondition.class.php @@ -5,6 +5,7 @@ use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObject; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\option\user\UserOptionHandler; use wcf\system\WCF; @@ -41,7 +42,7 @@ class UserOptionsCondition extends AbstractMultipleFieldsCondition implements IC */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } $optionValues = $conditionData['optionValues']; diff --git a/wcfsetup/install/files/lib/system/condition/UserRegistrationDateCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserRegistrationDateCondition.class.php index 163a6c8119..1ed1420258 100644 --- a/wcfsetup/install/files/lib/system/condition/UserRegistrationDateCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserRegistrationDateCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\exception\UserInputException; use wcf\system\WCF; @@ -40,7 +41,7 @@ class UserRegistrationDateCondition extends AbstractSingleFieldCondition impleme */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } if (isset($conditionData['registrationDateEnd'])) { diff --git a/wcfsetup/install/files/lib/system/condition/UserRegistrationDateIntervalCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserRegistrationDateIntervalCondition.class.php index 97dcc00a6c..66254ec1e3 100644 --- a/wcfsetup/install/files/lib/system/condition/UserRegistrationDateIntervalCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserRegistrationDateIntervalCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\exception\UserInputException; use wcf\system\WCF; @@ -34,7 +35,7 @@ class UserRegistrationDateIntervalCondition extends AbstractIntegerCondition imp */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } if (isset($conditionData['greaterThan'])) { diff --git a/wcfsetup/install/files/lib/system/condition/UserSignatureCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserSignatureCondition.class.php index e2baa4820c..857a66c65a 100644 --- a/wcfsetup/install/files/lib/system/condition/UserSignatureCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserSignatureCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\WCF; /** @@ -45,7 +46,7 @@ class UserSignatureCondition extends AbstractSelectCondition implements IContent */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } switch ($conditionData['userSignature']) { diff --git a/wcfsetup/install/files/lib/system/condition/UserStateCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserStateCondition.class.php index 327044dba1..d8fe860d4b 100644 --- a/wcfsetup/install/files/lib/system/condition/UserStateCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserStateCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\exception\UserInputException; use wcf\system\WCF; @@ -65,7 +66,7 @@ class UserStateCondition extends AbstractSingleFieldCondition implements IConten */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } if (isset($conditionData['userIsBanned'])) { diff --git a/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php index 9dbd4ea58b..f7dfe6f7a1 100644 --- a/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php @@ -7,6 +7,7 @@ use wcf\data\user\trophy\UserTrophyList; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\exception\UserInputException; use wcf\system\WCF; use wcf\util\ArrayUtil; @@ -62,7 +63,7 @@ class UserTrophyCondition extends AbstractMultipleFieldsCondition implements ICo */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } if (isset($conditionData['userTrophyIDs'])) { diff --git a/wcfsetup/install/files/lib/system/condition/UserUserIDCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserUserIDCondition.class.php index ba0e355ff6..4b5236a2d7 100644 --- a/wcfsetup/install/files/lib/system/condition/UserUserIDCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserUserIDCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\WCF; /** @@ -32,7 +33,7 @@ class UserUserIDCondition extends AbstractSingleFieldCondition implements IConte */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is not an instance of '".UserList::class."', an instance of '".get_class($objectList)."' was given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } $objectList->getConditionBuilder()->add('user_table.userID = ?', [$conditionData['userID']]); diff --git a/wcfsetup/install/files/lib/system/condition/UserUsernameCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserUsernameCondition.class.php index 3bc51dc381..baff6a6144 100644 --- a/wcfsetup/install/files/lib/system/condition/UserUsernameCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserUsernameCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\condition\Condition; use wcf\data\user\User; use wcf\data\user\UserList; use wcf\data\DatabaseObjectList; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\WCF; /** @@ -32,7 +33,7 @@ class UserUsernameCondition extends AbstractTextCondition implements IContentCon */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } $objectList->getConditionBuilder()->add('user_table.username LIKE ?', ['%'.addcslashes($conditionData['username'], '_%').'%']); diff --git a/wcfsetup/install/files/lib/system/condition/article/ArticleCategoryCondition.class.php b/wcfsetup/install/files/lib/system/condition/article/ArticleCategoryCondition.class.php index 75152476e6..abbc0edb88 100644 --- a/wcfsetup/install/files/lib/system/condition/article/ArticleCategoryCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/article/ArticleCategoryCondition.class.php @@ -4,6 +4,7 @@ use wcf\data\article\ArticleList; use wcf\data\DatabaseObjectList; use wcf\system\condition\AbstractMultiCategoryCondition; use wcf\system\condition\IObjectListCondition; +use wcf\system\exception\InvalidObjectArgument; /** * Condition implementation for the category an article belongs to. @@ -35,7 +36,7 @@ class ArticleCategoryCondition extends AbstractMultiCategoryCondition implements */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof ArticleList)) { - throw new \InvalidArgumentException("Object list is no instance of '".ArticleList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, ArticleList::class, 'Object list'); } $objectList->getConditionBuilder()->add('article.categoryID IN (?)', [$conditionData[$this->fieldName]]); diff --git a/wcfsetup/install/files/lib/system/condition/user/UserLastActivityTimeIntervalDaysCondition.class.php b/wcfsetup/install/files/lib/system/condition/user/UserLastActivityTimeIntervalDaysCondition.class.php index 18665dd4ad..ff962f6c97 100644 --- a/wcfsetup/install/files/lib/system/condition/user/UserLastActivityTimeIntervalDaysCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/user/UserLastActivityTimeIntervalDaysCondition.class.php @@ -8,6 +8,7 @@ use wcf\data\user\UserList; use wcf\system\condition\AbstractSingleFieldCondition; use wcf\system\condition\IObjectCondition; use wcf\system\condition\IObjectListCondition; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\exception\UserInputException; use wcf\system\WCF; use wcf\util\ClassUtil; @@ -44,7 +45,7 @@ class UserLastActivityTimeIntervalDaysCondition extends AbstractSingleFieldCondi */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserList)) { - throw new \InvalidArgumentException("Object list is no instance of '" . UserList::class . "', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserList::class, 'Object list'); } /** @noinspection PhpUndefinedFieldInspection */ @@ -64,7 +65,7 @@ class UserLastActivityTimeIntervalDaysCondition extends AbstractSingleFieldCondi */ public function checkObject(DatabaseObject $object, array $conditionData) { if (!($object instanceof User) && !ClassUtil::isDecoratedInstanceOf($object, User::class)) { - throw new \InvalidArgumentException("Object is no instance of '" . User::class . "', instance of '".get_class($object)."' given."); + throw new InvalidObjectArgument($objectList, User::class); } if (isset($conditionData['startDays'])) { diff --git a/wcfsetup/install/files/lib/system/condition/user/activity/event/UserActivityEventExcludedObjectTypeCondition.class.php b/wcfsetup/install/files/lib/system/condition/user/activity/event/UserActivityEventExcludedObjectTypeCondition.class.php index 995be9b1d9..497ee1f892 100644 --- a/wcfsetup/install/files/lib/system/condition/user/activity/event/UserActivityEventExcludedObjectTypeCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/user/activity/event/UserActivityEventExcludedObjectTypeCondition.class.php @@ -5,6 +5,7 @@ use wcf\data\user\activity\event\UserActivityEventList; use wcf\data\DatabaseObjectList; use wcf\system\condition\AbstractMultiSelectCondition; use wcf\system\condition\IObjectListCondition; +use wcf\system\exception\InvalidObjectArgument; use wcf\system\WCF; /** @@ -37,7 +38,7 @@ class UserActivityEventExcludedObjectTypeCondition extends AbstractMultiSelectCo */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserActivityEventList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserActivityEventList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserActivityEventList::class, 'Object list'); } $objectList->getConditionBuilder()->add('user_activity_event.objectTypeID NOT IN (?)', [$conditionData[$this->fieldName]]); diff --git a/wcfsetup/install/files/lib/system/condition/user/trophy/UserTrophyExcludedTrophiesCondition.class.php b/wcfsetup/install/files/lib/system/condition/user/trophy/UserTrophyExcludedTrophiesCondition.class.php index 3127d2899c..f95fa83b19 100644 --- a/wcfsetup/install/files/lib/system/condition/user/trophy/UserTrophyExcludedTrophiesCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/user/trophy/UserTrophyExcludedTrophiesCondition.class.php @@ -5,6 +5,7 @@ use wcf\data\user\trophy\UserTrophyList; use wcf\data\DatabaseObjectList; use wcf\system\condition\AbstractMultiSelectCondition; use wcf\system\condition\IObjectListCondition; +use wcf\system\exception\InvalidObjectArgument; /** * Condition implementation for the excluded trophies. @@ -36,7 +37,7 @@ class UserTrophyExcludedTrophiesCondition extends AbstractMultiSelectCondition i */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserTrophyList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserTrophyList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserTrophyList::class, 'Object list'); } $objectList->getConditionBuilder()->add('user_trophy.trophyID NOT IN (?)', [$conditionData[$this->fieldName]]); diff --git a/wcfsetup/install/files/lib/system/condition/user/trophy/UserTrophyExcludedTrophyCategoriesCondition.class.php b/wcfsetup/install/files/lib/system/condition/user/trophy/UserTrophyExcludedTrophyCategoriesCondition.class.php index 0d181b166d..b37682e848 100644 --- a/wcfsetup/install/files/lib/system/condition/user/trophy/UserTrophyExcludedTrophyCategoriesCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/user/trophy/UserTrophyExcludedTrophyCategoriesCondition.class.php @@ -5,6 +5,7 @@ use wcf\data\user\trophy\UserTrophyList; use wcf\data\DatabaseObjectList; use wcf\system\condition\AbstractMultiSelectCondition; use wcf\system\condition\IObjectListCondition; +use wcf\system\exception\InvalidObjectArgument; /** * Condition implementation for the excluded trophies. @@ -36,7 +37,7 @@ class UserTrophyExcludedTrophyCategoriesCondition extends AbstractMultiSelectCon */ public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { if (!($objectList instanceof UserTrophyList)) { - throw new \InvalidArgumentException("Object list is no instance of '".UserTrophyList::class."', instance of '".get_class($objectList)."' given."); + throw new InvalidObjectArgument($objectList, UserTrophyList::class, 'Object list'); } $objectList->getConditionBuilder()->add('trophy.categoryID NOT IN (?)', [$conditionData[$this->fieldName]]); diff --git a/wcfsetup/install/files/lib/system/exception/InvalidObjectArgument.class.php b/wcfsetup/install/files/lib/system/exception/InvalidObjectArgument.class.php new file mode 100644 index 0000000000..600746cd38 --- /dev/null +++ b/wcfsetup/install/files/lib/system/exception/InvalidObjectArgument.class.php @@ -0,0 +1,21 @@ + + * @package WoltLabSuite\Core\System\Exception + * @since 5.4 + */ +class InvalidObjectArgument extends \InvalidArgumentException { + /** + * InvalidObjectArgument constructor. + */ + public function __construct(object $object, string $expectedClass, string $objectName = 'Object') { + parent::__construct("{$objectName} is no instance of '{$expectedClass}', instance of '" . get_class($object) . "' given."); + } +} -- 2.20.1