TryCatch::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 2
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace einfach\operation\step;
4
5
use einfach\operation\Railway;
6
use function einfach\operation\response\error;
7
8
class TryCatch extends AbstractStep
9
{
10 6
    public function __invoke(&$params, string $track)
11
    {
12
        // only on OK track
13 6
        if ($track == Railway::TRACK_SUCCESS) {
14
            try {
15 4
                $response = $this->normalizeStepResponse(call_user_func($this->function, $params));
16 2
                return $response;
17 2
            } catch (\Exception $e) {
18 2
                return $this->normalizeStepResponse(error($params, $e->getMessage()));
19
            }
20
        } else {
21 2
            $this->skip();
22
        }
23 2
    }
24
}
25