Skip to content

Commit 51794a1

Browse files
authored
Enhancement: Use Helper to select random element instead of array_rand() (#754)
1 parent 2c28821 commit 51794a1

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Faker/Core/File.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,14 @@ final class File implements Extension\FileExtension
547547

548548
public function mimeType(): string
549549
{
550-
return array_rand($this->mimeTypes, 1);
550+
return Extension\Helper::randomElement(array_keys($this->mimeTypes));
551551
}
552552

553553
public function extension(): string
554554
{
555-
$extension = $this->mimeTypes[array_rand($this->mimeTypes, 1)];
555+
$extension = Extension\Helper::randomElement($this->mimeTypes);
556556

557-
return is_array($extension) ? $extension[array_rand($extension, 1)] : $extension;
557+
return is_array($extension) ? Extension\Helper::randomElement($extension) : $extension;
558558
}
559559

560560
public function filePath(): string

src/Faker/ORM/CakePHP/EntityPopulator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Faker\ORM\CakePHP;
44

55
use Cake\ORM\TableRegistry;
6+
use Faker\Extension;
67

78
class EntityPopulator
89
{
@@ -112,7 +113,7 @@ public function guessModifiers()
112113
throw new \Exception(sprintf('%s belongsTo %s, which seems empty at this point.', $this->getTable($this->class)->table(), $assoc->table()));
113114
}
114115

115-
$foreignKey = $foreignKeys[array_rand($foreignKeys)];
116+
$foreignKey = Extension\Helper::randomElement($foreignKeys);
116117
$data[$assoc->foreignKey()] = $foreignKey;
117118

118119
return $data;

0 commit comments

Comments
 (0)