Passed
Push — release/1.0.0 ( ebadbe...948a47 )
by Yo
01:34
created

DefinitionRefResolver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getErrorDefinitionId() 0 13 3
A getDefinitionRef() 0 3 1
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 3
    public function getMethodDefinitionId(MethodDoc $method, $definitionType)
24
    {
25 3
        $base = 'UNKNONWN_METHOD-%s';
26
        switch ($definitionType) {
27 3
            case self::METHOD_RESULT_DEFINITION_TYPE:
28 1
                $base = 'Method-%s-Result';
29 1
                break;
30 2
            case self::METHOD_PARAMS_DEFINITION_TYPE:
31 1
                $base = 'Method-%s-RequestParams';
32 1
                break;
33
        }
34
35 3
        return sprintf($base, $method->getIdentifier());
36
    }
37
38
    /**
39
     * @param ErrorDoc $error
40
     * @param string          $definitionType
41
     *
42
     * @return string
43
     */
44 3
    public function getErrorDefinitionId(ErrorDoc $error, $definitionType)
45
    {
46 3
        $base = 'UNKNONWN_ERROR-%s';
47
        switch ($definitionType) {
48 3
            case self::CUSTOM_ERROR_DEFINITION_TYPE:
49 1
                $base = 'Error-%s';
50 1
                break;
51 2
            case self::SERVER_ERROR_DEFINITION_TYPE:
52 1
                $base = 'ServerError-%s';
53 1
                break;
54
        }
55
56 3
        return sprintf($base, $error->getIdentifier());
57
    }
58
59
    /**
60
     * @param string $path
61
     *
62
     * @return string
63
     */
64 1
    public function getDefinitionRef(string $path) : string
65
    {
66 1
        return sprintf('#/definitions/%s', $path);
67
    }
68
}
69