BlogPostStrategy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 8 2
A extract() 0 11 2
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 2
        }
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 2
            );
36 2
        }
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