Completed
Push — master ( c93e0a...f87b82 )
by Mario
09:30 queued 03:59
created

src/Hydrator/Strategy/BlogPostStrategy.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Marek\Toggable\Hydrator\Strategy;
4
5
use Marek\Toggable\API\Toggl\Values\User\BlogPost;
6
use Marek\Toggable\Hydrator\StrategyInterface;
7
8
/**
9
 * Class BlogPostStrategy
10
 * @package Marek\Toggable\Hydrator\Strategy
11
 */
12
class BlogPostStrategy implements StrategyInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 3
    public function hydrate($value)
18
    {
19 3
        if (is_array($value)) {
20 2
            $value = new BlogPost($value);
21
        }
22
23 3
        return $value;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 3
    public function extract($value)
30
    {
31 3
        if ($value instanceof BlogPost) {
32
            $value = array(
33 2
                'title' => $value->title,
34 2
                'url' => $value->url,
35
            );
36
        }
37
38 3
        return $value;
0 ignored issues
show
Bug Compatibility introduced by
The expression return $value; of type array<string,string>|object is incompatible with the return type declared by the interface Marek\Toggable\Hydrator\StrategyInterface::extract of type array as it can also be of type object which is not included in this return type.
Loading history...
39
    }
40
}
41