Skip to content

Commit

Permalink
Strict types
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Jul 7, 2020
1 parent 5dd3673 commit 44a2086
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 79 deletions.
4 changes: 2 additions & 2 deletions src/Config/Degree.php
Expand Up @@ -45,7 +45,7 @@ public function getRules(): array
// radian
'r' => [
'symbol' => 'pi',
'rate' => function (float $value, string $ruleTo): float {
'rate' => static function (float $value, string $ruleTo): float {
if ($ruleTo === 'd') {
return $value * 180;
}
Expand All @@ -56,7 +56,7 @@ public function getRules(): array
// grads
'g' => [
'symbol' => 'Grad',
'rate' => function (float $value, string $ruleTo): float {
'rate' => static function (float $value, string $ruleTo): float {
if ($ruleTo === 'd') {
return $value * 0.9;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Info.php
Expand Up @@ -81,7 +81,7 @@ public function getRules(): array

'bit' => [
'symbol' => 'Bit',
'rate' => function (int $value, string $ruleTo) {
'rate' => static function (int $value, string $ruleTo) {

if ($ruleTo === 'bit') {
return $value * 8;
Expand Down
8 changes: 4 additions & 4 deletions src/Config/Temp.php
Expand Up @@ -41,7 +41,7 @@ public function getRules(): array
// Celsius
'C' => [
'symbol' => '°C',
'rate' => function (float $value, string $ruleTo): float {
'rate' => static function (float $value, string $ruleTo): float {
if ($ruleTo === 'k') {
$value += 273.15;
} else {
Expand All @@ -55,7 +55,7 @@ public function getRules(): array
// Fahrenheit
'F' => [
'symbol' => '°F',
'rate' => function (float $value, string $ruleTo): float {
'rate' => static function (float $value, string $ruleTo): float {
if ($ruleTo === 'k') {
$value = ($value + 459.67) * (5 / 9);
} else {
Expand All @@ -69,7 +69,7 @@ public function getRules(): array
// Rankine
'R' => [
'symbol' => '°R',
'rate' => function (float $value, string $ruleTo): float {
'rate' => static function (float $value, string $ruleTo): float {
if ($ruleTo === 'k') {
$value = $value * 5 / 9;
} else {
Expand All @@ -83,7 +83,7 @@ public function getRules(): array
// Kelvin
'K' => [
'symbol' => 'K',
'rate' => function (float $value): float {
'rate' => static function (float $value): float {
return $value;
},
],
Expand Down
15 changes: 7 additions & 8 deletions src/Formatter.php
Expand Up @@ -82,7 +82,8 @@ public function getList(bool $keysOnly = false): array
{
if ($keysOnly) {
$keys = array_keys($this->rules);
return array_combine($keys, $keys) ?: [];
$values = array_keys($this->rules);
return array_combine($keys, $values) ?: [];
}

return $this->rules;
Expand Down Expand Up @@ -117,7 +118,7 @@ public function text(float $value, string $rule, bool $showSymbol = true): strin
* @param array $params
* @return string
*/
public function html($current, $orig, $params): string
public function html(array $current, array $orig, array $params): string
{
$data = $this->format($current['value'], $current['rule']);
$rData = $this->get($current['rule']);
Expand All @@ -131,7 +132,7 @@ public function html($current, $orig, $params): string
$data['template']
);

return '<span ' . $this->htmlAttributes([
return '<span ' . self::htmlAttributes([
'class' => [
'simpleType',
'simpleType-block',
Expand All @@ -151,13 +152,13 @@ public function html($current, $orig, $params): string
* @param array $params
* @return string
*/
public function htmlInput($current, $orig, $params): string
public function htmlInput(array $current, array $orig, array $params): string
{
$inputValue = $params['formatted']
? $this->text($current['value'], $current['rule'])
: $this->text($current['value'], $current['rule'], false);

return '<input ' . $this->htmlAttributes([
return '<input ' . self::htmlAttributes([
'value' => $inputValue,
'name' => $params['name'],
'type' => 'text',
Expand All @@ -178,12 +179,10 @@ public function htmlInput($current, $orig, $params): string
* @param array $attributes
* @return string
*/
public function htmlAttributes($attributes): string
public static function htmlAttributes(array $attributes): string
{
$result = '';

$attributes = (array)$attributes;

if (count($attributes)) {
foreach ($attributes as $key => $param) {
$value = implode(' ', (array)$param);
Expand Down
12 changes: 6 additions & 6 deletions src/Parser.php
Expand Up @@ -42,7 +42,7 @@ public function __construct(string $default = '', array $ruleList = [])
* @param string $item2
* @return int
*/
$sortFunction = function (string $item1, string $item2): int {
$sortFunction = static function (string $item1, string $item2): int {
return strlen($item2) - strlen($item1);
};

Expand Down Expand Up @@ -78,7 +78,7 @@ public function parse($data = null, ?string $forceRule = null): array
}
}

$value = $this->cleanValue((string)$value);
$value = self::cleanValue((string)$value);
$rule = $this->checkRule($rule);

if ($forceRule) {
Expand All @@ -100,7 +100,7 @@ public function getCodeList(): array
* @param string|float|int|null $value
* @return float
*/
public function cleanValue($value): float
public static function cleanValue($value): float
{
$result = trim((string)$value);

Expand All @@ -120,7 +120,7 @@ public function cleanValue($value): float
* @param string|null $rule
* @return string
*/
public function cleanRule(?string $rule): string
public static function cleanRule(?string $rule): string
{
return strtolower(trim((string)$rule));
}
Expand All @@ -129,9 +129,9 @@ public function cleanRule(?string $rule): string
* @param string|null $rule
* @return string
*/
public function checkRule(?string $rule)
public function checkRule(?string $rule): string
{
$rule = $this->cleanRule($rule);
$rule = self::cleanRule($rule);

if (!$rule) {
return $this->default;
Expand Down

0 comments on commit 44a2086

Please sign in to comment.