DefinitionRefResolver   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 57
ccs 16
cts 16
cp 1
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefinitionRef() 0 3 1
A getErrorDefinitionId() 0 13 3
A getMethodDefinitionId() 0 13 3
1
<?php
2
namespace Yoanm\JsonRpcHttpServerSwaggerDoc\App\Resolver;
3
4
use Yoanm\JsonRpcServerDoc\Domain\Model\ErrorDoc;
5
use Yoanm\JsonRpcServerDoc\Domain\Model\MethodDoc;
6
7
/**
8
 * Class DefinitionRefResolver
9
 */
10
class DefinitionRefResolver
11
{
12
    const METHOD_RESULT_DEFINITION_TYPE = 'method-result';
13
    const METHOD_PARAMS_DEFINITION_TYPE = 'method-params';
14
    const CUSTOM_ERROR_DEFINITION_TYPE = 'custom-error';
15
    const SERVER_ERROR_DEFINITION_TYPE = 'server-error';
16
17
    /**
18
     * @param MethodDoc $method
19
     * @param string    $definitionType
20
     *
21
     * @return string
22
     */
23 9
    public function getMethodDefinitionId(MethodDoc $method, $definitionType) : string
24
    {
25 9
        $base = 'UNKNONWN_METHOD-%s';
26
        switch ($definitionType) {
27
            case self::METHOD_RESULT_DEFINITION_TYPE:
28 7
                $base = 'Method-%s-Result';
29 7
                break;
30
            case self::METHOD_PARAMS_DEFINITION_TYPE:
31 7
                $base = 'Method-%s-RequestParams';
32 7
                break;
33
        }
34
35 9
        return sprintf($base, $method->getIdentifier());
36
    }
37
38
    /**
39
     * @param ErrorDoc $error
40
     * @param string          $definitionType
41
     *
42
     * @return string
43
     */
44 31
    public function getErrorDefinitionId(ErrorDoc $error, $definitionType) : string
45
    {
46 31
        $base = 'UNKNONWN_ERROR-%s';
47
        switch ($definitionType) {
48
            case self::CUSTOM_ERROR_DEFINITION_TYPE:
49 26
                $base = 'Error-%s';
50 26
                break;
51
            case self::SERVER_ERROR_DEFINITION_TYPE:
52 4
                $base = 'ServerError-%s';
53 4
                break;
54
        }
55
56 31
        return sprintf($base, $error->getIdentifier());
57
    }
58
59
    /**
60
     * @param string $path
61
     *
62
     * @return string
63
     */
64 7
    public function getDefinitionRef(string $path) : string
65
    {
66 7
        return sprintf('#/definitions/%s', $path);
67
    }
68
}
69