Skip to content
This repository has been archived by the owner on Apr 10, 2020. It is now read-only.

Commit

Permalink
Bugfix: removed deprecated method usage for ReflectionType and added …
Browse files Browse the repository at this point in the history
…mixed type support

The method __toString was used on the ReflectionType returned from the parameter. This has been changed to using the getName method on the ReflectionNamedType.

Added support for mixed types.
  • Loading branch information
mfrankruijter committed Nov 17, 2019
1 parent de5e6ac commit 688eaea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
30 changes: 11 additions & 19 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,35 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.0.1 - 2019-11-17
## 1.0.2 - 2019-11-17
### Added
- Nothing
- Mixed parameter support.

### Changed
- Nothing
- Depending on deprecated method `__toString` on ReflectionType, to `getName`.

### Deprecated
- Nothing

### Removed
- Composer dependency on `ulrack/configuration`.
- Nothing

### Fixed
- Nothing

### Security
- Nothing

## 1.0.0 - 2019-11-17
### Added
- Created the initial implementation of the ObjectFactory.

### Changed
- Nothing

### Deprecated
- Nothing
## 1.0.1 - 2019-11-17

### Removed
- Nothing
- Composer dependency on `ulrack/configuration`.

### Fixed
- Nothing
## 1.0.0 - 2019-11-17

### Security
- Nothing
### Added
- Created the initial implementation of the ObjectFactory.

[Unreleased]: https://github.com/ulrack/object-factory/compare/1.0.1...HEAD
[Unreleased]: https://github.com/ulrack/object-factory/compare/1.0.2...HEAD
[1.0.2]: https://github.com/ulrack/object-factory/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/ulrack/object-factory/compare/1.0.0...1.0.1
4 changes: 2 additions & 2 deletions src/Component/Analyser/ClassAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ private function reflect(string $class): array
foreach ($constructor->getParameters() as $parameter) {
$type = $parameter->getType();
$parameters[$parameter->getName()] = [
'type' => $type->__toString(),
'builtin' => $type->isBuiltin(),
'type' => $type !== null ? $type->getName() : 'mixed',
'builtin' => $type !== null ? $type->isBuiltin(): true,
'allowsNull' => $parameter->allowsNull(),
'isOptional' => $parameter->isOptional(),
'isVariadic' => $parameter->isVariadic(),
Expand Down
4 changes: 3 additions & 1 deletion src/Factory/ObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ private function parameterByType(array $parameterConfig, $parameter)
if ($parameterConfig['builtin']) {
if (gettype(
$parameter
) === $parameterConfig['type']) {
) === $parameterConfig['type']
|| $parameterConfig['type'] === 'mixed') {
return $parameter;
}

throw new InvalidParameterTypeException($parameterConfig, $parameter);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Factory/ObjectFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public function testVariadicParameter(): void
VariadicTestClass::class,
[
'foo' => ['foo', 'bar', 'baz'],
'bar' => 'baz',
]
);

Expand Down Expand Up @@ -246,6 +247,7 @@ public function testVariadicParameterFailure(): void
VariadicTestClass::class,
[
'foo' => ['foo', 1, 'baz'],
'bar' => 'baz',
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/MockObjects/VariadicTestClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class VariadicTestClass
*
* @param string ...$foo
*/
public function __construct(string ...$foo)
public function __construct($bar, string ...$foo)
{
$this->foo = $foo;
}
Expand Down

0 comments on commit 688eaea

Please sign in to comment.