Completed
Push — master ( 73e21a...085edf )
by Jean-Christophe
04:37
created

JsUtils   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 56
Duplicated Lines 23.21 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 1
cbo 1
dl 13
loc 56
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setDi() 0 4 1
A getDi() 0 3 1
A getUrl() 0 3 1
A addViewElement() 0 8 2
A forward() 0 10 1
A renderContent() 0 6 1
B fromDispatcher() 13 13 5

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
3
namespace Ajax\php\phalcon;
4
5
use Phalcon\DiInterface;
6
use Phalcon\Di\InjectionAwareInterface;
7
use Phalcon\Mvc\View;
8
use Phalcon\Mvc\Controller;
9
10
class JsUtils extends \Ajax\JsUtils implements InjectionAwareInterface{
11
	protected $_di;
12
	public function setDi(DiInterface $di) {
13
		$this->_di=$di;
14
		//$this->_setDi($di);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
15
	}
16
17
	public function getDi() {
18
		return $this->_di;
19
	}
20
21
	public function getUrl($url){
22
		return $this->_di->get("url")->get($url);
23
	}
24
25
	public function addViewElement($identifier,$content,$view){
26
		$controls=$view->getVar("q");
27
		if (isset($controls) === false) {
28
			$controls=array ();
29
		}
30
		$controls[$identifier]=$content;
31
		$view->setVar("q", $controls);
32
	}
33
34
	public function forward($initialController,$controller,$action){
35
		$dispatcher = $initialController->dispatcher;
36
		$dispatcher->setControllerName($controller);
37
		$dispatcher->setActionName($action);
38
		$dispatcher->dispatch();
39
		$template=$initialController->view->getRender($dispatcher->getControllerName(), $dispatcher->getActionName(),$dispatcher->getParams(), function ($view) {
40
			$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
41
		});
42
		return $template;
43
	}
44
45
	public function renderContent($view, $controller, $action, $params=NULL) {
46
		$template=$view->getRender($controller, $action, $params, function ($view) {
47
			$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
48
		});
49
		return $template;
50
	}
51
52 View Code Duplication
	public function fromDispatcher($dispatcher){
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...
53
		$params=$dispatcher->getParams();
54
		$action=$dispatcher->getActionName();
55
		$items=array($dispatcher->getControllerName());
56
		if(\sizeof($params)>0 || \strtolower($action)!="index" ){
57
			$items[]=$action;
58
			foreach ($params as $p){
59
				if(\is_object($p)===false)
60
					$items[]=$p;
61
			}
62
		}
63
		return $items;
64
	}
65
}