Skip to content

Commit 44a2086

Browse files
committed
Strict types
1 parent 5dd3673 commit 44a2086

17 files changed

Lines changed: 81 additions & 79 deletions

src/Config/Degree.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getRules(): array
4545
// radian
4646
'r' => [
4747
'symbol' => 'pi',
48-
'rate' => function (float $value, string $ruleTo): float {
48+
'rate' => static function (float $value, string $ruleTo): float {
4949
if ($ruleTo === 'd') {
5050
return $value * 180;
5151
}
@@ -56,7 +56,7 @@ public function getRules(): array
5656
// grads
5757
'g' => [
5858
'symbol' => 'Grad',
59-
'rate' => function (float $value, string $ruleTo): float {
59+
'rate' => static function (float $value, string $ruleTo): float {
6060
if ($ruleTo === 'd') {
6161
return $value * 0.9;
6262
}

src/Config/Info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getRules(): array
8181

8282
'bit' => [
8383
'symbol' => 'Bit',
84-
'rate' => function (int $value, string $ruleTo) {
84+
'rate' => static function (int $value, string $ruleTo) {
8585

8686
if ($ruleTo === 'bit') {
8787
return $value * 8;

src/Config/Temp.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getRules(): array
4141
// Celsius
4242
'C' => [
4343
'symbol' => '°C',
44-
'rate' => function (float $value, string $ruleTo): float {
44+
'rate' => static function (float $value, string $ruleTo): float {
4545
if ($ruleTo === 'k') {
4646
$value += 273.15;
4747
} else {
@@ -55,7 +55,7 @@ public function getRules(): array
5555
// Fahrenheit
5656
'F' => [
5757
'symbol' => '°F',
58-
'rate' => function (float $value, string $ruleTo): float {
58+
'rate' => static function (float $value, string $ruleTo): float {
5959
if ($ruleTo === 'k') {
6060
$value = ($value + 459.67) * (5 / 9);
6161
} else {
@@ -69,7 +69,7 @@ public function getRules(): array
6969
// Rankine
7070
'R' => [
7171
'symbol' => '°R',
72-
'rate' => function (float $value, string $ruleTo): float {
72+
'rate' => static function (float $value, string $ruleTo): float {
7373
if ($ruleTo === 'k') {
7474
$value = $value * 5 / 9;
7575
} else {
@@ -83,7 +83,7 @@ public function getRules(): array
8383
// Kelvin
8484
'K' => [
8585
'symbol' => 'K',
86-
'rate' => function (float $value): float {
86+
'rate' => static function (float $value): float {
8787
return $value;
8888
},
8989
],

src/Formatter.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public function getList(bool $keysOnly = false): array
8282
{
8383
if ($keysOnly) {
8484
$keys = array_keys($this->rules);
85-
return array_combine($keys, $keys) ?: [];
85+
$values = array_keys($this->rules);
86+
return array_combine($keys, $values) ?: [];
8687
}
8788

8889
return $this->rules;
@@ -117,7 +118,7 @@ public function text(float $value, string $rule, bool $showSymbol = true): strin
117118
* @param array $params
118119
* @return string
119120
*/
120-
public function html($current, $orig, $params): string
121+
public function html(array $current, array $orig, array $params): string
121122
{
122123
$data = $this->format($current['value'], $current['rule']);
123124
$rData = $this->get($current['rule']);
@@ -131,7 +132,7 @@ public function html($current, $orig, $params): string
131132
$data['template']
132133
);
133134

134-
return '<span ' . $this->htmlAttributes([
135+
return '<span ' . self::htmlAttributes([
135136
'class' => [
136137
'simpleType',
137138
'simpleType-block',
@@ -151,13 +152,13 @@ public function html($current, $orig, $params): string
151152
* @param array $params
152153
* @return string
153154
*/
154-
public function htmlInput($current, $orig, $params): string
155+
public function htmlInput(array $current, array $orig, array $params): string
155156
{
156157
$inputValue = $params['formatted']
157158
? $this->text($current['value'], $current['rule'])
158159
: $this->text($current['value'], $current['rule'], false);
159160

160-
return '<input ' . $this->htmlAttributes([
161+
return '<input ' . self::htmlAttributes([
161162
'value' => $inputValue,
162163
'name' => $params['name'],
163164
'type' => 'text',
@@ -178,12 +179,10 @@ public function htmlInput($current, $orig, $params): string
178179
* @param array $attributes
179180
* @return string
180181
*/
181-
public function htmlAttributes($attributes): string
182+
public static function htmlAttributes(array $attributes): string
182183
{
183184
$result = '';
184185

185-
$attributes = (array)$attributes;
186-
187186
if (count($attributes)) {
188187
foreach ($attributes as $key => $param) {
189188
$value = implode(' ', (array)$param);

src/Parser.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(string $default = '', array $ruleList = [])
4242
* @param string $item2
4343
* @return int
4444
*/
45-
$sortFunction = function (string $item1, string $item2): int {
45+
$sortFunction = static function (string $item1, string $item2): int {
4646
return strlen($item2) - strlen($item1);
4747
};
4848

@@ -78,7 +78,7 @@ public function parse($data = null, ?string $forceRule = null): array
7878
}
7979
}
8080

81-
$value = $this->cleanValue((string)$value);
81+
$value = self::cleanValue((string)$value);
8282
$rule = $this->checkRule($rule);
8383

8484
if ($forceRule) {
@@ -100,7 +100,7 @@ public function getCodeList(): array
100100
* @param string|float|int|null $value
101101
* @return float
102102
*/
103-
public function cleanValue($value): float
103+
public static function cleanValue($value): float
104104
{
105105
$result = trim((string)$value);
106106

@@ -120,7 +120,7 @@ public function cleanValue($value): float
120120
* @param string|null $rule
121121
* @return string
122122
*/
123-
public function cleanRule(?string $rule): string
123+
public static function cleanRule(?string $rule): string
124124
{
125125
return strtolower(trim((string)$rule));
126126
}
@@ -129,9 +129,9 @@ public function cleanRule(?string $rule): string
129129
* @param string|null $rule
130130
* @return string
131131
*/
132-
public function checkRule(?string $rule)
132+
public function checkRule(?string $rule): string
133133
{
134-
$rule = $this->cleanRule($rule);
134+
$rule = self::cleanRule($rule);
135135

136136
if (!$rule) {
137137
return $this->default;

0 commit comments

Comments
 (0)