ApiResourceLinkSchemaBuilder::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 2
nop 5
dl 0
loc 15
rs 10
c 1
b 0
f 0
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\Core\ClassResourceConverter;
9
use W2w\Lib\Apie\OpenApiSchema\Factories\SchemaFactory;
10
use W2w\Lib\Apie\OpenApiSchema\OpenApiSchemaGenerator;
11
use W2w\Lib\Apie\PluginInterfaces\DynamicSchemaInterface;
12
use W2w\Lib\Apie\PluginInterfaces\FrameworkConnectionInterface;
13
14
class ApiResourceLinkSchemaBuilder implements DynamicSchemaInterface
15
{
16
    /**
17
     * @var FrameworkConnectionInterface
18
     */
19
    private $connection;
20
21
    public function __construct(FrameworkConnectionInterface $connection)
22
    {
23
        $this->connection = $connection;
24
    }
25
26
    /**
27
     * {@inheritDoc}
28
     */
29
    public function __invoke(
30
        string $resourceClass,
31
        string $operation,
32
        array $groups,
33
        int $recursion,
34
        OpenApiSchemaGenerator $generator
35
    ): ?Schema {
36
        if ($recursion > 0 && $operation === 'get') {
37
            return SchemaFactory::createStringSchema(
38
                'path',
39
                $this->connection->getExampleUrl($resourceClass),
40
                true
41
            );
42
        }
43
        return $generator->createSchema($resourceClass, $operation, $groups);
44
    }
45
}
46