UseCaseMock   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 24
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 15 2
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace FlexPHP\UseCases\Tests\Mocks;
11
12
use Exception;
13
use FlexPHP\UseCases\Exception\UnavailableRepositoryUseCaseException;
14
use FlexPHP\UseCases\UseCase;
15
16
/**
17
 * @method RepositoryMock getRepository()
18
 */
19
class UseCaseMock extends UseCase
20
{
21
    /**
22
     * Use case mock
23
     *
24
     * @param mixed|RequestMock $request
25
     *
26
     * @return ResponseMock
27
     */
28
    public function execute($request)
29
    {
30
        $this->throwExceptionIfRequestNotValid(__FUNCTION__, RequestMock::class, $request);
31
32
        $item = [];
33
        $item['foo'] = $request->foo;
34
        $item['bar'] = $request->bar;
35
36
        try {
37
            $response = $this->getRepository()->push($item);
38
        } catch (Exception $exception) {
39
            throw new UnavailableRepositoryUseCaseException($exception->getMessage());
40
        }
41
42
        return new ResponseMock($response);
43
    }
44
}
45