Code Duplication    Length = 9-17 lines in 2 locations

includes/api/ApiQueryBase.php 2 locations

@@ 546-562 (lines=17) @@
543
	 * @param int $namespace Namespace of the title
544
	 * @return string DBkey (no namespace prefix)
545
	 */
546
	public function titlePartToKey( $titlePart, $namespace = NS_MAIN ) {
547
		$t = Title::makeTitleSafe( $namespace, $titlePart . 'x' );
548
		if ( !$t || $t->hasFragment() ) {
549
			// Invalid title (e.g. bad chars) or contained a '#'.
550
			$this->dieUsageMsg( [ 'invalidtitle', $titlePart ] );
551
		}
552
		if ( $namespace != $t->getNamespace() || $t->isExternal() ) {
553
			// This can happen in two cases. First, if you call titlePartToKey with a title part
554
			// that looks like a namespace, but with $defaultNamespace = NS_MAIN. It would be very
555
			// difficult to handle such a case. Such cases cannot exist and are therefore treated
556
			// as invalid user input. The second case is when somebody specifies a title interwiki
557
			// prefix.
558
			$this->dieUsageMsg( [ 'invalidtitle', $titlePart ] );
559
		}
560
561
		return substr( $t->getDBkey(), 0, -1 );
562
	}
563
564
	/**
565
	 * Convert an input title or title prefix into a namespace constant and dbkey.
@@ 572-580 (lines=9) @@
569
	 * @param int $defaultNamespace Default namespace if none is given
570
	 * @return array (int, string) Namespace number and DBkey
571
	 */
572
	public function prefixedTitlePartToKey( $titlePart, $defaultNamespace = NS_MAIN ) {
573
		$t = Title::newFromText( $titlePart . 'x', $defaultNamespace );
574
		if ( !$t || $t->hasFragment() || $t->isExternal() ) {
575
			// Invalid title (e.g. bad chars) or contained a '#'.
576
			$this->dieUsageMsg( [ 'invalidtitle', $titlePart ] );
577
		}
578
579
		return [ $t->getNamespace(), substr( $t->getDBkey(), 0, -1 ) ];
580
	}
581
582
	/**
583
	 * @param string $hash