Skip to content

Commit f8f3916

Browse files
committed
Fix wrong type - #33
1 parent 9261d4a commit f8f3916

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/ValueObject/ArrayFactory.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function nodeVisitorsFromNative(string $name, TypeSet ...$typeSets): arra
283283
($this->classNameFilter)($typeName)
284284
);
285285

286-
$nodeVisitors[] = new ClassMethod($this->methodFromArray($name, $typeName, 'from' . $typeMethod));
286+
$nodeVisitors[] = new ClassMethod($this->methodFromArray($name, $typeName, 'from' . $typeMethod, \lcfirst($typeMethod)));
287287
$nodeVisitors[] = new ClassMethod($this->methodFromItems($name, $typeName));
288288
$nodeVisitors[] = new ClassMethod($this->methodEmptyList());
289289
$nodeVisitors[] = new ClassMethod($this->methodMagicConstruct($name, $name, $typeName));
@@ -319,7 +319,7 @@ public function classBuilderFromNative(string $name, TypeSet ...$typeSets): Clas
319319
($this->classNameFilter)($typeName)
320320
);
321321
$classBuilder->addMethod(
322-
ClassMethodBuilder::fromNode($this->methodFromArray($name, $typeName, 'from' . $typeMethod)->generate()),
322+
ClassMethodBuilder::fromNode($this->methodFromArray($name, $typeName, 'from' . $typeMethod, \lcfirst($typeMethod))->generate()),
323323
ClassMethodBuilder::fromNode($this->methodFromItems($name, $typeName)->generate()),
324324
ClassMethodBuilder::fromNode($this->methodEmptyList()->generate()),
325325
ClassMethodBuilder::fromNode($this->methodMagicConstruct($name, $name, $typeName)->generate()),
@@ -590,10 +590,11 @@ public function methodToArray(
590590
public function methodFromArray(
591591
string $argumentName,
592592
string $typeName,
593-
string $typeMethod = 'fromString'
593+
string $typeMethod = 'fromString',
594+
string $type = 'string'
594595
): MethodGenerator {
595596
$body = <<<'PHP'
596-
return new self(...array_map(static function (string $item) {
597+
return new self(...array_map(static function (%s $item) {
597598
return %s::%s($item);
598599
}, $%s));
599600
PHP;
@@ -606,7 +607,7 @@ public function methodFromArray(
606607
new ParameterGenerator($argumentName, 'array'),
607608
],
608609
MethodGenerator::FLAG_PUBLIC | MethodGenerator::FLAG_STATIC,
609-
new BodyGenerator($this->parser, \sprintf($body, $typeName, $typeMethod, $argumentName))
610+
new BodyGenerator($this->parser, \sprintf($body, $type, $typeName, $typeMethod, $argumentName))
610611
);
611612
$method->setTyped($this->typed);
612613
$method->setReturnType('self');

tests/ValueObjectFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ public function count() : int
528528
}
529529
public static function fromArray(array $shippingAddresses) : self
530530
{
531-
return new self(...array_map(static function (string $item) {
531+
return new self(...array_map(static function (array $item) {
532532
return Address::fromArray($item);
533533
}, $shippingAddresses));
534534
}

0 commit comments

Comments
 (0)