Completed
Push — master ( 5c71f2...630401 )
by Oleg
07:36
created

GeneralErrorResponseFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 24
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 3
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Stdlib\Validation;
5
6
use Psr\Http\Message\ResponseInterface;
7
use SlayerBirden\DataFlowServer\Notification\DangerMessage;
8
use Zend\Diactoros\Response\JsonResponse;
9
10
final class GeneralErrorResponseFactory
11
{
12 28
    public function __invoke(
13
        string $message,
14
        ?string $dataObjectName = null,
15
        $code = 500,
16
        $value = null,
17
        $count = null
18
    ): ResponseInterface {
19 28
        $data = [];
20 28
        if ($dataObjectName !== null) {
21 20
            $data[$dataObjectName] = $value;
22 20
            $data['validation'] = [];
23
        }
24 28
        if ($count !== null) {
25 4
            $data['count'] = $count;
26
        }
27 28
        return new JsonResponse([
28 28
            'data' => $data,
29
            'success' => false,
30 28
            'msg' => new DangerMessage($message),
31 28
        ], $code);
32
    }
33
}
34