SimpleServletEngine::findRequestedApplication()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 18
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 18
loc 18
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
/**
4
 * AppserverIo\SingleApp\ServletEngine\SimpleServletEngine
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/single-app
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\SingleApp\ServletEngine;
22
23
use AppserverIo\Server\Dictionaries\ServerVars;
24
use AppserverIo\Server\Interfaces\RequestContextInterface;
25
use AppserverIo\Appserver\ServletEngine\ServletEngine;
26
use AppserverIo\Appserver\ServletEngine\BadRequestException;
27
28
/**
29
 * A servlet engine implementation to handle a single app container.
30
 *
31
 * @author    Tim Wagner <[email protected]>
32
 * @copyright 2015 TechDivision GmbH <[email protected]>
33
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
 * @link      https://github.com/appserver-io/single-app
35
 * @link      http://www.appserver.io
36
 */
37
class SimpleServletEngine extends ServletEngine
38
{
39
40
    /**
41
     * Simply returns the first application, assuming we only have one. If no application
42
     * has been deployed, an exception will be thrown.
43
     *
44
     * @param \AppserverIo\Server\Interfaces\RequestContextInterface $requestContext Context of the current request
45
     *
46
     * @return null|\AppserverIo\Psr\Application\ApplicationInterface
47
     * @throws \AppserverIo\Appserver\ServletEngine\BadRequestException Is thrown if no application is available
48
     */
49 View Code Duplication
    public function findRequestedApplication(RequestContextInterface $requestContext)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
50
    {
51
52
        // return the first application (we only have one)
53
        foreach ($this->applications as $application) {
54
            return $application;
55
        }
56
57
        // if we did not find anything we should throw a bad request exception
58
        throw new BadRequestException(
59
            sprintf(
60
                'Can\'t find application for URL %s%s',
61
                $requestContext->getServerVar(ServerVars::HTTP_HOST),
62
                $requestContext->getServerVar(ServerVars::X_REQUEST_URI)
63
            ),
64
            404
65
        );
66
    }
67
}
68