Skip to content

Commit

Permalink
Add type declarations to PhpMyAdmin\Advisor
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
  • Loading branch information
MauricioFauth committed Apr 13, 2018
1 parent d350fab commit 0acf5ac
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions libraries/classes/Advisor.php
Expand Up @@ -128,7 +128,7 @@ public function getVariables()
*
* @return Advisor
*/
public function setVariables(array $variables)
public function setVariables(array $variables): self
{
$this->variables = $variables;

Expand All @@ -143,7 +143,7 @@ public function setVariables(array $variables)
*
* @return $this
*/
public function setVariable($variable, $value)
public function setVariable($variable, $value): self
{
$this->variables[$variable] = $value;

Expand All @@ -167,7 +167,7 @@ public function getParseResult()
*
* @return Advisor
*/
public function setParseResult(array $parseResult)
public function setParseResult(array $parseResult): self
{
$this->parseResult = $parseResult;

Expand All @@ -191,7 +191,7 @@ public function getRunResult()
*
* @return Advisor
*/
public function setRunResult(array $runResult)
public function setRunResult(array $runResult): self
{
$this->runResult = $runResult;

Expand All @@ -203,7 +203,7 @@ public function setRunResult(array $runResult)
*
* @return array with run and parse results
*/
public function run()
public function run(): array
{
// HowTo: A simple Advisory system in 3 easy steps.

Expand Down Expand Up @@ -236,12 +236,12 @@ public function run()
/**
* Stores current error in run results.
*
* @param string $description description of an error.
* @param Exception $exception exception raised
* @param string $description description of an error.
* @param \Throwable $exception exception raised
*
* @return void
*/
public function storeError($description, $exception)
public function storeError(string $description, \Throwable $exception): void
{
$this->runResult['errors'][] = $description
. ' '
Expand All @@ -256,7 +256,7 @@ public function storeError($description, $exception)
*
* @return boolean
*/
public function runRules()
public function runRules(): bool
{
$this->setRunResult(
array(
Expand Down Expand Up @@ -332,7 +332,7 @@ public function runRules()
*
* @return string
*/
public static function escapePercent($str)
public static function escapePercent(string $str): string
{
return preg_replace('/%( |,|\.|$|\(|\)|<|>)/', '%%\1', $str);
}
Expand All @@ -345,7 +345,7 @@ public static function escapePercent($str)
*
* @return string
*/
public function translate($str, $param = null)
public function translate(string $str, ?string $param = null): string
{
$string = _gettext(self::escapePercent($str));
if (! is_null($param)) {
Expand All @@ -363,7 +363,7 @@ public function translate($str, $param = null)
*
* @return string[]
*/
public static function splitJustification(array $rule)
public static function splitJustification(array $rule): array
{
$jst = preg_split('/\s*\|\s*/', $rule['justification'], 2);
if (count($jst) > 1) {
Expand All @@ -380,7 +380,7 @@ public static function splitJustification(array $rule)
*
* @return void
*/
public function addRule($type, array $rule)
public function addRule(string $type, array $rule): void
{
switch ($type) {
case 'notfired':
Expand Down Expand Up @@ -436,7 +436,7 @@ public function addRule($type, array $rule)
*
* @return string Replacement value
*/
private function replaceLinkURL(array $matches)
private function replaceLinkURL(array $matches): string
{
return 'href="' . Core::linkURL($matches[2]) . '" target="_blank" rel="noopener noreferrer"';
}
Expand All @@ -448,7 +448,7 @@ private function replaceLinkURL(array $matches)
*
* @return string Replacement value
*/
private function replaceVariable(array $matches)
private function replaceVariable(array $matches): string
{
return '<a href="server_variables.php' . Url::getCommon(array('filter' => $matches[1]))
. '">' . htmlspecialchars($matches[1]) . '</a>';
Expand All @@ -460,11 +460,11 @@ private function replaceVariable(array $matches)
*
* @param string $expr expression to evaluate
*
* @return integer result of evaluated expression
* @return mixed result of evaluated expression
*
* @throws Exception
*/
public function ruleExprEvaluate($expr)
public function ruleExprEvaluate(string $expr)
{
// Actually evaluate the code
// This can throw exception
Expand All @@ -482,7 +482,7 @@ public function ruleExprEvaluate($expr)
*
* @return array with parsed data
*/
public static function parseRulesFile()
public static function parseRulesFile(): array
{
$filename = 'libraries/advisory_rules.txt';
$file = file($filename, FILE_IGNORE_NEW_LINES);
Expand Down Expand Up @@ -587,12 +587,12 @@ public static function parseRulesFile()
/**
* Formats interval like 10 per hour
*
* @param integer $num number to format
* @param float $num number to format
* @param integer $precision required precision
*
* @return string formatted string
*/
public static function byTime($num, $precision)
public static function byTime(float $num, int $precision): string
{
if ($num >= 1) { // per second
$per = __('per second');
Expand Down Expand Up @@ -625,7 +625,7 @@ public static function byTime($num, $precision)
*
* @return string the formatted value
*/
public static function timespanFormat($seconds)
public static function timespanFormat(int $seconds): string
{
return Util::timespanFormat($seconds);
}
Expand All @@ -641,7 +641,7 @@ public static function timespanFormat($seconds)
*
* @return string the formatted value with unit
*/
public static function formatByteDown($value, $limes = 6, $comma = 0)
public static function formatByteDown(float $value, int $limes = 6, int $comma = 0): string
{
return implode(' ', Util::formatByteDown($value, $limes, $comma));
}
Expand Down

0 comments on commit 0acf5ac

Please sign in to comment.