Passed
Branch 3.3 (6947f9)
by Pieter
03:45
created

ApiResourceLinkSchemaBuilder::__invoke()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 2
nop 5
dl 0
loc 14
rs 10
1
<?php
2
3
4
namespace W2w\Lib\Apie\Plugins\PrimaryKey\Schema;
5
6
7
use erasys\OpenApi\Spec\v3\Schema;
8
use W2w\Lib\Apie\OpenApiSchema\SchemaGenerator;
9
use W2w\Lib\Apie\PluginInterfaces\DynamicSchemaInterface;
10
11
class ApiResourceLinkSchemaBuilder implements DynamicSchemaInterface
12
{
13
14
    /**
15
     * @param string $resourceClass
16
     * @param string $operation
17
     * @param array $groups
18
     * @param int $recursion
19
     * @param SchemaGenerator $generator
20
     */
21
    public function __invoke(
22
        string $resourceClass,
23
        string $operation,
24
        array $groups,
25
        int $recursion,
26
        SchemaGenerator $generator
27
    ) {
28
        if ($recursion > 0 && $operation === 'get') {
29
            return new Schema([
30
                'type' => 'string',
31
                'format' => 'path',
32
            ]);
33
        }
34
        return $generator->createSchema($resourceClass, $operation, $groups);
35
    }
36
}
37