Skip to content

Commit bad09ac

Browse files
wesolydexterdmajka
and
dmajka
authored
fix: resolve deprecations for implicitly nullable parameters in PHP 8.4 (#231)
* fix: resolve deprecations for implicitly nullable parameters in PHP 8.4 * Update actions/cache from v2 to v3 * Update workflows to use the latest output method * Fix composer cache directory setup * Fix composer cache directory output in CI * Fix mysqli connection test. * Renamed abstract test classes to avoid warnings * Fix namespace issue in MysqliTest * Update CI to upload coverage report for PHP 8.1 * Revert version number in Docker Compose file. * Use `docker compose` instead of `docker-compose`. * Skip testing mysql connection on non-Linux systems * Disable Codecov coverage upload in the CI workflow * Remove code coverage in CI --------- Co-authored-by: dmajka <dawid.majka@verestro.com>
1 parent e2809f8 commit bad09ac

33 files changed

+83
-78
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
operating-system: [ubuntu-latest, windows-latest, macos-latest]
18-
php-versions: ["7.4", "8.0", "8.1"]
18+
php-versions: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]
1919
steps:
2020
- name: Checkout
2121
uses: actions/checkout@v2
@@ -27,9 +27,9 @@ jobs:
2727
extensions: mysql
2828
- name: Get composer cache directory
2929
id: composer-cache
30-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
30+
run: echo "dir=$(composer config cache-files-dir | tr -d '\n' | tr -d '\r')" >> $GITHUB_OUTPUT
3131
- name: Cache composer dependencies
32-
uses: actions/cache@v2
32+
uses: actions/cache@v3
3333
with:
3434
path: ${{ steps.composer-cache.outputs.dir }}
3535
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
@@ -44,17 +44,3 @@ jobs:
4444
run: composer static-check
4545
- name: Run tests
4646
run: composer test -- --coverage-clover=build/logs/clover.xml
47-
- name: Upload coverage report to codecov service
48-
if: ${{ matrix.operating-system == 'ubuntu-latest' && matrix.php-versions == '8.0' }}
49-
run: |
50-
wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
51-
chmod +x php-coveralls.phar
52-
php php-coveralls.phar --version
53-
mkdir -p build/logs
54-
php php-coveralls.phar -v
55-
bash <(curl -s https://codecov.io/bash)
56-
env:
57-
# Running coveralls with default config did not work so followed the workaround below:
58-
# https://github.com/php-coveralls/php-coveralls/issues/273#issuecomment-537473525
59-
COVERALLS_RUN_LOCALLY: 1
60-
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ composer.phar
22
composer.lock
33
/vendor/
44
.phpunit.result.cache
5+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
4+
5+
$finder = PhpCsFixer\Finder::create()
6+
->in('src')
7+
->in('tests')
8+
;
9+
10+
return (new PhpCsFixer\Config())
11+
->setParallelConfig(ParallelConfigFactory::detect())
12+
->setRules(
13+
[
14+
'nullable_type_declaration_for_default_null_value' => true,
15+
]
16+
)
17+
->setFinder($finder)
18+
;

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
![CI](https://github.com/openzipkin/zipkin-php/workflows/CI/badge.svg)
44
[![Latest Stable Version](https://poser.pugx.org/openzipkin/zipkin/v/stable)](https://packagist.org/packages/openzipkin/zipkin)
5-
[![Coverage Status](https://coveralls.io/repos/github/openzipkin/zipkin-php/badge.svg)](https://coveralls.io/github/openzipkin/zipkin-php)
65
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg)](https://php.net/)
76
[![Total Downloads](https://poser.pugx.org/openzipkin/zipkin/downloads)](https://packagist.org/packages/openzipkin/zipkin)
87
[![License](https://img.shields.io/packagist/l/openzipkin/zipkin.svg)](https://github.com/openzipkin/zipkin-php/blob/master/LICENSE)

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"require-dev": {
2929
"ext-mysqli": "*",
30+
"friendsofphp/php-cs-fixer": "^3.75",
3031
"jcchavezs/httptest": "~0.2",
3132
"middlewares/fast-route": "^2.0",
3233
"middlewares/request-handler": "^2.0",

src/Zipkin/Instrumentation/Http/Client/HttpClientTracing.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class HttpClientTracing
2727

2828
public function __construct(
2929
Tracing $tracing,
30-
HttpClientParser $parser = null,
31-
callable $requestSampler = null
30+
?HttpClientParser $parser = null,
31+
?callable $requestSampler = null
3232
) {
3333
$this->tracing = $tracing;
3434
$this->parser = $parser ?? new DefaultHttpClientParser();

src/Zipkin/Instrumentation/Http/Server/HttpServerTracing.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class HttpServerTracing
2626

2727
public function __construct(
2828
Tracing $tracing,
29-
HttpServerParser $parser = null,
30-
callable $requestSampler = null
29+
?HttpServerParser $parser = null,
30+
?callable $requestSampler = null
3131
) {
3232
$this->tracing = $tracing;
3333
$this->parser = $parser ?? new DefaultHttpServerParser();

src/Zipkin/Instrumentation/Mysqli/Mysqli.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ final class Mysqli extends \Mysqli
3030
public function __construct(
3131
Tracer $tracer,
3232
array $options = [],
33-
string $host = null,
34-
string $user = null,
35-
string $password = null,
33+
?string $host = null,
34+
?string $user = null,
35+
?string $password = null,
3636
string $database = '',
37-
int $port = null,
38-
string $socket = null
37+
?int $port = null,
38+
?string $socket = null
3939
) {
4040
self::validateOptions($options);
4141
$this->tracer = $tracer;
@@ -65,7 +65,7 @@ private static function validateOptions(array $opts): void
6565
}
6666
}
6767

68-
private function addsTagsAndRemoteEndpoint(Span $span, string $query = null): void
68+
private function addsTagsAndRemoteEndpoint(Span $span, ?string $query = null): void
6969
{
7070
if ($query !== null && $this->options['tag_query']) {
7171
$span->tag('sql.query', $query);

src/Zipkin/NoopSpan.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getContext(): TraceContext
3737
* Spans can be modified before calling start. For example, you can add tags to the span and
3838
* set its name without lock contention.
3939
*/
40-
public function start(int $timestamp = null): void
40+
public function start(?int $timestamp = null): void
4141
{
4242
}
4343

@@ -87,7 +87,7 @@ public function setError(Throwable $e): void
8787
* @return void
8888
* @see Annotations
8989
*/
90-
public function annotate(string $value, int $timestamp = null): void
90+
public function annotate(string $value, ?int $timestamp = null): void
9191
{
9292
}
9393

@@ -113,7 +113,7 @@ public function abandon(): void
113113
* {@link zipkin.Span#duration Zipkin's span duration} is derived by subtracting the start
114114
* timestamp from this, and set when appropriate.
115115
*/
116-
public function finish(int $timestamp = null): void
116+
public function finish(?int $timestamp = null): void
117117
{
118118
}
119119

src/Zipkin/NoopSpanCustomizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function tag(string $key, string $value): void
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function annotate(string $value, int $timestamp = null): void
26+
public function annotate(string $value, ?int $timestamp = null): void
2727
{
2828
}
2929
}

src/Zipkin/Propagation/B3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ final class B3 implements Propagation
147147
* same injector list.
148148
*/
149149
public function __construct(
150-
LoggerInterface $logger = null,
150+
?LoggerInterface $logger = null,
151151
array $kindInjectors = []
152152
) {
153153
$this->logger = $logger ?: new NullLogger();

src/Zipkin/Propagation/CurrentTraceContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class CurrentTraceContext
2020
{
2121
private ?TraceContext $context;
2222

23-
public function __construct(TraceContext $currentContext = null)
23+
public function __construct(?TraceContext $currentContext = null)
2424
{
2525
$this->context = $currentContext;
2626
}
@@ -40,7 +40,7 @@ public function getContext(): ?TraceContext
4040
* @param TraceContext|null $currentContext
4141
* @return callable():void The scope closed
4242
*/
43-
public function createScopeAndRetrieveItsCloser(TraceContext $currentContext = null): callable
43+
public function createScopeAndRetrieveItsCloser(?TraceContext $currentContext = null): callable
4444
{
4545
$previous = $this->context;
4646
$self = $this;

src/Zipkin/RealSpan.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getContext(): TraceContext
5252
* @return void
5353
* @throws \InvalidArgumentException
5454
*/
55-
public function start(int $timestamp = null): void
55+
public function start(?int $timestamp = null): void
5656
{
5757
if ($timestamp !== null && !isValid($timestamp)) {
5858
throw new InvalidArgumentException(
@@ -117,7 +117,7 @@ public function setError(Throwable $e): void
117117
* @throws \InvalidArgumentException
118118
* @see Zipkin\Annotations
119119
*/
120-
public function annotate(string $value, int $timestamp = null): void
120+
public function annotate(string $value, ?int $timestamp = null): void
121121
{
122122
if ($timestamp !== null && !isValid($timestamp)) {
123123
throw new InvalidArgumentException(
@@ -161,7 +161,7 @@ public function abandon(): void
161161
* @return void
162162
* @throws \InvalidArgumentException
163163
*/
164-
public function finish(int $timestamp = null): void
164+
public function finish(?int $timestamp = null): void
165165
{
166166
if ($timestamp !== null && !isValid($timestamp)) {
167167
throw new InvalidArgumentException('Invalid timestamp');

src/Zipkin/Recording/Span.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public function setRemoteEndpoint(Endpoint $remoteEndpoint): void
268268
*
269269
* @param int|null $finishTimestamp
270270
*/
271-
public function finish(int $finishTimestamp = null): void
271+
public function finish(?int $finishTimestamp = null): void
272272
{
273273
if ($this->finished) {
274274
return;

src/Zipkin/Reporters/Http.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ final class Http implements Reporter
5151
*/
5252
public function __construct(
5353
array $options = [],
54-
ClientFactory $requesterFactory = null,
55-
LoggerInterface $logger = null,
56-
SpanSerializer $serializer = null
54+
?ClientFactory $requesterFactory = null,
55+
?LoggerInterface $logger = null,
56+
?SpanSerializer $serializer = null
5757
) {
5858
$this->options = \array_merge(self::DEFAULT_OPTIONS, $options);
5959
$this->clientFactory = $requesterFactory ?? CurlFactory::create();

src/Zipkin/Reporters/JsonV2Serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class JsonV2Serializer implements SpanSerializer
1313
{
1414
private ErrorParser $errorParser;
1515

16-
public function __construct(ErrorParser $errorParser = null)
16+
public function __construct(?ErrorParser $errorParser = null)
1717
{
1818
$this->errorParser = $errorParser ?? new DefaultErrorParser();
1919
}

src/Zipkin/Reporters/Log.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class Log implements Reporter
1616

1717
public function __construct(
1818
LoggerInterface $logger,
19-
SpanSerializer $serializer = null
19+
?SpanSerializer $serializer = null
2020
) {
2121
$this->logger = $logger;
2222
$this->serializer = $serializer ?? new JsonV2Serializer();

src/Zipkin/Span.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function getContext(): TraceContext;
2525
* Spans can be modified before calling start. For example, you can add tags to the span and
2626
* set its name without lock contention.
2727
*/
28-
public function start(int $timestamp = null): void;
28+
public function start(?int $timestamp = null): void;
2929

3030
/**
3131
* Sets the string name for the logical operation this span represents.
@@ -67,7 +67,7 @@ public function setError(Throwable $e): void;
6767
* @return void
6868
* @see Annotations
6969
*/
70-
public function annotate(string $value, int $timestamp = null): void;
70+
public function annotate(string $value, ?int $timestamp = null): void;
7171

7272
/**
7373
* For a client span, this would be the server's address.
@@ -95,7 +95,7 @@ public function abandon(): void;
9595
* @param int|null $timestamp
9696
* @return void
9797
*/
98-
public function finish(int $timestamp = null): void;
98+
public function finish(?int $timestamp = null): void;
9999

100100
/**
101101
* Reports the span, even if unfinished. Most users will not call this method.

src/Zipkin/SpanCustomizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ public function tag(string $key, string $value): void;
4141
* @return void
4242
* @see Annotations
4343
*/
44-
public function annotate(string $value, int $timestamp = null): void;
44+
public function annotate(string $value, ?int $timestamp = null): void;
4545
}

src/Zipkin/SpanCustomizerShield.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function tag(string $key, string $value): void
3737
/**
3838
* {@inheritdoc}
3939
*/
40-
public function annotate(string $value, int $timestamp = null): void
40+
public function annotate(string $value, ?int $timestamp = null): void
4141
{
4242
$this->delegate->annotate($value, $timestamp);
4343
}

src/Zipkin/Tracer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(
7373
* @param SamplingFlags $samplingFlags
7474
* @return Span
7575
*/
76-
public function newTrace(SamplingFlags $samplingFlags = null): Span
76+
public function newTrace(?SamplingFlags $samplingFlags = null): Span
7777
{
7878
if ($samplingFlags === null) {
7979
$samplingFlags = DefaultSamplingFlags::createAsEmpty();
@@ -139,7 +139,7 @@ public function joinSpan(TraceContext $context): Span
139139
*
140140
* @return callable():void The scope closer
141141
*/
142-
public function openScope(Span $span = null): callable
142+
public function openScope(?Span $span = null): callable
143143
{
144144
return $this->currentTraceContext->createScopeAndRetrieveItsCloser(
145145
$span === null ? null : $span->getContext()
@@ -193,7 +193,7 @@ public function flush(): void
193193
* @return Span
194194
* @throws \RuntimeException
195195
*/
196-
public function nextSpan(SamplingFlags $contextOrFlags = null): Span
196+
public function nextSpan(?SamplingFlags $contextOrFlags = null): Span
197197
{
198198
if ($contextOrFlags === null) {
199199
$parent = $this->currentTraceContext->getContext();
@@ -230,7 +230,7 @@ public function nextSpan(SamplingFlags $contextOrFlags = null): Span
230230
public function nextSpanWithSampler(
231231
callable $sampler,
232232
array $args = [],
233-
SamplingFlags $contextOrFlags = null
233+
?SamplingFlags $contextOrFlags = null
234234
): Span {
235235
if ($contextOrFlags === null) {
236236
$contextOrFlags = $this->currentTraceContext->getContext();

tests/Integration/Instrumentation/Mysqli/MysqliTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace ZipkinTests\Integration\Instrumentation\Http\Server;
5+
namespace ZipkinTests\Integration\Instrumentation\Mysqli;
66

77
use Zipkin\Tracer;
88
use Zipkin\Samplers\BinarySampler;
@@ -20,12 +20,12 @@ final class MysqliTest extends TestCase
2020
private static function launchMySQL(): array
2121
{
2222
shell_exec('docker rm -f zipkin_php_mysql_test');
23-
shell_exec(sprintf('cd %s; docker-compose up -d', __DIR__));
23+
shell_exec(sprintf('cd %s; docker compose up -d', __DIR__));
2424
echo "Waiting for MySQL container to be up.\n";
2525
while (true) {
2626
$res = shell_exec('docker ps --filter "name=zipkin_php_mysql_test" --format "{{.Status}}"');
2727
usleep(500000);
28-
if (strpos($res, "healthy") !== false) {
28+
if ($res !== null && strpos($res, "healthy") !== false) {
2929
echo "MySQL container is up.\n";
3030
break;
3131
}
@@ -38,14 +38,14 @@ private static function launchMySQL(): array
3838
$port = 3306;
3939

4040
return [[$host, $user, $pass, $db, $port], function () {
41-
shell_exec(sprintf('cd %s; docker-compose stop', __DIR__));
41+
shell_exec(sprintf('cd %s; docker compose stop', __DIR__));
4242
}];
4343
}
4444

4545
public function testConnect()
4646
{
47-
if (PHP_OS_FAMILY === 'Windows') {
48-
$this->markTestSkipped("Running the test on windows might be problematic");
47+
if (PHP_OS_FAMILY !== 'Linux') {
48+
$this->markTestSkipped("Running the test on non-Linux systems might be problematic");
4949
}
5050

5151
if (!extension_loaded("mysqli")) {

tests/Unit/Instrumentation/Http/Client/BaseRequestTest.php renamed to tests/Unit/Instrumentation/Http/Client/BaseRequestTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Zipkin\Instrumentation\Http\Client\Request;
88
use PHPUnit\Framework\TestCase;
99

10-
abstract class BaseRequestTest extends TestCase
10+
abstract class BaseRequestTestCase extends TestCase
1111
{
1212
/**
1313
* @return mixed[] including

0 commit comments

Comments
 (0)