8000 minor #49240 [Lock] Fix some typos in MongoDbStore (javiereguiluz) · symfony/symfony@8c48f32 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c48f32

Browse files
minor #49240 [Lock] Fix some typos in MongoDbStore (javiereguiluz)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Lock] Fix some typos in MongoDbStore | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | - | License | MIT | Doc PR | - I didn't include this in #49239 because I don't know if this is a typo that can be fixed (maybe the code uses the same word with the typo). Commits ------- 7b7e859 [Lock] Fix some typos in MongoDbStore
2 parents c05bd6c + 7b7e859 commit 8c48f32

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

UPGRADE-6.3.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ HttpKernel
4848

4949
* Deprecate parameters `container.dumper.inline_factories` and `container.dumper.inline_class_loader`, use `.container.dumper.inline_factories` and `.container.dumper.inline_class_loader` instead
5050

51+
Lock
52+
----
53+
54+
* Deprecate the `gcProbablity` option to fix a typo in its name, use the `gcProbability` option instead
55+
5156
Messenger
5257
---------
5358

src/Symfony/Component/Lock/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Create migration for lock table when DoctrineDbalStore is used
88
* Add support for Relay PHP extension for Redis
9+
* Renamed the `gcProbablity` option to `gcProbability` to fix a typo in its name
910

1011
6.0
1112
---

src/Symfony/Component/Lock/Store/MongoDbStore.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class MongoDbStore implements PersistingStoreInterface
6464
* @throws InvalidTtlException When the initial ttl is not valid
6565
*
6666
* Options:
67-
* gcProbablity: Should a TTL Index be created expressed as a probability from 0.0 to 1.0 [default: 0.001]
67+
* gcProbability: Should a TTL Index be created expressed as a probability from 0.0 to 1.0 [default: 0.001]
6868
* database: The name of the database [required when $mongo is a Client]
6969
* collection: The name of the collection [required when $mongo is a Client]
7070
* uriOptions: Array of uri options. [used when $mongo is a URI]
@@ -78,9 +78,9 @@ class MongoDbStore implements PersistingStoreInterface
7878
*
7979
* @see https://docs.mongodb.com/php-library/current/reference/method/MongoDBClient__construct/
8080
*
81-
* If gcProbablity is set to a value greater than 0.0 there is a chance
81+
* If gcProbability is set to a value greater than 0.0 there is a chance
8282
* this store will attempt to create a TTL index on self::save().
83-
* If you prefer to create your TTL Index manually you can set gcProbablity
83+
* If you prefer to create your TTL Index manually you can set gcProbability
8484
* to 0.0 and optionally leverage
8585
* self::createTtlIndex(int $expireAfterSeconds = 0).
8686
*
@@ -90,8 +90,15 @@ class MongoDbStore implements PersistingStoreInterface
9090
*/
9191
public function __construct(Collection|Client|string $mongo, array $options = [], float $initialTtl = 300.0)
9292
{
93+
if (isset($options['gcProbablity'])) {
94+
trigger_deprecation('symfony/lock', '6.3', 'The "gcProbablity" option (notice the typo in its name) is deprecated in "%s"; use the "gcProbability" option instead.', __CLASS__);
95+
96+
$options['gcProbability'] = $options['gcProbablity'];
97+
unset($options['gcProbablity']);
98+
}
99+
93100
$this->options = array_merge([
94-
'gcProbablity' => 0.001,
101+
'gcProbability' => 0.001,
95102
'database' => null,
96103
'collection' => null,
97104
'uriOptions' => [],
@@ -117,8 +124,8 @@ public function __construct(Collection|Client|string $mongo, array $options = []
117124
}
118125
}
119126

120-
if ($this->options['gcProbablity'] < 0.0 || $this->options['gcProbablity'] > 1.0) {
121-
throw new InvalidArgumentException(sprintf('"%s()" gcProbablity must be a float from 0.0 to 1.0, "%f" given.', __METHOD__, $this->options['gcProbablity']));
127+
if ($this->options['gcProbability'] < 0.0 || $this->options['gcProbability'] > 1.0) {
128+
throw new InvalidArgumentException(sprintf('"%s()" gcProbability must be a float from 0.0 to 1.0, "%f" given.', __METHOD__, $this->options['gcProbability']));
122129
}
123130

124131
if ($this->initialTtl <= 0) {
@@ -159,7 +166,7 @@ private function skimUri(string $uri): string
159166
/**
160167
* Creates a TTL index to automatically remove expired locks.
161168
*
162-
* If the gcProbablity option is set higher than 0.0 (defaults to 0.001);
169+
* If the gcProbability option is set higher than 0.0 (defaults to 0.001);
163170
* there is a chance this will be called on self::save().
164171
*
165172
* Otherwise; this should be called once manually during database setup.
@@ -212,7 +219,7 @@ public function save(Key $key)
212219
throw new LockAcquiringException('Failed to acquire lock.', 0, $e);
213220
}
214221

215-
if ($this->options['gcProbablity'] > 0.0 && (1.0 === $this->options['gcProbablity'] || (random_int(0, \PHP_INT_MAX) / \PHP_INT_MAX) <= $this->options['gcProbablity'])) {
222+
if ($this->options['gcProbability'] > 0.0 && (1.0 === $this->options['gcProbability'] || (random_int(0, \PHP_INT_MAX) / \PHP_INT_MAX) <= $this->options['gcProbability'])) {
216223
$this->createTtlIndex();
217224
}
218225

src/Symfony/Component/Lock/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
],
1818
"require": {
1919
"php": ">=8.1",
20-
"psr/log": "^1|^2|^3"
20+
"psr/log": "^1|^2|^3",
21+
"symfony/deprecation-contracts": "^2.5|^3"
2122
},
2223
"require-dev": {
2324
"doctrine/dbal": "^2.13|^3.0",

0 commit comments

Comments
 (0)
0