Completed
Push — master ( 5d1949...a5e456 )
by Andreas
8s
created

ConvertTypeToAccept   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 35
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 23 4
1
<?php
2
/**
3
 * Copyright (c) 2016-2016 The callingallpapers.com Developer Team
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 *
23
 * @author    Andreas Heigl<[email protected]>
24
 * @copyright 2016-2016 The callingallpapers.com Developer Team
25
 * @license   http://www.opensource.org/licenses/mit-license.php MIT-License
26
 * @version   0.0
27
 * @since     16.01.2016
28
 * @link      https://github.com/joindin/callingallpapers-api
29
 */
30
31
namespace Callingallpapers\Api\Middleware;
32
33
use Callingallpapers\Api\PersistenceLayer\UserPersistenceLayer;
34
use Psr\Http\Message\ResponseInterface;
35
use Psr\Http\Message\ServerRequestInterface;
36
37
class ConvertTypeToAccept
38
{
39
    /**
40
     * Convert a GET-Param "type" to an Accept-Header
41
     *
42
     * @param  \Psr\Http\Message\ServerRequestInterface $request  PSR7 request
43
     * @param  \Psr\Http\Message\ResponseInterface      $response PSR7 response
44
     * @param  callable                                 $next     Next middleware
45
     *
46
     * @return \Psr\Http\Message\ResponseInterface
47
     */
48
    public function __invoke(
49
        ServerRequestInterface $request,
50
        ResponseInterface $response,
51
        callable $next
52
    ) {
53
        $query = $request->getQueryParams();
54
        if (! isset($query['type'])) {
55
            return $next($request, $response);
56
        }
57
58
        switch (strtolower($query['type'])) {
59
            case 'rss':
60
                $request = $request->withHeader('Accept', 'application/rss+xml');
61
                break;
62
            case 'calendar':
63
                $request = $request->withHeader('Accept', 'text/calendar');
64
                break;
65
            default:
66
                break;
67
        }
68
69
        return $next($request, $response);
70
    }
71
}
72