Skip to content

Commit 52695f8

Browse files
committed
Refactor DataLoaderOptions validation to be more readable
1 parent f46e4f4 commit 52695f8

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/DataLoaderOptions.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,37 @@ public function shouldCache()
7070
*/
7171
private function validateOptions($maxBatchSize, $shouldBatch, $shouldCache)
7272
{
73-
if (! is_bool($shouldBatch)) {
73+
$this->validateMaxBatchSizeOption($maxBatchSize);
74+
$this->validateBatchOption($shouldBatch);
75+
$this->validateCacheOption($shouldCache);
76+
}
77+
78+
/**
79+
* @param bool $shouldBatch
80+
*/
81+
private function validateBatchOption($shouldBatch)
82+
{
83+
if (!is_bool($shouldBatch)) {
7484
throw new \InvalidArgumentException('Expected argument $shouldBatch to be a boolean');
7585
}
86+
}
7687

77-
if (! is_bool($shouldCache)) {
88+
/**
89+
* @param bool $shouldCache
90+
*/
91+
private function validateCacheOption($shouldCache)
92+
{
93+
if (!is_bool($shouldCache)) {
7894
throw new \InvalidArgumentException('Expected argument $shouldCache to be a boolean');
7995
}
96+
}
8097

81-
if ($maxBatchSize !== null && ! is_int($maxBatchSize)) {
98+
/**
99+
* @param null|int $maxBatchSize
100+
*/
101+
private function validateMaxBatchSizeOption($maxBatchSize)
102+
{
103+
if ($maxBatchSize !== null && !is_int($maxBatchSize)) {
82104
throw new \InvalidArgumentException('Expected argument $maxBatchSize to be null or an integer');
83105
}
84106
}

0 commit comments

Comments
 (0)