Completed
Push — master ( f0b491...11ee78 )
by Thomas
09:37
created

AppKernel::main()   A

Complexity

Conditions 4
Paths 39

Size

Total Lines 57
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 57
rs 9.031
cc 4
eloc 25
nc 39
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace keeko\core\kernel;
3
4
use keeko\core\routing\ApplicationRouter;
5
use Symfony\Component\HttpFoundation\Request;
6
7
class AppKernel extends AbstractKernel {
8
9
	public function process(array $options = []) {
10
		try {
11
			$request = Request::createFromGlobals();
12
13
// 			printf('<p>Basepath: %s<br>
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
14
// 					Pathinfo: %s<br>
15
// 					Baseurl: %s<br>
16
// 					Host: %s<br>
17
// 					HttpHost: %s<br>
18
// 					Requsturi: %s<br>
19
// 					Uri: %s<br>
20
// 					Port: %s<br>
21
// 					Secure: %s</p>',
22
// 					$request->getBasePath(),
23
// 					$request->getPathInfo(),
24
// 					$request->getBaseUrl(),
25
// 					$request->getHost(),
26
// 					$request->getHttpHost(),
27
// 					$request->getRequestUri(),
28
// 					$request->getUri(),
29
// 					$request->getPort(),
30
// 					$request->isSecure() ? 'yes' : 'no');
31
		
32
			// no trailing slashes in urls
33
			if (substr($request->getUri(), -1) == '/') {
34
				$this->redirect(rtrim($request->getUri(), '/'));
35
			}
36
		
37
			$router = new ApplicationRouter();
38
		
39
			$uri = $router->match($request);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
40
			$model = $uri->getApplication();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
41
			$destination = str_replace($router->getDestination(), '', $request->getUri());
42
			$root = str_replace($router->getPrefix(), '', $destination);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
43
		
44
			$class = $model->getClassName();
45
			$app = new $class($model, $this->service);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
46
			$app->setLocalization($uri->getLocalization());
47
			$app->setRootUrl($root);
48
			$app->setAppPath($router->getPrefix());
49
			$app->setDestinationPath($router->getDestination());
50
			$this->app = $app;
51
52
			$response = $this->handle($app, $request);
53
54
			if ($response instanceof RedirectResponse) {
0 ignored issues
show
Bug introduced by
The class keeko\core\kernel\RedirectResponse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
55
				$response->sendHeaders();
56
				$this->redirect($response->getTargetUrl());
57
			}
58
			
59
			$response->prepare($request);
60
			
61
			return $response;
62
		} catch (\Exception $e) {
63
			printf('<b>[%s] %s</b><pre>%s</pre>', get_class($e), $e->getMessage(), $e->getTraceAsString());
64
		}
65
	}
66
	
67
	/**
68
	 * Returns the application
69
	 *
70
	 * @return AbstractApplication
71
	 */
72
	public function getApplication() {
73
		return $this->app;
74
	}
75
	
76
	private function redirect($url) {
77
		header('Location: ' . $url);
78
		exit(0);
0 ignored issues
show
Coding Style Compatibility introduced by
The method redirect() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
79
	}
80
}
81