Completed
Push — master ( 6e1c48...7d90f1 )
by John
03:00
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
9
namespace KleijnWeb\PhpApi\Descriptions\Util;
10
11
use KleijnWeb\PhpApi\Descriptions\Description\Operation;
12
13
class OkStatusResolver
14
{
15
    /**
16
     * @param mixed     $operationResult
17
     * @param Operation $operation
18
     * @return int
19
     */
20
    public function resolve($operationResult, Operation $operation): int
21
    {
22
        $codes = $operation->getStatusCodes();
23
24
        if ($operationResult === null) {
25
            if (in_array(204, $codes)) {
26
                return 204;
27
            }
28
        }
29
30
        $statusCode = 200;
31
        foreach ($codes as $code) {
32
            if ('2' == substr((string)$code, 0, 1)) {
33
                $statusCode = $code;
34
                break;
35
            }
36
        }
37
38
        return $statusCode;
39
    }
40
}
41