| 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); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 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 |  | View Code Duplication | 	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 createScriptVariable($view,$view_var, $output){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		$view->setVar($view_var,$output); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 38 |  | View Code Duplication | 	public function forward($initialController,$controller,$action){ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		$dispatcher = $initialController->dispatcher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		$dispatcher->setControllerName($controller); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		$dispatcher->setActionName($action); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		$dispatcher->dispatch(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		$template=$initialController->view->getRender($dispatcher->getControllerName(), $dispatcher->getActionName(),$dispatcher->getParams(), function ($view) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			$view->setRenderLevel(View::LEVEL_ACTION_VIEW); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		return $template; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 47 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	public function renderContent($view, $controller, $action, $params=NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		$template=$view->getRender($controller, $action, $params, function ($view) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			$view->setRenderLevel(View::LEVEL_ACTION_VIEW); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		return $template; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 54 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 56 |  | View Code Duplication | 	public function fromDispatcher($dispatcher){ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		$params=$dispatcher->getParams(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$action=$dispatcher->getActionName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$items=array($dispatcher->getControllerName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		if(\sizeof($params)>0 || \strtolower($action)!="index" ){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			$items[]=$action; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 			foreach ($params as $p){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 				if(\is_object($p)===false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 					$items[]=$p; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		return $items; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 69 |  |  | } | 
            
                        
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.