Completed
Push — master ( 84255c...a7d7e4 )
by Thomas
14:38
created

PageRouter::match()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 25
Code Lines 8

Duplication

Lines 25
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 25
loc 25
rs 8.5806
ccs 0
cts 14
cp 0
cc 4
eloc 8
nc 8
nop 1
crap 20
1
<?php
2
namespace keeko\core\routing;
3
4
use Symfony\Component\Routing\Route;
5
use Symfony\Component\Routing\RouteCollection;
6
7
class PageRouter extends AbstractRouter implements RouterInterface {
8
	
9
	/*
10
	 * (non-PHPdoc) @see \keeko\core\routing\AbstractRouter::__construct()
11
	 */
12
	public function __construct(array $options) {
13
		// options
14
		parent::__construct($options);
0 ignored issues
show
Bug introduced by
The call to AbstractRouter::__construct() misses a required argument $options.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
$options is of type array, but the function expects a object<Symfony\Component\HttpFoundation\Request>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
15
		
16
		// routes
17
		$routes = new RouteCollection();
18
		$routes->add('slug', new Route('/{slug}'));
19
		$routes->add('params', new Route(sprintf('/{slug}%s{params}', $this->options['param-separator'])));
20
		
21
		$this->init($routes);
22
	}
23
	
24
	
25
	/*
26
	 * (non-PHPdoc) @see \keeko\core\routing\RouteMatcherInterface::match()
27
	 */
28 View Code Duplication
	public function match($destination) {
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...
29
		if ($destination == '') {
30
			$destination = '/';
31
		}
32
		
33
		$data = $this->matcher->match($destination);
34
		
35
		// find page for matched slug
36
		if (array_key_exists('slug', $data)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
37
// 			$data['page'] = PageQuery::create()
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
38
// 				->filterByApplication($this->options['application'])
39
// 				->useRouteQuery()
40
// 					->filterBySlug($data['slug'])
41
// 				->endUse()
42
// 				->find()
43
// 			;
44
		}
45
		
46
		// unserialize params
47
		if (array_key_exists('params', $data)) {
48
			$data['params'] = $this->unserializeParams($data['params']);
49
		}
50
		
51
		return $data;
52
	}
53
	
54
	/*
55
	 * @TODO: More data params (e.g. page) (non-PHPdoc) @see \keeko\core\routing\RouteGeneratorInterface::match()
56
	 */
57
	public function generate($data) {
58
		
59
		// params route
60 View Code Duplication
		if (array_key_exists('params', $data)) {
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...
61
			$data['params'] = $this->serializeParams($data['params']);
62
			return $this->generator->generate('params', $data);
63
		}
64
		
65
		// slug route
66
		return $this->generator->generate('slug', $data);
67
	}
68
}