Skip to content

Commit bb5029b

Browse files
committed
PHP CS
1 parent c2eda3f commit bb5029b

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

src/Filter.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,12 @@ public static function className($input)
410410
*/
411411
public static function stripQuotes($value)
412412
{
413-
if (($value[0] === '"' && substr($value, -1) === '"') ||
414-
($value[0] === "'" && substr($value, -1) === "'")
415-
) {
416-
return substr($value, 1, -1);
413+
if ($value[0] === '"' && substr($value, -1) === '"') {
414+
$value = trim($value, '"');
415+
}
416+
417+
if ($value[0] === "'" && substr($value, -1) === "'") {
418+
$value = trim($value, "'");
417419
}
418420

419421
return $value;

src/Vars.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,21 @@ public static function out($number, $min, $max)
245245
/**
246246
* Get relative percent
247247
*
248-
* @param float $current
249248
* @param float $normal
249+
* @param float $current
250250
* @return string
251251
*/
252-
public static function relativePercent($current, $normal)
252+
public static function relativePercent($normal, $current)
253253
{
254-
$current = (float)$current;
255254
$normal = (float)$normal;
255+
$current = (float)$current;
256256

257-
if (!$current) {
258-
return '~';
257+
if (!$normal || $normal == $current) {
258+
return '100';
259259

260260
} else {
261-
$current = abs($current);
262-
$percent = round($normal / $current * 100);
261+
$normal = abs($normal);
262+
$percent = round($current / $normal * 100);
263263

264264
return number_format($percent, 0, '.', ' ');
265265
}

tests/FilterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,20 @@ public function testClassname()
331331
isSame('Class123Name456', Filter::className('CLASS123NAME456'));
332332
isSame('Classname', Filter::className('CLASSNAME'));
333333
}
334+
335+
public function tstStripQuotes()
336+
{
337+
isSame('qwerty', Filter::stripQuotes('qwerty'));
338+
isSame('qwerty"', Filter::stripQuotes('qwerty"'));
339+
isSame('"qwerty', Filter::stripQuotes('"qwerty'));
340+
isSame('"qwerty"', Filter::stripQuotes('"qwerty"'));
341+
342+
isSame("qwerty", Filter::stripQuotes('qwerty'));
343+
isSame("qwerty'", Filter::stripQuotes('qwerty\''));
344+
isSame("'qwerty", Filter::stripQuotes('\'qwerty'));
345+
isSame("'qwerty'", Filter::stripQuotes('\'qwerty\''));
346+
347+
isSame("'qwerty\"", Filter::stripQuotes('\'qwerty"'));
348+
isSame("\"qwerty'", Filter::stripQuotes('"qwerty\''));
349+
}
334350
}

tests/VarsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,6 @@ public function testRelativePercent()
157157
isSame('100', Vars::relativePercent(100, 100));
158158
isSame('10 000', Vars::relativePercent(1, 100));
159159
isSame('1', Vars::relativePercent(100, 1));
160-
isSame('~', Vars::relativePercent(0, 1));
160+
isSame('100', Vars::relativePercent(0, 1));
161161
}
162162
}

0 commit comments

Comments
 (0)