Skip to content

Commit

Permalink
Merge "Use PHP type hints"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Sep 16, 2024
2 parents e39981d + c756e2a commit 1c2800b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/Realnames.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ class Realnames implements
* @var array
* @since 2011-09-16, 0.1
*/
protected static $realnames = [];
protected static array $realnames = [];

/**
* namespace regex option string.
*
* @var string|null
* @since 2011-09-16, 0.2
*/
protected static $namespacePrefixes = null;
protected static ?string $namespacePrefixes = null;

/**
* namespace regex option string urlencoded.
*
* @var string|null
* @since 2019-03-10, 0.6
*/
protected static $namespacePrefixesEncoded = null;
protected static ?string $namespacePrefixesEncoded = null;

private Config $config;
private Language $lang;
Expand All @@ -89,7 +89,7 @@ public function __construct(
* @since 2011-09-16, 0.1
* @see lookForBare() for regex
*/
protected function checkBare( $matches ) {
protected function checkBare( array $matches ): string {
// matches come from self::lookForBare()'s regular expression
$m = [
'all' => $matches[0],
Expand All @@ -114,7 +114,7 @@ protected function checkBare( $matches ) {
* @since 2011-09-16, 0.1
* @see lookForBare() for regex
*/
protected function checkLink( $matches ) {
protected function checkLink( array $matches ): string {
// matches come from self::lookForLinks()'s regular expression
$m = [
'all' => $matches[0],
Expand Down Expand Up @@ -148,7 +148,7 @@ protected function checkLink( $matches ) {
*
* @since 2019-01-24, 0.3.2
*/
protected static function debug( $method, $text ) {
protected static function debug( string $method, string $text ): void {
wfDebugLog( 'realnames', $method . ': ' . $text );
}

Expand All @@ -169,7 +169,7 @@ protected static function debug( $method, $text ) {
* @see $wgRealnamesStyles
* @see $wgRealnamesBlank
*/
protected function display( $m ) {
protected function display( array $m ): string {
// what kind of formatting will we do?
$style = $this->config->get( 'RealnamesLinkStyle' );
$styleBlankName = $this->config->get( 'RealnamesLinkStyleBlankName' );
Expand Down Expand Up @@ -245,7 +245,7 @@ protected function display( $m ) {
*
* @since 2011-09-22, 0.2
*/
public function getNamespacePrefixes( $encode = false ) {
public function getNamespacePrefixes( bool $encode = false ): string {
if ( $encode ) {
$prefixes = self::$namespacePrefixesEncoded;
} else {
Expand Down Expand Up @@ -366,7 +366,7 @@ public function onBeforePageDisplay( $out, $skin ): void {
* @param User $user
* @param array &$userPageOpt
*/
private function transformUsernameToRealname( User $user, &$userPageOpt ): void {
private function transformUsernameToRealname( User $user, array &$userPageOpt ): void {
// replace the name of the logged-in user
if ( isset( $userPageOpt )
&& isset( $userPageOpt['text'] ) ) {
Expand Down Expand Up @@ -425,7 +425,7 @@ public function onSkinTemplateNavigation__Universal( $skin, &$links ): void {
* we tend to just strip the User: and leave the username, but we only modify the
* first word so some weird style might screw it up (2011-09-17, ofb)
*/
protected function lookForBare( $text, $pattern = null ) {
protected function lookForBare( string $text, string $pattern = null ): string {
// considered doing [^<]+ here to catch names with spaces or underscores,
// which works for most titles but is not universal
$pattern ??= '/' . $this->getNamespacePrefixes() . '([^ \t]+)(\/.+)?/';
Expand Down Expand Up @@ -454,7 +454,7 @@ protected function lookForBare( $text, $pattern = null ) {
*
* @since 2011-09-16, 0.1
*/
protected function lookForLinks( $text, $pattern = null ) {
protected function lookForLinks( string $text, string $pattern = null ): string {
self::debug( __METHOD__, 'before: ' . $this->getNamespacePrefixes( false ) );
self::debug( __METHOD__, 'after: ' . $this->getNamespacePrefixes( true ) );
$pattern ??= '/(<a\b[^">]+href="[^">]+'
Expand Down Expand Up @@ -488,7 +488,7 @@ protected function lookForLinks( $text, $pattern = null ) {
*
* @since 2011-09-16, 0.1
*/
protected function replace( $m ) {
protected function replace( array $m ): string {
$debug_msg = 'matched '
. ( $m['username'] ?? print_r( $m, true ) );
self::debug( __METHOD__, $debug_msg );
Expand Down

0 comments on commit 1c2800b

Please sign in to comment.