| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SRF\Outline; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SMW\Query\PrintRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SRF\Outline\OutlineTree; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SMWDataItem as DataItem; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @license GNU GPL v2+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @since 3.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author mwjames | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | class ListTreeBuilder { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	 * @var [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	private $params = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	 * @var Linker | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	private $linker; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * @param array $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 3 |  | 	public function __construct( array $params ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 3 |  | 		$this->params = $params; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 3 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	 * @since 3.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	 * @param Linker|null|false $linker | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 1 |  | 	public function setLinker( $linker ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 1 |  | 		$this->linker = $linker; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 1 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	 * @since 3.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 * @param OutlineTree $tree | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 2 |  | 	public function build( OutlineTree $outlineTree ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 2 |  | 		return $this->tree( $outlineTree ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 2 |  | 	private function tree( $outline_tree, $level = 0 ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 | 2 |  | 		$text = ""; | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 2 |  | 		if ( !is_null( $outline_tree->items ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 | 2 |  | 			$text .= "<ul>\n"; | 
            
                                                                        
                            
            
                                    
            
            
                | 59 | 2 |  | 			foreach ( $outline_tree->items as $item ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 60 | 1 |  | 				$text .= "<li>{$this->item($item)}</li>\n"; | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 62 | 2 |  | 			$text .= "</ul>\n"; | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 65 | 2 |  | 		if ( $level > 0 ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 66 | 1 |  | 			$text .= "<ul>\n"; | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 69 | 2 |  | 		$num_levels = count( $this->params['outlineproperties'] ); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  | 		// set font size and weight depending on level we're at | 
            
                                                                        
                            
            
                                    
            
            
                | 71 | 2 |  | 		$font_level = $level; | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 73 | 2 |  | 		if ( $num_levels < 4 ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 74 | 2 |  | 			$font_level += ( 4 - $num_levels ); | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 77 | 2 |  | 		if ( $font_level == 0 ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  | 			$font_size = 'x-large'; | 
            
                                                                        
                            
            
                                    
            
            
                | 79 | 2 |  | 		} elseif ( $font_level == 1 ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  | 			$font_size = 'large'; | 
            
                                                                        
                            
            
                                    
            
            
                | 81 | 2 |  | 		} elseif ( $font_level == 2 ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 82 | 1 |  | 			$font_size = 'medium'; | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  | 		} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 84 | 2 |  | 			$font_size = 'small'; | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 87 | 2 |  | 		if ( $font_level == 3 ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 88 | 2 |  | 			$font_weight = 'bold'; | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  | 		} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 90 | 1 |  | 			$font_weight = 'regular'; | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 93 | 2 |  | 		foreach ( $outline_tree->tree as $key => $node ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 94 | 1 |  | 			$text .= "<p style=\"font-size: $font_size; font-weight: $font_weight;\">$key</p>\n"; | 
            
                                                                        
                            
            
                                    
            
            
                | 95 | 1 |  | 			$text .= $this->tree( $node, $level + 1 ); | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 98 | 2 |  | 		if ( $level > 0 ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 99 | 1 |  | 			$text .= "</ul>\n"; | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 102 | 2 |  | 		return $text; | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 1 |  | 	private function item( $item ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 1 |  | 		$first_col = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 1 |  | 		$found_values = false; // has anything but the first column been printed? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 1 |  | 		$result = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 1 |  | 		foreach ( $item->row as $resultArray ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 1 |  | 			$printRequest = $resultArray->getPrintRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 1 |  | 			$val = $printRequest->getText( SMW_OUTPUT_WIKI, null ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 1 |  | 			$first_value = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 1 |  | 			if ( in_array( $val, $this->params['outlineproperties'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 1 |  | 				continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 1 |  | 			$linker = $this->params['link'] === 'all' ? $this->linker : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 1 |  | 			if ( $this->params['link'] === 'subject' && $printRequest->isMode( PrintRequest::PRINT_THIS ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 				$linker = $this->linker; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 1 |  | 			while ( ( $dv = $resultArray->getNextDataValue() ) !== false ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 1 |  | 				if ( !$first_col && !$found_values ) { // first values after first column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 1 |  | 					$result .= ' ('; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 | 1 |  | 					$found_values = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 | 1 |  | 				} elseif ( $found_values || !$first_value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 					// any value after '(' or non-first values on first column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 					$result .= ', '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 1 |  | 				if ( $first_value ) { // first value in any column, print header | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 | 1 |  | 					$first_value = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 | 1 |  | 					if ( $this->params['showHeaders'] && ( '' != $printRequest->getLabel() ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 | 1 |  | 						$result .= $printRequest->getText( SMW_OUTPUT_WIKI, $linker ) . ' '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 1 |  | 				$dataItem = $dv->getDataItem(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 1 |  | 				if ( $linker === null && $dataItem->getDIType() === DataItem::TYPE_WIKIPAGE && ( $caption = $dv->getDisplayTitle() ) !== '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 					$dv->setCaption( $caption ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 | 1 |  | 				$result .= $dv->getShortText( SMW_OUTPUT_WIKI, $linker ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 | 1 |  | 			$first_col = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 1 |  | 		if ( $found_values ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 | 1 |  | 			$result .= ')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 | 1 |  | 		return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 162 |  |  | } | 
            
                        
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.