Skip to content

Commit

Permalink
Merge pull request #71 from laminas/4.2.x-merge-up-into-4.3.x_QBVrvbwo
Browse files Browse the repository at this point in the history
Merge release 4.2.2 into 4.3.x
  • Loading branch information
weierophinney committed Aug 2, 2021
2 parents 74bcbe2 + ed5d9ca commit edb70c8
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
19 changes: 16 additions & 3 deletions docs/book/v4/strategy.md
Expand Up @@ -84,12 +84,25 @@ if present, will use it to translate the property name prior to looking up a

### Laminas\\Hydrator\\Strategy\\BooleanStrategy

> Deprecated since version 4.2.0. Use the [ScalarTypeStrategy](#laminashydratorstrategyscalartypestrategy] instead.
This strategy converts values into Booleans and vice versa. It expects two
This strategy converts values into booleans and vice versa. It expects two
arguments at the constructor, which are used to define value maps for `true` and
`false`.

The arguments could be strings:

```php
$boolStrategy = new Laminas\Hydrator\Strategy\BooleanStrategy('1', '0');
```

or integers:

```php
$boolStrategy = new Laminas\Hydrator\Strategy\BooleanStrategy(1, 0);
```

The main difference from [ScalarTypeStrategy](#laminashydratorstrategyscalartypestrategy)
is extracting booleans back to arguments given at the constructor.

### Laminas\\Hydrator\\Strategy\\ClosureStrategy

This is a strategy that allows you to pass in options for:
Expand Down
6 changes: 0 additions & 6 deletions psalm.xml.dist
Expand Up @@ -16,12 +16,6 @@
</projectFiles>

<issueHandlers>
<DeprecatedClass>
<errorLevel type="suppress">
<file name="test/Strategy/BooleanStrategyTest.php"/>
</errorLevel>
</DeprecatedClass>

<InternalMethod>
<errorLevel type="suppress">
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::method"/>
Expand Down
13 changes: 12 additions & 1 deletion src/Aggregate/HydrateEvent.php
Expand Up @@ -9,6 +9,8 @@
/**
* Event triggered when the {@see AggregateHydrator} hydrates
* data into an object
*
* @template T of object
*/
class HydrateEvent extends Event
{
Expand All @@ -19,14 +21,18 @@ class HydrateEvent extends Event
*/
protected $name = self::EVENT_HYDRATE;

/** @var object */
/**
* @var object
* @psalm-var T
*/
protected $hydratedObject;

/** @var mixed[] Data being used to hydrate the $hydratedObject */
protected $hydrationData;

/**
* @param mixed[] $hydrationData Data being used to hydrate the $hydratedObject
* @psalm-param T $hydratedObject
*/
public function __construct(object $target, object $hydratedObject, array $hydrationData)
{
Expand All @@ -38,12 +44,17 @@ public function __construct(object $target, object $hydratedObject, array $hydra

/**
* Retrieves the object that is being hydrated
*
* @psalm-return T
*/
public function getHydratedObject(): object
{
return $this->hydratedObject;
}

/**
* @psalm-param T $hydratedObject
*/
public function setHydratedObject(object $hydratedObject): void
{
$this->hydratedObject = $hydratedObject;
Expand Down
3 changes: 3 additions & 0 deletions src/HydrationInterface.php
Expand Up @@ -13,6 +13,9 @@ interface HydrationInterface
* @return object The implementation should return an object of any type.
* By purposely omitting the return type from the signature,
* implementations may choose to specify a more specific type.
* @psalm-param T $object
* @psalm-return T
* @template T of object
*/
public function hydrate(array $data, object $object);
}
2 changes: 0 additions & 2 deletions src/Strategy/BooleanStrategy.php
Expand Up @@ -16,8 +16,6 @@

/**
* This Strategy extracts and hydrates int and string values to Boolean values
*
* @deprecated Since version 4.2.0; use the {@see ScalarTypeStrategy} instead.
*/
final class BooleanStrategy implements StrategyInterface
{
Expand Down
1 change: 1 addition & 0 deletions test/Aggregate/HydratorListenerTest.php
Expand Up @@ -80,6 +80,7 @@ public function testOnHydrate(): void
->will($this->returnValue($hydrated));
$event->expects($this->once())->method('setHydratedObject')->with($hydrated);

/** @psalm-suppress MixedArgumentTypeCoercion */
$this->assertSame($hydrated, $this->listener->onHydrate($event));
}

Expand Down
10 changes: 5 additions & 5 deletions test/ClassMethodsHydratorTest.php
Expand Up @@ -46,18 +46,18 @@ public function testCanExtractFromMethodsWithOptionalParameters(): void
*/
public function testCanHydratedPromiscuousInstances(): void
{
/** @var ClassMethodsCamelCase $classMethodsCamelCase */
$classMethodsCamelCase = $this->hydrator->hydrate(
$classMethodsCamelCase = $this->hydrator->hydrate(
['fooBar' => 'baz-tab'],
new ClassMethodsCamelCase()
);
/** @var ClassMethodsCamelCaseMissing $classMethodsCamelCaseMissing */
$classMethodsCamelCaseMissing = $this->hydrator->hydrate(
['fooBar' => 'baz-tab'],
new ClassMethodsCamelCaseMissing()
);
/** @var ArraySerializable $arraySerializable */
$arraySerializable = $this->hydrator->hydrate(['fooBar' => 'baz-tab'], new ArraySerializable());
$arraySerializable = $this->hydrator->hydrate(
['fooBar' => 'baz-tab'],
new ArraySerializable()
);

$this->assertSame('baz-tab', $classMethodsCamelCase->getFooBar());
$this->assertSame('baz-tab', $classMethodsCamelCaseMissing->getFooBar());
Expand Down

0 comments on commit edb70c8

Please sign in to comment.