Skip to content

Commit

Permalink
style(types): Add php typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Jun 8, 2019
1 parent 0e5cb09 commit 53f38f7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 59 deletions.
56 changes: 28 additions & 28 deletions src/plugins/BasePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,44 @@ abstract public function gettext(string $msgId): string;
/**
* Get translation for a message id
*
* @param mixed $msgId Message id
* @param string $msgId Message id
* @return string
*/
abstract public function __($msgId): string;
abstract public function __(string $msgId): string;

/**
* Get translation
*
* @param mixed $domain Domain
* @param mixed $msgctxt msgctxt
* @param mixed $msgId Message id
* @param mixed $msgIdPlural Plural message id
* @param mixed $number Number
* @param string $domain Domain
* @param string $msgctxt msgctxt
* @param string $msgId Message id
* @param string $msgIdPlural Plural message id
* @param int $number Number
* @return string
*/
abstract public function dnpgettext($domain, $msgctxt, $msgId, $msgIdPlural, $number): string;
abstract public function dnpgettext(string $domain, string $msgctxt, string $msgId, string $msgIdPlural, int $number): string;

/**
* Get translation
*
* @param mixed $domain Domain
* @param mixed $msgId Message id
* @param mixed $msgIdPlural Plural message id
* @param mixed $number Number
* @param string $domain Domain
* @param string $msgId Message id
* @param string $msgIdPlural Plural message id
* @param int $number Number
* @return string
*/
abstract public function dngettext($domain, $msgId, $msgIdPlural, $number): string;
abstract public function dngettext(string $domain, string $msgId, string $msgIdPlural, int $number): string;

/**
* Get translation
*
* @param mixed $msgctxt msgctxt
* @param mixed $msgId Message id
* @param mixed $msgIdPlural Plural message id
* @param mixed $number Number
* @param string $msgctxt msgctxt
* @param string $msgId Message id
* @param string $msgIdPlural Plural message id
* @param int $number Number
* @return string
*/
abstract public function npgettext($msgctxt, $msgId, $msgIdPlural, $number): string;
abstract public function npgettext(string $msgctxt, string $msgId, string $msgIdPlural, int $number): string;

/**
* Plural version of gettext
Expand All @@ -83,29 +83,29 @@ abstract public function ngettext(string $msgId, string $msgIdPlural, int $numbe
/**
* Get translation
*
* @param mixed $domain Domain
* @param mixed $msgctxt msgctxt
* @param mixed $msgId Message id
* @param string $domain Domain
* @param string $msgctxt msgctxt
* @param string $msgId Message id
* @return string
*/
abstract public function dpgettext($domain, $msgctxt, $msgId): string;
abstract public function dpgettext(string $domain, string $msgctxt, string $msgId): string;

/**
* Get translation
*
* @param mixed $domain Domain
* @param mixed $msgId Message id
* @param string $domain Domain
* @param string $msgId Message id
* @return string
*/
abstract public function dgettext($domain, $msgId): string;
abstract public function dgettext(string $domain, string $msgId): string;

/**
* Get translation
*
* @param mixed $msgctxt msgctxt
* @param mixed $msgId Message id
* @param string $msgctxt msgctxt
* @param string $msgId Message id
* @return string
*/
abstract public function pgettext($msgctxt, $msgId): string;
abstract public function pgettext(string $msgctxt, string $msgId): string;

}
66 changes: 35 additions & 31 deletions src/plugins/MoReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ public static function readInteger(int $endian, $res)
/**
* Return string id or translation
*
* @param mixed $msgId The message id
* @param string $msgId The message id
* @return string
*/
public function idOrFind($msgId): string
public function idOrFind(string $msgId): string
{
if (array_key_exists($msgId, $this->data->translations)) {
return $this->data->translations[$msgId];
Expand All @@ -265,10 +265,10 @@ public function idOrFind($msgId): string
/**
* Get translation for a message id
*
* @param mixed $msgId Message id
* @param string $msgId Message id
* @return string
*/
public function __($msgId): string
public function __(string $msgId): string
{
return self::gettext($msgId);
}
Expand All @@ -287,44 +287,48 @@ public function gettext(string $msgId): string
/**
* Get translation
*
* @param mixed $domain Domain
* @param mixed $msgctxt msgctxt
* @param mixed $msgId Message id
* @param mixed $msgIdPlural Plural message id
* @param mixed $number Number
* @param string $domain Domain
* @param string $msgctxt msgctxt
* @param string $msgId Message id
* @param string $msgIdPlural Plural message id
* @param int $number Number
* @return string
*/
public function dnpgettext($domain, $msgctxt, $msgId, $msgIdPlural, $number): string
public function dnpgettext(string $domain, string $msgctxt, string $msgId, string $msgIdPlural, int $number): string
{
return self::idOrFind($msgId);
}

/**
* Get translation
*
* @param mixed $domain Domain
* @param mixed $msgId Message id
* @param mixed $msgIdPlural Plural message id
* @param mixed $number Number
* @param string $domain Domain
* @param string $msgId Message id
* @param string $msgIdPlural Plural message id
* @param int $number Number
* @return string
*/
public function dngettext($domain, $msgId, $msgIdPlural, $number): string
public function dngettext(string $domain, string $msgId, string $msgIdPlural, int $number): string
{
return self::idOrFind($msgId);
}

/**
* Get translation
*
* @param mixed $msgctxt msgctxt
* @param mixed $msgId Message id
* @param mixed $msgIdPlural Plural message id
* @param mixed $number Number
* @param string $msgctxt msgctxt
* @param string $msgId Message id
* @param string $msgIdPlural Plural message id
* @param int $number Number
* @return string
*/
public function npgettext($msgctxt, $msgId, $msgIdPlural, $number): string
public function npgettext(string $msgctxt, string $msgId, string $msgIdPlural, int $number): string
{
return self::idOrFind($msgId);
if ($number > 1) {
return self::idOrFind($msgIdPlural);
} else {
return self::idOrFind($msgId);
}
}

/**
Expand All @@ -347,36 +351,36 @@ public function ngettext(string $msgId, string $msgIdPlural, int $number): strin
/**
* Get translation
*
* @param mixed $domain Domain
* @param mixed $msgctxt msgctxt
* @param mixed $msgId Message id
* @param string $domain Domain
* @param string $msgctxt msgctxt
* @param string $msgId Message id
* @return string
*/
public function dpgettext($domain, $msgctxt, $msgId): string
public function dpgettext(string $domain, string $msgctxt, string $msgId): string
{
return self::idOrFind($msgId);
}

/**
* Get translation
*
* @param mixed $domain Domain
* @param mixed $msgId Message id
* @param string $domain Domain
* @param string $msgId Message id
* @return string
*/
public function dgettext($domain, $msgId): string
public function dgettext(string $domain, string $msgId): string
{
return self::idOrFind($msgId);
}

/**
* Get translation
*
* @param mixed $msgctxt msgctxt
* @param mixed $msgId Message id
* @param string $msgctxt msgctxt
* @param string $msgId Message id
* @return string
*/
public function pgettext($msgctxt, $msgId): string
public function pgettext(string $msgctxt, string $msgId): string
{
return self::idOrFind($msgId);
}
Expand Down

0 comments on commit 53f38f7

Please sign in to comment.