Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DeliveryPatchRequestHandler
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2022 (original work) Open Assessment Technologies SA;
19 *
20 * @author Sergei Mikhailov <sergei.mikhailov@taotesting.com>
21 */
22
23declare(strict_types=1);
24
25namespace oat\taoDeliveryRdf\model\Delivery\Presentation\Web\RequestHandler;
26
27use common_exception_RestApi as BadRequestException;
28use oat\taoDeliveryRdf\model\Delivery\Business\Input\DeliveryUpdateInput;
29use Psr\Http\Message\ServerRequestInterface;
30
31class DeliveryPatchRequestHandler
32{
33    /** @var DeliverySearchRequestHandler */
34    private $searchRequestHandler;
35
36    /** @var DeliveryPatchRequestHandlerInterface[] */
37    private $patchRequestHandlers;
38
39    public function __construct(
40        DeliverySearchRequestHandler $searchRequestHandler,
41        DeliveryPatchRequestHandlerInterface ...$patchRequestHandlers
42    ) {
43        $this->searchRequestHandler = $searchRequestHandler;
44        $this->patchRequestHandlers = $patchRequestHandlers;
45    }
46
47    /**
48     * @throws BadRequestException
49     */
50    public function handle(ServerRequestInterface $request): DeliveryUpdateInput
51    {
52        $searchRequest = $this->searchRequestHandler->handle($request);
53
54        foreach ($this->patchRequestHandlers as $patchRequestHandler) {
55            if ($patchRequestHandler->isApplicable($request)) {
56                return new DeliveryUpdateInput(
57                    $searchRequest,
58                    $patchRequestHandler->handle($request)
59                );
60            }
61        }
62
63        throw new BadRequestException('Unsupported Media Type', 415);
64    }
65}