| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Ajax\semantic\html\content; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Ajax\service\JArray; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Ajax\semantic\html\elements\HtmlList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class HtmlListItem extends HtmlAbsractItem { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	protected $image; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 	public function __construct($identifier, $content=NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 		parent::__construct($identifier,"item",$content); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 13 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | 	protected function initContent($content){ | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | 		if(\is_array($content)){ | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 16 |  | View Code Duplication | 			if(JArray::isAssociative($content)===false){ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  | 				$icon=@$content[0]; | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  | 				$title=@$content[1]; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  | 				$desc=@$content[2]; | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | 			}else{ | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | 				$icon=@$content["icon"]; | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  | 				$image=@$content["image"]; | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | 				$title=@$content["title"]; | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | 				$header=@$content["header"]; | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | 				$desc=@$content["description"]; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | 				$items=@$content["items"]; | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  | 			if(isset($icon)===true){ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 				$this->setIcon($icon); | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | 			if(isset($image)===true){ | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | 				$this->setImage($image); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 			if(isset($title)===true){ | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 				$this->setTitle($title,$desc); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 			}elseif (isset($header)===true){ | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 				$this->setTitle($header,$desc,"header"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 			if(isset($items)===true){ | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 				$this->addList($items); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 		}else{ | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 			$this->setContent($content); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	public function addList($items=array()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		$list=new HtmlList("", $items); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		$list->setClass("list"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		$this->content["list"]=$list; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		return $list; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	public function getList(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		return $this->content["list"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	public function getItem($index){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		return $this->getList()->getItem($index); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 59 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 60 |  |  | } | 
            
                        
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.