From 93f430b94f9d74974435531b9d4113eab6427027 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 11 Dec 2019 01:47:24 +0100 Subject: [PATCH] Fix CS --- src/Symfony/Component/Lock/CHANGELOG.md | 12 ++++++--- .../Component/Lock/Store/MongoDbStore.php | 25 +++++++------------ .../Lock/Tests/Store/MongoDbStoreTest.php | 6 +++-- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Component/Lock/CHANGELOG.md b/src/Symfony/Component/Lock/CHANGELOG.md index c38b783fb9..66a3acbb76 100644 --- a/src/Symfony/Component/Lock/CHANGELOG.md +++ b/src/Symfony/Component/Lock/CHANGELOG.md @@ -1,18 +1,22 @@ CHANGELOG ========= +5.1.0 +----- + + * added the MongoDbStore supporting MongoDB servers >=2.2 + 5.0.0 ----- -* `Factory` has been removed, use `LockFactory` instead. -* `StoreInterface` has been removed, use `BlockingStoreInterface` and `PersistingStoreInterface` instead. -* removed the `waitAndSave()` method from `CombinedStore`, `MemcachedStore`, `RedisStore`, and `ZookeeperStore` + * `Factory` has been removed, use `LockFactory` instead. + * `StoreInterface` has been removed, use `BlockingStoreInterface` and `PersistingStoreInterface` instead. + * removed the `waitAndSave()` method from `CombinedStore`, `MemcachedStore`, `RedisStore`, and `ZookeeperStore` 4.4.0 ----- * added InvalidTtlException - * added the MongoDbStore supporting MongoDB servers >=2.2 * deprecated `StoreInterface` in favor of `BlockingStoreInterface` and `PersistingStoreInterface` * `Factory` is deprecated, use `LockFactory` instead * `StoreFactory::createStore` allows PDO and Zookeeper DSN. diff --git a/src/Symfony/Component/Lock/Store/MongoDbStore.php b/src/Symfony/Component/Lock/Store/MongoDbStore.php index 73158935c9..1475bf426b 100644 --- a/src/Symfony/Component/Lock/Store/MongoDbStore.php +++ b/src/Symfony/Component/Lock/Store/MongoDbStore.php @@ -44,8 +44,6 @@ use Symfony\Component\Lock\StoreInterface; * * @see https://docs.mongodb.com/manual/reference/limits/#Index-Key-Limit * - * @requires extension mongodb - * * @author Joe Bennett */ class MongoDbStore implements StoreInterface @@ -109,10 +107,10 @@ class MongoDbStore implements StoreInterface $this->collection = $mongo; } elseif ($mongo instanceof Client) { if (null === $this->options['database']) { - throw new InvalidArgumentException(sprintf('%s() requires the "database" option when constructing with a %s', __METHOD__, Client::class)); + throw new InvalidArgumentException(sprintf('"%s()" requires the "database" option when constructing with a "%s".', __METHOD__, Client::class)); } if (null === $this->options['collection']) { - throw new InvalidArgumentException(sprintf('%s() requires the "collection" option when constructing with a %s', __METHOD__, Client::class)); + throw new InvalidArgumentException(sprintf('"%s()" requires the "collection" option when constructing with a "%s".', __METHOD__, Client::class)); } $this->client = $mongo; @@ -127,28 +125,28 @@ class MongoDbStore implements StoreInterface $this->options['collection'] = $this->options['collection'] ?? $query['collection'] ?? null; $this->options['database'] = $this->options['database'] ?? ltrim($parsedUrl['path'] ?? '', '/') ?: null; if (null === $this->options['database']) { - throw new InvalidArgumentException(sprintf('%s() requires the "database" in the uri path or option when constructing with a uri', __METHOD__)); + throw new InvalidArgumentException(sprintf('"%s()" requires the "database" in the URI path or option when constructing with a URI.', __METHOD__)); } if (null === $this->options['collection']) { - throw new InvalidArgumentException(sprintf('%s() requires the "collection" in the uri querystring or option when constructing with a uri', __METHOD__)); + throw new InvalidArgumentException(sprintf('"%s()" requires the "collection" in the URI querystring or option when constructing with a URI.', __METHOD__)); } $this->uri = $mongo; } else { - throw new InvalidArgumentException(sprintf('%s() requires %s or %s or URI as first argument, %s given.', __METHOD__, Collection::class, Client::class, \is_object($mongo) ? \get_class($mongo) : \gettype($mongo))); + throw new InvalidArgumentException(sprintf('"%s()" requires "%s" or "%s" or URI as first argument, "%s" given.', __METHOD__, Collection::class, Client::class, \is_object($mongo) ? \get_class($mongo) : \gettype($mongo))); } if ($this->options['gcProbablity'] < 0.0 || $this->options['gcProbablity'] > 1.0) { - throw new InvalidArgumentException(sprintf('%s() gcProbablity must be a float from 0.0 to 1.0, %f given.', __METHOD__, $this->options['gcProbablity'])); + throw new InvalidArgumentException(sprintf('"%s()" gcProbablity must be a float from 0.0 to 1.0, "%f" given.', __METHOD__, $this->options['gcProbablity'])); } if ($this->initialTtl <= 0) { - throw new InvalidTtlException(sprintf('%s() expects a strictly positive TTL. Got %d.', __METHOD__, $this->initialTtl)); + throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL, got "%d".', __METHOD__, $this->initialTtl)); } } /** - * Create a TTL index to automatically remove expired locks. + * Creates a TTL index to automatically remove expired locks. * * If the gcProbablity option is set higher than 0.0 (defaults to 0.001); * there is a chance this will be called on self::save(). @@ -205,12 +203,7 @@ class MongoDbStore implements StoreInterface throw new LockAcquiringException('Failed to acquire lock', 0, $e); } - if ($this->options['gcProbablity'] > 0.0 - && ( - 1.0 === $this->options['gcProbablity'] - || (random_int(0, PHP_INT_MAX) / PHP_INT_MAX) <= $this->options['gcProbablity'] - ) - ) { + if ($this->options['gcProbablity'] > 0.0 && (1.0 === $this->options['gcProbablity'] || (random_int(0, PHP_INT_MAX) / PHP_INT_MAX) <= $this->options['gcProbablity'])) { $this->createTtlIndex(); } diff --git a/src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php b/src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php index 144c58737b..2e922919d7 100644 --- a/src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php +++ b/src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php @@ -12,6 +12,8 @@ namespace Symfony\Component\Lock\Tests\Store; use MongoDB\Client; +use Symfony\Component\Lock\Exception\InvalidArgumentException; +use Symfony\Component\Lock\Exception\NotSupportedException; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\PersistingStoreInterface; use Symfony\Component\Lock\Store\MongoDbStore; @@ -70,7 +72,7 @@ class MongoDbStoreTest extends AbstractStoreTest public function testNonBlocking() { - $this->expectException(\Symfony\Component\Lock\Exception\NotSupportedException::class); + $this->expectException(NotSupportedException::class); $store = $this->getStore(); @@ -113,7 +115,7 @@ class MongoDbStoreTest extends AbstractStoreTest */ public function testInvalidConstructionMethods($mongo, array $options) { - $this->expectException('Symfony\Component\Lock\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); new MongoDbStore($mongo, $options); }