Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 416b981

Browse files
committed
fix method names for PHP<7 compatibility
The methods - `InstanaSpanType::entry()`, - `InstanaSpanType::local()` and - `InstanaSpanType::exit()` have been renamed to - `InstanaSpanType::entryType()`, - `InstanaSpanType::localType()` and - `InstanaSpanType::exitType()` to provide compatibility with PHP < 7. Because the methods are API and introduce a BC break, I am bumping the version to 2.0.0.
1 parent 4f2f34a commit 416b981

8 files changed

Lines changed: 26 additions & 42 deletions

File tree

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@ consider using the alternative REST SDK endpoint. To do so, set the global trace
1313
1414
Using the restSdk tracer will send traces to the endpoint in the agent listening on port 42699.
1515

16-
Minimum PHP Version is PHP 5.4.
16+
Starting with v2.0.0 the minimum PHP version required is PHP 5.4.
17+
The 1.x branch will only work on PHP 7+.
18+
19+
## BC breaks between the 1.x version and the 2.x version
20+
21+
The methods `InstanaSpanType::entry()`, `InstanaSpanType::local()` and `InstanaSpanType::exit()`
22+
have been renamed to `InstanaSpanType::entryType()`, `InstanaSpanType::localType()` and
23+
`InstanaSpanType::exitType()` to provide compatibility with PHP < 7. Direct invocations of these
24+
methods in your code will need to be renamed.
1725

1826
## Installation
1927

2028
This library is available on Packagist. You can include it in your composer.yml like this:
2129

2230
"require": {
23-
"instana/instana-php-opentracing": "^1.0"
31+
"instana/instana-php-opentracing": "^2.0"
2432
}
2533

2634
Because OpenTracing v1.0.0 is still in beta, you will also need to set

src/Instana/OpenTracing/InstanaSdkSpan.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function jsonSerialize()
6868
$json['p'] = $this->spanContext->getParentId();
6969
}
7070

71-
if ($this->spanType === InstanaSpanType::entry()) {
71+
if ($this->spanType === InstanaSpanType::entryType()) {
7272
if ($this->processId != null) {
7373
$json['ppid'] = $this->processId;
7474
}

src/Instana/OpenTracing/InstanaSpan.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public function __construct($operationName, Microtime $startTime = null, Instana
6161
: $spanContext;
6262

6363
$this->spanType = $this->spanContext->getParentId() === null
64-
? InstanaSpanType::entry()
65-
: InstanaSpanType::local();
64+
? InstanaSpanType::entryType()
65+
: InstanaSpanType::localType();
6666
}
6767

6868
/**
@@ -160,11 +160,11 @@ public function setTag($key, $value)
160160
switch ($value) {
161161
case \OpenTracing\Tags\SPAN_KIND_RPC_SERVER:
162162
case \OpenTracing\Tags\SPAN_KIND_MESSAGE_BUS_CONSUMER:
163-
$this->spanType = InstanaSpanType::entry();
163+
$this->spanType = InstanaSpanType::entryType();
164164
break;
165165
case \OpenTracing\Tags\SPAN_KIND_RPC_CLIENT:
166166
case \OpenTracing\Tags\SPAN_KIND_MESSAGE_BUS_PRODUCER:
167-
$this->spanType = call_user_func(__NAMESPACE__ . '\InstanaSpanType::exit');
167+
$this->spanType = InstanaSpanType::exitType();
168168
break;
169169
}
170170
break;

src/Instana/OpenTracing/InstanaSpanType.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private function __construct($kind, $type)
4242
/**
4343
* @return InstanaSpanType
4444
*/
45-
public static function entry() {
45+
public static function entryType() {
4646
if (self::$entry === null) {
4747
self::$entry = new InstanaSpanType(1, 'entry');
4848
}
@@ -52,19 +52,6 @@ public static function entry() {
5252
/**
5353
* @return InstanaSpanType
5454
*/
55-
public static function exit() {
56-
if (self::$exit === null) {
57-
self::$exit = new InstanaSpanType(2, 'exit');
58-
}
59-
return self::$exit;
60-
}
61-
62-
/**
63-
* Workaround for PHP < 7 where exit() is parsed as T_EXIT
64-
*
65-
* @return InstanaSpanType
66-
* @deprecated Upgrade to PHP7 to use InstanaSpanType::exit()
67-
*/
6855
public static function exitType() {
6956
if (self::$exit === null) {
7057
self::$exit = new InstanaSpanType(2, 'exit');
@@ -75,7 +62,7 @@ public static function exitType() {
7562
/**
7663
* @return InstanaSpanType
7764
*/
78-
public static function local() {
65+
public static function localType() {
7966
if (self::$local === null) {
8067
self::$local = new InstanaSpanType(3, 'local');
8168
}

src/Instana/OpenTracing/UserAgent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ final class UserAgent
99
*/
1010
public static function get()
1111
{
12-
return 'Instana PHP OpenTracing/1.0.4';
12+
return 'Instana PHP OpenTracing/2.0.0';
1313
}
1414
}

test/Instana/OpenTracing/InstanaHttpSpanFlusherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function creatingRootSpan()
9393
$tracer->flush();
9494

9595
$requestData = $this->getRequestData();
96-
$this->assertEquals('Instana PHP OpenTracing/1.0.4', $requestData['User-Agent']);
96+
$this->assertEquals('Instana PHP OpenTracing/2.0.0', $requestData['User-Agent']);
9797
$this->assertEquals('application/json', $requestData['Content-type']);
9898
$this->assertEquals('close', $requestData['Connection']);
9999

test/Instana/OpenTracing/InstanaSpanTypeTest.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class InstanaSpanTypeTest extends TestCase
1111
*/
1212
public function verifyEntryReturnsSameInstanceAndHasCorrectTypeAndKind()
1313
{
14-
$exit = InstanaSpanType::entry();
15-
$this->assertSame($exit, InstanaSpanType::entry());
14+
$exit = InstanaSpanType::entryType();
15+
$this->assertSame($exit, InstanaSpanType::entryType());
1616
$this->assertEquals(1, $exit->getKind());
1717
$this->assertEquals('entry', $exit->getType());
1818
}
@@ -22,8 +22,8 @@ public function verifyEntryReturnsSameInstanceAndHasCorrectTypeAndKind()
2222
*/
2323
public function verifyExitReturnsSameInstanceAndHasCorrectTypeAndKind()
2424
{
25-
$exit = InstanaSpanType::exit();
26-
$this->assertSame($exit, InstanaSpanType::exit());
25+
$exit = InstanaSpanType::exitType();
26+
$this->assertSame($exit, InstanaSpanType::exitType());
2727
$this->assertEquals(2, $exit->getKind());
2828
$this->assertEquals('exit', $exit->getType());
2929
}
@@ -33,20 +33,9 @@ public function verifyExitReturnsSameInstanceAndHasCorrectTypeAndKind()
3333
*/
3434
public function verifyLocalReturnsSameInstanceAndHasCorrectTypeAndKind()
3535
{
36-
$exit = InstanaSpanType::local();
37-
$this->assertSame($exit, InstanaSpanType::local());
36+
$exit = InstanaSpanType::localType();
37+
$this->assertSame($exit, InstanaSpanType::localType());
3838
$this->assertEquals(3, $exit->getKind());
3939
$this->assertEquals('local', $exit->getType());
4040
}
41-
42-
/**
43-
* @test
44-
*/
45-
public function verifyExitTypeReturnsSameInstanceAndHasCorrectTypeAndKind()
46-
{
47-
$exit = InstanaSpanType::exitType();
48-
$this->assertSame($exit, InstanaSpanType::exitType());
49-
$this->assertEquals(2, $exit->getKind());
50-
$this->assertEquals('exit', $exit->getType());
51-
}
5241
}

test/Instana/OpenTracing/UserAgentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ class UserAgentTest extends TestCase
1111
*/
1212
public function getReturnsUserAgent()
1313
{
14-
$this->assertEquals('Instana PHP OpenTracing/1.0.4', UserAgent::get());
14+
$this->assertEquals('Instana PHP OpenTracing/2.0.0', UserAgent::get());
1515
}
1616
}

0 commit comments

Comments
 (0)