GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — 3.x (#2549)
by
unknown
02:15
created

NotAllowed::renderPlainOptionsMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Slim Framework (https://slimframework.com)
4
 *
5
 * @link      https://github.com/slimphp/Slim
6
 * @copyright Copyright (c) 2011-2017 Josh Lockhart
7
 * @license   https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
8
 */
9
namespace Slim\Handlers;
10
11
use Psr\Http\Message\ServerRequestInterface;
12
use Psr\Http\Message\ResponseInterface;
13
use Slim\Http\Body;
14
use UnexpectedValueException;
15
16
/**
17
 * Default Slim application not allowed handler
18
 *
19
 * It outputs a simple message in either JSON, XML or HTML based on the
20
 * Accept header.
21
 */
22
class NotAllowed extends AbstractHandler
23
{
24
    /**
25
     * Invoke error handler
26
     *
27
     * @param  ServerRequestInterface $request  The most recent Request object
28
     * @param  ResponseInterface      $response The most recent Response object
29
     * @param  string[]               $methods  Allowed HTTP methods
30
     *
31
     * @return ResponseInterface
32
     * @throws UnexpectedValueException
33
     */
34
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $methods)
35
    {
36
        if ($request->getMethod() === 'OPTIONS') {
37
            $status = 200;
38
            $contentType = 'text/plain';
39
            $output = Render::make('PlainOptionsMessage', $methods);
40 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
            $status = 405;
42
            $contentType = $this->determineContentType($request);
43
            switch ($contentType) {
44
                case 'application/json':
45
                    $output = Render::make('JsonNotAllowedMessage', $methods);
46
                    break;
47
48
                case 'text/xml':
49
                case 'application/xml':
50
                    $output = Render::make('XmlNotAllowedMessage', $methods);
51
                    break;
52
53
                case 'text/html':
54
                    $output = Render::make('HtmlNotAllowedMessage', $methods);
55
                    break;
56
                default:
57
                    throw new UnexpectedValueException('Cannot render unknown content type ' . $contentType);
58
            }
59
        }
60
61
        $body = new Body(fopen('php://temp', 'r+'));
62
        $body->write($output);
63
        $allow = implode(', ', $methods);
64
65
        return $response
66
                ->withStatus($status)
67
                ->withHeader('Content-type', $contentType)
68
                ->withHeader('Allow', $allow)
69
                ->withBody($body);
70
    }
71
}
72