Skip to content

Commit 2ad6c93

Browse files
Merge pull request #7 from janek2012/scalar-argument-fix
Added checking if provided arguments are objects
2 parents 2206649 + 1841b7a commit 2ad6c93

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

ModelFactoryCollection/ModelFactoryCollection.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,16 @@ public function createModels($objects)
7373
foreach ($objects as $key => $object) {
7474
$modelFactory = $this->findSupportingModelFactoryForObject($object);
7575
if (!$modelFactory instanceof ModelFactoryInterface) {
76+
if (is_object($object)) {
77+
throw new ModelFactoryCollectionException(sprintf(
78+
'Model factory for class %s not found.',
79+
get_class($object)
80+
));
81+
}
82+
7683
throw new ModelFactoryCollectionException(sprintf(
77-
"Model factory for class '%s' not found.",
78-
get_class($object)
84+
'Model factory for type %s not found.',
85+
gettype($object)
7986
));
8087
}
8188
$models[$key] = $this->createModelAndSetDependencies($modelFactory, $object);

Tests/Functional/ModelFactoryCollectionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public function dataProvider_supportsObjects_onInvalidArgument()
167167
[3],
168168
[false],
169169
[new stdClass()],
170+
[null],
170171
];
171172
}
172173

@@ -186,7 +187,7 @@ public function test_createModels_onInvalidArgument($invalidArgument)
186187
new BarModelFactory()
187188
);
188189

189-
$modelFactoryCollection->createModels($invalidArgument);
190+
$modelFactoryCollection->createModels([$invalidArgument]);
190191
}
191192

192193
/**

0 commit comments

Comments
 (0)