Completed
Push — master ( bc53b5...fc9cad )
by Jean-Christophe
03:58
created

_JsUtils   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 38.46 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 0
dl 20
loc 52
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 3 1
A addViewElement() 0 10 2
A createScriptVariable() 0 3 1
A forward() 9 9 1
A renderContent() 11 11 3
A fromDispatcher() 0 3 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
3
namespace Ajax\php\cakephp;
4
5
6
use Ajax\service\JString;
7
use Cake\Routing\Router;
8
class _JsUtils extends \Ajax\JsUtils{
9
	public function getUrl($url){
10
		return Router::url($url);
11
	}
12
	public function addViewElement($identifier,$content,&$view){
13
		$viewVars=$view->viewVars;
14
		if (isset($viewVars["q"]) === false) {
15
			$controls=array ();
16
		}else{
17
			$controls=$viewVars["q"];
18
		}
19
		$controls[$identifier]=$content;
20
		$view->set("q", $controls);
21
	}
22
23
	public function createScriptVariable(&$view,$view_var, $output){
24
		$view->set($view_var,$output);
25
	}
26
27
	/**
28
	 * @param Symfony\Component\DependencyInjection\ContainerInterface $initialControllerInstance
29
	 * @param string $controllerName
30
	 * @param string $actionName
31
	 * @param array $params
32
	 * @see \Ajax\JsUtils::forward()
33
	 */
34 View Code Duplication
	public function forward($initialControllerInstance,$controllerName,$actionName,$params=array()){
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...
35
		$path=$params;
36
		$request = $initialControllerInstance->get('request_stack')->getCurrentRequest();
37
		$path['_forwarded'] = $request->attributes;
38
		$path['_controller'] = $controllerName.":".$actionName;
39
		$subRequest = $request->duplicate([], null, $path);
40
		$response= $initialControllerInstance->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
41
		return $response->getContent();
42
	}
43
44 View Code Duplication
	public function renderContent($initialControllerInstance,$viewName, $params=NULL) {
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...
45
        if ($initialControllerInstance->has('templating')) {
46
            return $initialControllerInstance->get('templating')->render($viewName, $params);
47
        }
48
49
        if (!$initialControllerInstance->has('twig')) {
50
            throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available.');
51
        }
52
53
        return $initialControllerInstance->get('twig')->render($viewName, $params);
54
	}
55
56
	public function fromDispatcher($dispatcher){
57
		return \explode("/", Router::getRequest(true)->url);
58
	}
59
}