ServletValve::invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 16
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * \AppserverIo\Appserver\ServletEngine\ServletValve
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/appserver
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Appserver\ServletEngine;
22
23
use AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface;
24
use AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface;
25
26
/**
27
 * Valve implementation that will be executed by the servlet engine to handle
28
 * an incoming HTTP servlet request.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2015 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/appserver-io/appserver
34
 * @link      http://www.appserver.io
35
 */
36
class ServletValve implements ValveInterface
37
{
38
39
    /**
40
     * Processes the request by invoking the request handler that executes the servlet
41
     * in a protected context.
42
     *
43
     * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The request instance
44
     * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance
45
     *
46
     * @return void
47
     */
48
    public function invoke(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
49
    {
50
51
        // load the servlet manager
52
        /** @var \AppserverIo\Psr\Servlet\ServletContextInterface|\AppserverIo\Psr\Application\ManagerInterface $servletManager */
53
        $servletManager = $servletRequest->getContext()->search('ServletContextInterface');
0 ignored issues
show
Bug introduced by
The method getContext() does not exist on AppserverIo\Psr\Servlet\...ServletRequestInterface. Did you maybe mean getContextPath()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $servletManager = $servletRequest->/** @scrutinizer ignore-call */ getContext()->search('ServletContextInterface');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
55
        // locate and service the servlet
56
        $servlet = $servletManager->locate($servletRequest);
0 ignored issues
show
Bug introduced by
The method locate() does not exist on AppserverIo\Psr\Application\ManagerInterface. It seems like you code against a sub-type of AppserverIo\Psr\Application\ManagerInterface such as AppserverIo\Appserver\MessageQueue\QueueManager or AppserverIo\Appserver\ServletEngine\ServletManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        /** @scrutinizer ignore-call */ 
57
        $servlet = $servletManager->locate($servletRequest);
Loading history...
Bug introduced by
The method locate() does not exist on AppserverIo\Psr\Servlet\ServletContextInterface. It seems like you code against a sub-type of AppserverIo\Psr\Servlet\ServletContextInterface such as AppserverIo\Appserver\ServletEngine\ServletManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        /** @scrutinizer ignore-call */ 
57
        $servlet = $servletManager->locate($servletRequest);
Loading history...
57
        $servlet->service($servletRequest, $servletResponse);
58
59
        // finally invoke the destroy() method
60
        $servlet->destroy();
61
62
        // dispatch this request, because we have finished processing it
63
        $servletRequest->setDispatched(true);
64
    }
65
}
66