| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Radio checkbox fields. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | class HTMLRadioField extends HTMLFormField { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 	function validate( $value, $alldata ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 		$p = parent::validate( $value, $alldata ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 		if ( $p !== true ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 			return $p; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 		if ( !is_string( $value ) && !is_int( $value ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 			return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		$validOptions = HTMLFormField::flattenOptions( $this->getOptions() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 20 |  | View Code Duplication | 		if ( in_array( strval( $value ), $validOptions, true ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 			return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 			return $this->msg( 'htmlform-select-badoption' )->parse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * This returns a block of all the radio options, in one cell. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * @see includes/HTMLFormField#getInputHTML() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	 * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 34 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 	function getInputHTML( $value ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 		$html = $this->formatOptions( $this->getOptions(), strval( $value ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 		return $html; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	function getInputOOUI( $value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		$options = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		foreach ( $this->getOptions() as $label => $data ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			$options[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 				'data' => $data, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 				'label' => $this->mOptionsLabelsNotFromMessage ? new OOUI\HtmlSnippet( $label ) : $label, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		return new OOUI\RadioSelectInputWidget( [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			'name' => $this->mName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			'id' => $this->mID, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			'value' => $value, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			'options' => $options, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		] + OOUI\Element::configFromHtmlAttributes( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			$this->getAttributes( [ 'disabled', 'tabindex' ] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	protected function shouldInfuseOOUI() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	function formatOptions( $options, $value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		global $wgUseMediaWikiUIEverywhere; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$html = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$attribs = $this->getAttributes( [ 'disabled', 'tabindex' ] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$elementFunc = [ 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		# @todo Should this produce an unordered list perhaps? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		foreach ( $options as $label => $info ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			if ( is_array( $info ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 				$html .= Html::rawElement( 'h1', [], $label ) . "\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 				$html .= $this->formatOptions( $info, $value ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 				$id = Sanitizer::escapeId( $this->mID . "-$info" ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 				$classes = [ 'mw-htmlform-flatlist-item' ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 				if ( $wgUseMediaWikiUIEverywhere || $this->mParent instanceof VFormHTMLForm ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 					$classes[] = 'mw-ui-radio'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 				$radio = Xml::radio( $this->mName, $info, $info === $value, $attribs + [ 'id' => $id ] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 				$radio .= ' ' . call_user_func( $elementFunc, 'label', [ 'for' => $id ], $label ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 				$html .= ' ' . Html::rawElement( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 					'div', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 					[ 'class' => $classes ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 					$radio | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 				); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		return $html; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	protected function needsLabel() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 101 |  |  |  | 
            
                        
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.