Completed
Push — master ( 22a756...a8d83f )
by John
02:03
created

OkStatusResolver::resolve()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 7
nop 2
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\PhpApi\Descriptions package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
namespace KleijnWeb\PhpApi\Middleware\Util;
9
10
use KleijnWeb\PhpApi\Descriptions\Description\Operation;
11
12
class OkStatusResolver
13
{
14
    /**
15
     * @param mixed     $operationResult
16
     * @param Operation $operation
17
     * @return int
18
     */
19
    public function resolve($operationResult, Operation $operation): int
20
    {
21
        $codes = $operation->getStatusCodes();
22
23
        if ($operationResult === null) {
24
            if (in_array(204, $codes)) {
25
                return 204;
26
            }
27
        }
28
29
        $statusCode = 200;
30
        foreach ($codes as $code) {
31
            if ('2' == substr((string)$code, 0, 1)) {
32
                $statusCode = $code;
33
                break;
34
            }
35
        }
36
37
        return $statusCode;
38
    }
39
}