Completed
Push — master ( baf9c0...cf2f5b )
by Wanderson
02:20
created

RouteTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 34.62 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 27
loc 78
rs 10
wmc 5
lcom 0
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testThereIsNoRoutes() 0 11 1
A testThereIsOneRoute() 0 15 1
A testRouteToPageNotFound() 14 14 1
A testRouteToActionNotFound() 13 13 1
A testRouteWithCustomParam() 0 17 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Win\Mvc;
3
4
use Win\Helper\Url;
5
use Win\Mvc\Route;
6
use Win\Mvc\Application;
7
8
9
class RouteTest extends \PHPUnit_Framework_TestCase {
10
11
	public function testThereIsNoRoutes() {
12
13
		Url::instance()->setUrl('my-page/my-action/my-param/');
14
		$config = [];
15
		$app = new Application($config);
16
		$app->controller->load();
17
18
		$this->assertEquals('404', $app->getPage());
19
		$this->assertFalse(Route::instance()->hasCustomUrl());
20
		$this->assertEquals([null, null], Route::instance()->getCustomUrl());
21
	}
22
23
	public function testThereIsOneRoute() {
24
		Url::instance()->setUrl('my-page/my-action/my-param/');
25
		$config = [
26
			'route' => [
27
				'my-page/(.*)' => 'index'
28
			]
29
		];
30
31
		$app = new Application($config);
0 ignored issues
show
Documentation introduced by
$config is of type array<string,array<strin.../(.*)\":\"string\"}>"}>, but the function expects a array<integer,string>.

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...
32
		$app->controller->load();
33
34
		$this->assertEquals('index', $app->getPage());
35
		$this->assertTrue(Route::instance()->hasCustomUrl());
36
		$this->assertEquals(['index', null], Route::instance()->getCustomUrl());
37
	}
38
39 View Code Duplication
	public function testRouteToPageNotFound() {
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...
40
		Url::instance()->setUrl('my-page/my-action/my-param/');
41
		$config = [
42
			'route' => [
43
				'other-page' => 'index'
44
			]
45
		];
46
47
		$app = new Application($config);
0 ignored issues
show
Documentation introduced by
$config is of type array<string,array<strin...-page\":\"string\"}>"}>, but the function expects a array<integer,string>.

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...
48
		$app->controller->load();
49
50
		$this->assertEquals('404', $app->getPage());
51
		$this->assertFalse(Route::instance()->hasCustomUrl());
52
	}
53
54 View Code Duplication
	public function testRouteToActionNotFound() {
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...
55
		Url::instance()->setUrl('my-page/my-action/my-param/');
56
		$config = [
57
			'route' => [
58
				'my-page/(.*)' => 'index/this-action-doeent-exit'
59
			]
60
		];
61
62
		$app = new Application($config);
0 ignored issues
show
Documentation introduced by
$config is of type array<string,array<strin.../(.*)\":\"string\"}>"}>, but the function expects a array<integer,string>.

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...
63
		$app->controller->load();
64
65
		$this->assertEquals('404', $app->getPage());
66
	}
67
68
	public function testRouteWithCustomParam() {
69
		Url::instance()->setUrl('my-product/list/id/100');
70
		$config = [
71
			'route' => [
72
				'my-product/(.*)/id/(.*)' => 'index/index/$1/teste/$2'
73
			]
74
		];
75
76
		$app = new Application($config);
0 ignored issues
show
Documentation introduced by
$config is of type array<string,array<strin.../(.*)\":\"string\"}>"}>, but the function expects a array<integer,string>.

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...
77
		$app->controller->load();
78
79
		$this->assertEquals('index', $app->getPage());
80
		$this->assertEquals('list', $app->getParam(2));
81
		$this->assertEquals('teste', $app->getParam(3));
82
		$this->assertEquals('100', $app->getParam(4));
83
		$this->assertEquals(['index', 'index', 'list', 'teste', '100'], array_filter(Route::instance()->getCustomUrl()));
84
	}
85
86
}
87