diff --git a/core/modules/user/src/Exception/ConditionAlreadySetException.php b/core/modules/user/src/Exception/ExistingConditionException.php similarity index 73% rename from core/modules/user/src/Exception/ConditionAlreadySetException.php rename to core/modules/user/src/Exception/ExistingConditionException.php index 2a14ece..f89b4fa 100644 --- a/core/modules/user/src/Exception/ConditionAlreadySetException.php +++ b/core/modules/user/src/Exception/ExistingConditionException.php @@ -7,5 +7,5 @@ * * @see \Drupal\user\UserDataQuery */ -class ConditionAlreadySetException extends \Exception { +class ExistingConditionException extends \Exception { } diff --git a/core/modules/user/src/UserDataQuery.php b/core/modules/user/src/UserDataQuery.php index ff834e8..276a6b0 100644 --- a/core/modules/user/src/UserDataQuery.php +++ b/core/modules/user/src/UserDataQuery.php @@ -3,7 +3,7 @@ namespace Drupal\user; use Drupal\Core\Database\Query\SelectInterface; -use Drupal\user\Exception\ConditionAlreadySetException; +use Drupal\user\Exception\ExistingConditionException; /** * Returns data stored for a user account. @@ -15,7 +15,7 @@ class UserDataQuery implements UserDataQueryInterface { * * @var array */ - protected $sets; + protected $existingConditions; /** * The select query on the users_data table. @@ -38,7 +38,7 @@ public function __construct(SelectInterface $select) { * {@inheritdoc} */ public function setModule($module) { - $this->setter('module', $module); + $this->createCondition('module', $module); return $this; } @@ -46,7 +46,7 @@ public function setModule($module) { * {@inheritdoc} */ public function setUid($uid) { - $this->setter('uid', $uid); + $this->createCondition('uid', $uid); return $this; } @@ -54,7 +54,7 @@ public function setUid($uid) { * {@inheritdoc} */ public function setName($name) { - $this->setter('name', $name); + $this->createCondition('name', $name); return $this; } @@ -66,28 +66,28 @@ public function setValue($value) { if (!$is_scalar_value) { $value = serialize($value); } - $this->setter('value', $value); + $this->createCondition('value', $value); return $this; } /** - * Sets a condition on the query for the provided name using the value. + * Creates a condition on the query for the provided name using the value. * * @param string $name * The name of the field to check. * @param string|int $value * The value to test the field against. * - * @throws \Drupal\user\Exception\ConditionAlreadySetException + * @throws \Drupal\user\Exception\ExistingConditionException * Exception thrown when the select object already has a condition on the * field. */ - protected function setter($name, $value) { - if (isset($this->sets[$name]) && $this->sets[$name]) { - throw new ConditionAlreadySetException("Can not add another condition on '$name'"); + protected function createCondition($name, $value) { + if (isset($this->existingConditions[$name]) && $this->existingConditions[$name]) { + throw new ExistingConditionException("Can not add another condition on '$name'"); } $this->select->condition($name, $value); - $this->sets[$name] = TRUE; + $this->existingConditions[$name] = TRUE; } /** diff --git a/core/modules/user/src/UserDataQueryInterface.php b/core/modules/user/src/UserDataQueryInterface.php index 7271302..9fa8daa 100644 --- a/core/modules/user/src/UserDataQueryInterface.php +++ b/core/modules/user/src/UserDataQueryInterface.php @@ -17,7 +17,7 @@ * * @return $this * - * @throws \Drupal\user\Exception\ConditionAlreadySetException + * @throws \Drupal\user\Exception\ExistingConditionException * Exception thrown when the select object already has a module condition. */ public function setModule($module); @@ -30,7 +30,7 @@ public function setModule($module); * * @return $this * - * @throws \Drupal\user\Exception\ConditionAlreadySetException + * @throws \Drupal\user\Exception\ExistingConditionException * Exception thrown when the select object already has a user account ID * condition. */ @@ -44,7 +44,7 @@ public function setUid($uid); * * @return $this * - * @throws \Drupal\user\Exception\ConditionAlreadySetException + * @throws \Drupal\user\Exception\ExistingConditionException * Exception thrown when the select object already has a name condition. */ public function setName($name); @@ -57,7 +57,7 @@ public function setName($name); * * @return $this * - * @throws \Drupal\user\Exception\ConditionAlreadySetException + * @throws \Drupal\user\Exception\ExistingConditionException * Exception thrown when the select object already has a value condition. */ public function setValue($value); diff --git a/core/modules/user/tests/src/Kernel/UserDataQueryTest.php b/core/modules/user/tests/src/Kernel/UserDataQueryTest.php index 8a136ac..810d9a4 100644 --- a/core/modules/user/tests/src/Kernel/UserDataQueryTest.php +++ b/core/modules/user/tests/src/Kernel/UserDataQueryTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\user\Kernel; use Drupal\KernelTests\KernelTestBase; -use Drupal\user\Exception\ConditionAlreadySetException; +use Drupal\user\Exception\ExistingConditionException; /** * @coversDefaultClass \Drupal\user\UserDataQuery @@ -109,7 +109,7 @@ public function userDataQueryProvider() { * @dataProvider userDataQueryMultipleMethodCallsProvider */ public function testUserDataQueryMultipleMethodCalls($method, $name, $value) { - $this->setExpectedException(ConditionAlreadySetException::class, "Can not add another condition on '$name'"); + $this->setExpectedException(ExistingConditionException::class, "Can not add another condition on '$name'"); /** @var \Drupal\user\UserData $user_data */ $user_data = \Drupal::service('user.data'); $user_data_query = $user_data->getUserDataQuery(); @@ -171,12 +171,12 @@ public function testSetValue() { $user_data_query->setValue('bar'); $this->assertEquals([(object) $contents[1]], iterator_to_array($user_data_query->execute())); - // Test that catching \Drupal\user\Exception\ConditionAlreadySetException + // Test that catching \Drupal\user\Exception\ExistingConditionException // and re-running the query does not break is the value is not scalar. try { $user_data_query->setValue(['value']); } - catch (ConditionAlreadySetException $e) { + catch (ExistingConditionException $e) { } $this->assertEquals([(object) $contents[1]], iterator_to_array($user_data_query->execute()));