Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit c04e9e3

Browse files
committed
Merge pull request #713 from pomaxa/rand
mt_rand instead of rand()
2 parents c8097f5 + fd2ce63 commit c04e9e3

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/Faker/ORM/Doctrine/EntityPopulator.php

+12-9
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,19 @@ public function guessColumnFormatters(\Faker\Generator $generator)
114114

115115
$index = 0;
116116
$formatters[$assocName] = function ($inserted) use ($relatedClass, &$index, $unique, $optional) {
117-
if ($unique && isset($inserted[$relatedClass])) {
118-
$related = null;
119-
if (isset($inserted[$relatedClass][$index]) || !$optional) {
120-
$related = $inserted[$relatedClass][$index];
121-
}
122117

123-
$index++;
118+
if (isset($inserted[$relatedClass])) {
119+
if ($unique) {
120+
$related = null;
121+
if (isset($inserted[$relatedClass][$index]) || !$optional) {
122+
$related = $inserted[$relatedClass][$index];
123+
}
124+
125+
$index++;
126+
127+
return $related;
128+
}
124129

125-
return $related;
126-
} elseif (isset($inserted[$relatedClass])) {
127130
return $inserted[$relatedClass][mt_rand(0, count($inserted[$relatedClass]) - 1)];
128131
}
129132

@@ -186,7 +189,7 @@ private function generateId($obj, $column, EntityManagerInterface $manager)
186189

187190
$id = null;
188191
do {
189-
$id = rand();
192+
$id = mt_rand();
190193
} while (in_array($id, $ids));
191194

192195
return $id;

0 commit comments

Comments
 (0)