Completed
Push — master ( 7b2ae7...b60607 )
by Dominik
06:56
created

IndexMapping   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 62
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getClass() 0 4 1
A getType() 0 4 1
A getFieldMappings() 0 4 1
A getEmbeddedFieldMappings() 0 4 1
A getLinkMappings() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ApiSkeleton\Serialization;
6
7
use Chubbyphp\Serialization\Link\LinkGeneratorInterface;
8
use Chubbyphp\Serialization\Mapping\FieldMappingInterface;
9
use Chubbyphp\Serialization\Mapping\LinkMapping;
10
use Chubbyphp\Serialization\Mapping\LinkMappingInterface;
11
use Chubbyphp\Serialization\Mapping\ObjectMappingInterface;
12
use Chubbyphp\Serialization\Serializer\Link\CallbackLinkSerializer;
13
use Chubbyphp\ApiSkeleton\Search\Index;
14
use Psr\Http\Message\ServerRequestInterface as Request;
15
16
final class IndexMapping implements ObjectMappingInterface
17
{
18
    /**
19
     * @var LinkGeneratorInterface
20
     */
21
    private $linkGenerator;
22
23
    /**
24
     * @param LinkGeneratorInterface $linkGenerator
25
     */
26 5
    public function __construct(LinkGeneratorInterface $linkGenerator)
27
    {
28 5
        $this->linkGenerator = $linkGenerator;
29 5
    }
30
31
    /**
32
     * @return string
33
     */
34 1
    public function getClass(): string
35
    {
36 1
        return Index::class;
37
    }
38
39
    /**
40
     * @return string
41
     */
42 1
    public function getType(): string
43
    {
44 1
        return 'index';
45
    }
46
47
    /**
48
     * @return FieldMappingInterface[]
49
     */
50 1
    public function getFieldMappings(): array
51
    {
52 1
        return [];
53
    }
54
55
    /**
56
     * @return FieldMappingInterface[]
57
     */
58 1
    public function getEmbeddedFieldMappings(): array
59
    {
60 1
        return [];
61
    }
62
63
    /**
64
     * @return LinkMappingInterface[]
65
     */
66
    public function getLinkMappings(): array
67
    {
68
        return [
69 1
            new LinkMapping('self', new CallbackLinkSerializer(function (Request $request) {
70 1
                return $this->linkGenerator->generateLink($request, 'index');
71 1
            })),
72 1
            new LinkMapping('courses', new CallbackLinkSerializer(function (Request $request) {
73 1
                return $this->linkGenerator->generateLink($request, 'course_search');
74 1
            })),
75
        ];
76
    }
77
}
78