Skip to content

Commit 8571ed5

Browse files
committed
Add Debugger::roundVersion method
1 parent 3ac9352 commit 8571ed5

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/Debugger.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,20 @@ public static function makeDebugValue(mixed $value) : string
185185
default => 'instanceof ' . $type,
186186
};
187187
}
188+
189+
/**
190+
* Remove dots and zeros from the end of the version.
191+
*
192+
* @param string $version
193+
*
194+
* @return string
195+
*/
196+
public static function roundVersion(string $version) : string
197+
{
198+
if (\str_ends_with($version, '.0')) {
199+
$version = \substr($version, 0, -2);
200+
return static::roundVersion($version);
201+
}
202+
return $version;
203+
}
188204
}

src/Views/debugbar/debugbar.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
use Framework\Debug\Debugger;
4+
25
/**
36
* @var array<string,Framework\Debug\Collection> $collections
47
* @var array<string,mixed> $activities
@@ -27,8 +30,12 @@
2730
</header>
2831
<div class="contents">
2932
<div class="collector-default">
30-
<p>Running<?= class_exists('Aplus') ? ' Aplus ' . Aplus::VERSION
31-
: '' ?> on <?= \PHP_OS_FAMILY ?> with PHP <?= \PHP_VERSION ?></p>
33+
<p>Running<?=
34+
class_exists('Aplus')
35+
? ' Aplus ' . Debugger::roundVersion(Aplus::VERSION)
36+
: '' ?> on <?= \PHP_OS_FAMILY ?> with PHP
37+
<?= Debugger::roundVersion(\PHP_VERSION) ?>
38+
</p>
3239
<p>★
3340
<a href="https://aplus-framework.com" target="_blank">aplus-framework.com</a>
3441
</p>

tests/DebuggerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,12 @@ public function testMakeDebugValue() : void
205205
self::assertSame("'\\'Ok'", Debugger::makeDebugValue("'Ok"));
206206
self::assertSame('instanceof stdClass', Debugger::makeDebugValue(new \stdClass()));
207207
}
208+
209+
public function testRoundVersion() : void
210+
{
211+
self::assertSame('1.2.3', Debugger::roundVersion('1.2.3'));
212+
self::assertSame('1.0.3', Debugger::roundVersion('1.0.3'));
213+
self::assertSame('1.2', Debugger::roundVersion('1.2.0'));
214+
self::assertSame('1', Debugger::roundVersion('1.0.0'));
215+
}
208216
}

0 commit comments

Comments
 (0)