Skip to content

Commit f32c1a3

Browse files
sergeyklayjonahgeorge
authored andcommitted
Improved build process on Travis CI (#53)
* Setting up the PHP_CodeSniffer * Fixed code style * Improved build process on Travis CI * Add PHP 5.6 to allow_failures block Refs: #46 (comment) * Moved all tests to the its own namespace * Add jaeger-idl to the ignore paths * Amended docs
1 parent 57457a1 commit f32c1a3

33 files changed

+271
-81
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
.settings/
1+
.settings
22
.buildpath
33
.project
44
.idea
5+
6+
jaeger-idl
57
vendor
8+
69
composer.lock
10+
composer.phar
11+
712
jaeger-client-php.iml
13+
814
phpunit.xml
15+
phpcs.xml

.travis.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1+
sudo: false
2+
dist: trusty
3+
14
language: php
5+
26
php:
7+
- '5.6'
38
- '7.0'
49
- '7.1'
510
- '7.2'
611
- nightly
712

13+
git:
14+
depth: 1
15+
16+
matrix:
17+
fast_finish: true
18+
allow_failures:
19+
- php: '5.6'
20+
- php: nightly
21+
822
install:
9-
- composer install
23+
- |
24+
composer install \
25+
--prefer-dist \
26+
--no-interaction \
27+
--no-ansi \
28+
--no-progress \
29+
--optimize-autoloader \
30+
--no-suggest
1031
1132
script:
12-
- vendor/bin/phpunit
33+
- vendor/bin/phpcs
34+
- vendor/bin/phpunit

composer.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
{
22
"name": "jonahgeorge/jaeger-client-php",
3+
"description": "Jaeger Bindings for PHP OpenTracing API",
34
"license": "MIT",
45
"minimum-stability": "dev",
56
"prefer-stable": true,
67
"require": {
7-
"php": ">=7.0",
8+
"php": "^5.6||^7.0",
9+
"ext-sockets": "*",
810
"packaged/thrift": "0.10.0",
911
"opentracing/opentracing" : "1.0.0-beta5",
1012
"phlib/base_convert": "^1.0",
11-
"psr/log": "1.0.2",
12-
"ext-sockets": "*"
13+
"psr/log": "1.0.2"
1314
},
1415
"provide": {
1516
"opentracing/opentracing": "1.0.0-beta5"
1617
},
1718
"require-dev": {
18-
"phpunit/phpunit": "^6.4"
19+
"phpunit/phpunit": "~5.6||^6.4",
20+
"squizlabs/php_codesniffer": "3.*"
1921
},
2022
"autoload": {
2123
"psr-4": {
22-
"Jaeger\\": "src/Jaeger/"
24+
"Jaeger\\": "src/Jaeger/",
25+
"Jaeger\\Tests\\": "tests/Jaeger/"
2326
},
2427
"files": [
2528
"./src/Jaeger/Constants.php"

phpcs.xml.dist

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Jaeger">
3+
4+
<!--
5+
The name attribute of the ruleset tag is displayed
6+
when running PHP_CodeSniffer with the -v command line
7+
argument. The description tag below is not displayed anywhere
8+
except in this file, so it can contain information for
9+
developers who may change this file in the future.
10+
-->
11+
<description>The coding standard for Jaeger Client</description>
12+
13+
<!-- Show sniff codes in all reports -->
14+
<arg value="s"/>
15+
16+
<!-- Use PSR-2 as a base -->
17+
<rule ref="PSR2"/>
18+
19+
<!-- Uncomment to use colors in progress or report -->
20+
<!-- arg name="colors" / -->
21+
22+
<!--
23+
If no files or directories are specified on the command line
24+
your custom standard can specify what files should be checked
25+
instead.
26+
Note that specifying any file or directory path
27+
on the command line will ignore all file tags.
28+
-->
29+
<file>src</file>
30+
31+
<!--
32+
You can hard-code ignore patterns directly into your
33+
custom standard so you don't have to specify the
34+
patterns on the command line.
35+
-->
36+
<exclude-pattern>src/Jaeger/Thrift/*</exclude-pattern>
37+
</ruleset>

src/Jaeger/Codec/BinaryCodec.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,33 @@
77

88
class BinaryCodec implements CodecInterface
99
{
10+
/**
11+
* {@inheritdoc}
12+
*
13+
* @see \Jaeger\Tracer::inject
14+
*
15+
* @param SpanContext $spanContext
16+
* @param mixed $carrier
17+
*
18+
* @return void
19+
*/
1020
public function inject(SpanContext $spanContext, &$carrier)
1121
{
1222
throw new UnsupportedFormat('Binary encoding not implemented');
1323
}
1424

15-
/**
16-
* @return SpanContext|null
25+
/**
26+
* {@inheritdoc}
27+
*
28+
* @see \Jaeger\Tracer::extract
29+
*
30+
* @param mixed $carrier
31+
* @return SpanContext|null
32+
*
33+
* @throws UnsupportedFormat
1734
*/
1835
public function extract($carrier)
1936
{
2037
throw new UnsupportedFormat('Binary encoding not implemented');
2138
}
22-
}
39+
}

src/Jaeger/Codec/CodecInterface.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,31 @@
66

77
interface CodecInterface
88
{
9+
/**
10+
* Handle the logic behind injecting propagation scheme specific information into the carrier
11+
* (e.g. http request headers, amqp message headers, etc.).
12+
*
13+
* This method can modify the carrier.
14+
*
15+
* @see \Jaeger\Tracer::inject
16+
*
17+
* @param SpanContext $spanContext
18+
* @param mixed $carrier
19+
*
20+
* @return void
21+
*/
922
public function inject(SpanContext $spanContext, &$carrier);
1023

11-
/**
12-
* @return SpanContext|null
24+
/**
25+
* Handle the logic behind extracting propagation-scheme specific information from carrier
26+
* (e.g. http request headers, amqp message headers, etc.).
27+
*
28+
* This method must not modify the carrier.
29+
*
30+
* @see \Jaeger\Tracer::extract
31+
*
32+
* @param mixed $carrier
33+
* @return SpanContext|null
1334
*/
1435
public function extract($carrier);
15-
}
36+
}

src/Jaeger/Codec/TextCodec.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,24 @@ public function __construct(
3030
string $traceIdHeader = TRACE_ID_HEADER,
3131
string $baggageHeaderPrefix = BAGGAGE_HEADER_PREFIX,
3232
string $debugIdHeader = DEBUG_ID_HEADER_KEY
33-
)
34-
{
33+
) {
3534
$this->urlEncoding = $urlEncoding;
3635
$this->traceIdHeader = str_replace('_', '-', strtolower($traceIdHeader));
3736
$this->baggagePrefix = str_replace('_', '-', strtolower($baggageHeaderPrefix));
3837
$this->debugIdHeader = str_replace('_', '-', strtolower($debugIdHeader));
3938
$this->prefixLength = strlen($baggageHeaderPrefix);
4039
}
4140

41+
/**
42+
* {@inheritdoc}
43+
*
44+
* @see \Jaeger\Tracer::inject
45+
*
46+
* @param SpanContext $spanContext
47+
* @param mixed $carrier
48+
*
49+
* @return void
50+
*/
4251
public function inject(SpanContext $spanContext, &$carrier)
4352
{
4453
$carrier[$this->traceIdHeader] = $this->spanContextToString(
@@ -65,9 +74,11 @@ public function inject(SpanContext $spanContext, &$carrier)
6574
}
6675

6776
/**
68-
* Extract a span context from a carrier.
77+
* {@inheritdoc}
78+
*
79+
* @see \Jaeger\Tracer::extract
6980
*
70-
* @param array|\Traversable $carrier
81+
* @param mixed $carrier
7182
* @return SpanContext|null
7283
*
7384
* @throws Exception

src/Jaeger/Codec/ZipkinCodec.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ class ZipkinCodec implements CodecInterface
1818
const FLAGS_NAME = 'X-B3-Flags';
1919

2020
/**
21+
* {@inheritdoc}
22+
*
23+
* @see \Jaeger\Tracer::inject
24+
*
2125
* @param SpanContext $spanContext
22-
* @param array $carrier
26+
* @param mixed $carrier
27+
*
28+
* @return void
2329
*/
2430
public function inject(SpanContext $spanContext, &$carrier)
2531
{
@@ -32,7 +38,11 @@ public function inject(SpanContext $spanContext, &$carrier)
3238
}
3339

3440
/**
35-
* @param array $carrier
41+
* {@inheritdoc}
42+
*
43+
* @see \Jaeger\Tracer::extract
44+
*
45+
* @param mixed $carrier
3646
* @return SpanContext|null
3747
*/
3848
public function extract($carrier)
@@ -43,7 +53,9 @@ public function extract($carrier)
4353
$flags = 0;
4454

4555
if (isset($carrier[strtolower(self::SAMPLED_NAME)])) {
46-
if ($carrier[strtolower(self::SAMPLED_NAME)] === "1" || strtolower($carrier[strtolower(self::SAMPLED_NAME)] === "true")) {
56+
if ($carrier[strtolower(self::SAMPLED_NAME)] === "1" ||
57+
strtolower($carrier[strtolower(self::SAMPLED_NAME)] === "true")
58+
) {
4759
$flags = $flags | SAMPLED_FLAG;
4860
}
4961
}

src/Jaeger/Config.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ private function getSampler(): SamplerInterface
157157
*/
158158
private function getLocalAgentSender(): UdpSender
159159
{
160-
$udp = new ThriftUdpTransport($this->getLocalAgentReportingHost(), $this->getLocalAgentReportingPort(), $this->logger);
160+
$udp = new ThriftUdpTransport(
161+
$this->getLocalAgentReportingHost(),
162+
$this->getLocalAgentReportingPort(),
163+
$this->logger
164+
);
161165

162166
$transport = new TBufferedTransport($udp, $this->getMaxBufferLength(), $this->getMaxBufferLength());
163167
try {

src/Jaeger/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686

8787
const DEFAULT_SAMPLING_PORT = 5778;
8888

89-
const LOCAL_AGENT_DEFAULT_ENABLED = True;
89+
const LOCAL_AGENT_DEFAULT_ENABLED = true;
9090

9191
const ZIPKIN_SPAN_FORMAT = 'zipkin-span-format';
9292

src/Jaeger/Sampler/ConstSampler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace Jaeger\Sampler;
4+
45
use const Jaeger\SAMPLER_PARAM_TAG_KEY;
56
use const Jaeger\SAMPLER_TYPE_CONST;
67
use const Jaeger\SAMPLER_TYPE_TAG_KEY;

src/Jaeger/Sender/UdpSender.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ private function addZipkinAnnotations(JaegerSpan $span, Endpoint $endpoint)
167167
$host = $this->makeEndpoint(
168168
$span->peer['ipv4'] ?? 0,
169169
$span->peer['port'] ?? 0,
170-
$span->peer['service_name'] ?? '');
170+
$span->peer['service_name'] ?? ''
171+
);
171172

172173
$key = ($isClient) ? self::SERVER_ADDR : self::CLIENT_ADDR;
173174

src/Jaeger/Span.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ public function __construct(
8888
string $operationName,
8989
array $tags = [],
9090
$startTime = null
91-
)
92-
{
91+
) {
9392
$this->context = $context;
9493
$this->tracer = $tracer;
9594

@@ -205,7 +204,7 @@ public function overwriteOperationName($newOperationName)
205204
/**
206205
* {@inheritdoc}
207206
*
208-
* @param array|\Traversable $tags
207+
* @param array $tags
209208
* @return void
210209
*/
211210
public function setTags($tags)

src/Jaeger/SpanContext.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ public function getBaggageItem($key)
6767
*/
6868
public function withBaggageItem($key, $value)
6969
{
70-
return new self($this->traceId, $this->spanId, $this->parentId, $this->flags, [$key => $value] + $this->baggage);
70+
return new self(
71+
$this->traceId,
72+
$this->spanId,
73+
$this->parentId,
74+
$this->flags,
75+
[$key => $value] + $this->baggage
76+
);
7177
}
7278

7379
public function getTraceId()

src/Jaeger/ThriftUdpTransport.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function isOpen()
5858
public function open()
5959
{
6060
$ok = @socket_connect($this->socket, $this->host, $this->port);
61-
if ($ok === FALSE) {
61+
if ($ok === false) {
6262
throw new TTransportException('socket_connect failed');
6363
}
6464
}
@@ -75,9 +75,10 @@ public function close()
7575
/**
7676
* Read some data into the array.
7777
*
78+
* @todo
79+
*
7880
* @param int $len How much to read
7981
* @return string The data that has been read
80-
* @throws TTransportException if cannot read any more data
8182
*/
8283
public function read($len)
8384
{
@@ -96,7 +97,7 @@ public function write($buf)
9697
}
9798

9899
$ok = @socket_write($this->socket, $buf);
99-
if ($ok === FALSE) {
100+
if ($ok === false) {
100101
throw new TTransportException('socket_write failed');
101102
}
102103
}

0 commit comments

Comments
 (0)