File tree Expand file tree Collapse file tree 3 files changed +38
-7
lines changed Expand file tree Collapse file tree 3 files changed +38
-7
lines changed Original file line number Diff line number Diff line change @@ -28,12 +28,6 @@ public function getRuntime(): string
28
28
29
29
public function getPackageVersion (): string
30
30
{
31
- try {
32
- $ version = json_decode (file_get_contents (__DIR__ .'/../../composer.json ' ), true );
33
-
34
- return sprintf ('vector-php@%s ' , $ version ['version ' ]);
35
- } catch (Throwable $ e ) {
36
- return sprintf ('vector-php@unknown ' );
37
- }
31
+ return sprintf ('vector-php@%s ' , SdkVersion::resolve ());
38
32
}
39
33
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Upstash \Vector \Telemetry ;
4
+
5
+ use Throwable ;
6
+
7
+ class SdkVersion
8
+ {
9
+ public const UNKNOWN = 'unknown ' ;
10
+
11
+ public static function resolve (): string
12
+ {
13
+ try {
14
+ $ version = json_decode (file_get_contents (__DIR__ .'/../../composer.json ' ), true );
15
+
16
+ return $ version ['version ' ] ?? static ::UNKNOWN ;
17
+ } catch (Throwable $ e ) {
18
+ return static ::UNKNOWN ;
19
+ }
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Upstash \Vector \Tests \Unit \Telemetry ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use Upstash \Vector \Telemetry \SdkVersion ;
7
+
8
+ class SdkVersionTest extends TestCase
9
+ {
10
+ public function test_version_is_known (): void
11
+ {
12
+ $ version = SdkVersion::resolve ();
13
+
14
+ $ this ->assertNotSame (SdkVersion::UNKNOWN , $ version );
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments