Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on:
push:
branches: [ "*" ]
pull_request:

permissions:
contents: read

jobs:
tests:
name: Tests (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '8.4', '8.5' ]

steps:
- uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: sockets, apcu
ini-values: apc.enable_cli=1, error_reporting=-1
coverage: xdebug

- name: Install dependencies
uses: ramsey/composer-install@v3

- name: Run tests
run: vendor/bin/phpunit

static-analysis:
name: Static analysis
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: sockets, apcu
coverage: none

- name: Install dependencies
uses: ramsey/composer-install@v3

- name: Psalm
run: vendor/bin/psalm --output-format=github --no-cache

coding-standards:
name: Coding standards
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: sockets, apcu
coverage: none

- name: Install dependencies
uses: ramsey/composer-install@v3

- name: php-cs-fixer
run: vendor/bin/php-cs-fixer check --allow-risky=yes --using-cache=no --diff

- name: Rector
run: vendor/bin/rector process --dry-run --clear-cache

- name: Validate composer.json
run: composer validate --strict
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
/vendor/
composer.lock
composer.phar
.php-cs-fixer.cache
/.phpunit.cache
/phpunit.xml
49 changes: 49 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$finder = Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests'])
// src/Thrift is generated by bin/thrift-gen.sh and must stay byte-for-byte reproducible from
// the IDL, so its shape is the thrift compiler's contract rather than ours.
->exclude(['Thrift'])
->append([__DIR__ . '/rector.php', __FILE__]);

return new Config()
->setFinder($finder)
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PER-CS2.0' => true,
'@PER-CS2.0:risky' => true,
'@PHP84Migration' => true,
'@PHPUnit100Migration:risky' => true,
'declare_strict_types' => true,
'strict_comparison' => true,
'strict_param' => true,
'yoda_style' => true,
'native_function_invocation' => [
'include' => ['@compiler_optimized'],
'scope' => 'namespaced',
'strict' => true,
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => false,
'import_functions' => false,
],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'type_declaration_spaces' => true,
'no_unused_imports' => true,
'no_superfluous_phpdoc_tags' => true,
'phpdoc_align' => false,
'void_return' => true,
'nullable_type_declaration_for_default_null_value' => true,
'single_line_throw' => false,
'concat_space' => ['spacing' => 'one'],
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'parameters']],
]);
47 changes: 35 additions & 12 deletions bin/thrift-gen.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
#!/bin/bash
set -e
#!/usr/bin/env bash
#
# Regenerates src/Thrift from the Jaeger IDL.
#
# The compiler version matters: 0.24 emits declare(strict_types=1) and native
# types, earlier releases emit untyped properties with @var docblocks only.
#
# brew install thrift
#
set -euo pipefail

IDL_VERSION='v0.12.0'
THRIFT_MAJOR_MINOR='0.24'

cd "$(dirname "$0")/.."
root="$(pwd)"

if ! command -v thrift >/dev/null 2>&1; then
echo 'error: the thrift compiler is not installed (brew install thrift)' >&2
exit 1
fi

thrift_version="$(thrift --version | awk '{print $NF}')"
if [[ "${thrift_version}" != "${THRIFT_MAJOR_MINOR}."* ]]; then
echo "error: thrift ${THRIFT_MAJOR_MINOR}.x is required, found ${thrift_version}" >&2
exit 1
fi

git clone https://github.com/jaegertracing/jaeger-idl
pushd jaeger-idl
workdir="$(mktemp -d)"
trap 'rm -rf "${workdir}"' EXIT

rm -rf ../src/Thrift
git clone --quiet --depth 1 --branch "${IDL_VERSION}" \
https://github.com/jaegertracing/jaeger-idl.git "${workdir}/jaeger-idl"

FILES=thrift/*.thrift
for f in ${FILES}; do
thrift -r --gen php:psr4 ${f}
cd "${workdir}/jaeger-idl"
for definition in thrift/*.thrift; do
thrift -r --gen php "${definition}"
done

rm -rf ../src/Jaeger/Thrift/
mv ../jaeger-idl/gen-php/Jaeger/Thrift ../src/Thrift
rm -rf "${root}/src/Thrift"
mv gen-php/Jaeger/Thrift "${root}/src/Thrift"

popd
rm -rf jaeger-idl
echo "src/Thrift regenerated from jaeger-idl ${IDL_VERSION} using thrift ${thrift_version}"
37 changes: 27 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
{
"name": "code-tool/jaeger-client-php",
"description": "PHP OpenTracing client for Jaeger",
"license": "MIT",
"autoload": {
"psr-4": {
"Jaeger\\": "src/"
}
},
"type": "library",
"keywords": [
"jaeger",
"opentracing",
"tracing",
"thrift"
],
"require": {
"php": ">=7.4",
"php": "^8.4",
"ext-sockets": "*",
"apache/thrift": ">=0.11, <0.17"
"apache/thrift": "^0.24.0"
},
"require-dev": {
"phpunit/phpunit": "@stable"
"friendsofphp/php-cs-fixer": "^3.95",
"phpunit/phpunit": "^13",
"rector/rector": "^2.6",
"vimeo/psalm": "^6"
},
"suggest": {
"ext-apcu": "Required by RateLimitingSampler to share its rate counters between requests"
},
"minimum-stability": "dev",
"prefer-stable": true
"autoload": {
"psr-4": {
"Jaeger\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Jaeger\\Tests\\": "tests/"
}
}
}
32 changes: 32 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/13.3/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
recordTestRunHistory="false"
executionOrder="random"
failOnRisky="true"
failOnWarning="true"
beStrictAboutOutputDuringTests="true"
>
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="Jaeger Client Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory>src</directory>
</include>
<exclude>
<!-- Generated by bin/thrift-gen.sh. -->
<directory>src/Thrift</directory>
</exclude>
</source>
</phpunit>
45 changes: 45 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
<directory name="tests" />
<ignoreFiles>
<directory name="vendor" />
<!-- Generated by bin/thrift-gen.sh; its shape is the compiler's contract, and it calls
thrift_protocol_* from the optional C extension. -->
<directory name="src/Thrift" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MissingOverrideAttribute errorLevel="suppress" />
<!-- This is a library: consumers legitimately extend these classes. -->
<ClassMustBeFinal errorLevel="suppress" />
<UnusedClass errorLevel="suppress" />
<PossiblyUnusedMethod errorLevel="suppress" />
<!-- Idioms that are normal in test code: asserting on generated Thrift struct properties,
asserting types psalm already considers narrow, and fixtures set up in setUp(). -->
<NoInterfaceProperties>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</NoInterfaceProperties>
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</PropertyNotSetInConstructor>
<UnsafeInstantiation>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</UnsafeInstantiation>
</issueHandlers>
</psalm>
28 changes: 28 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/.php-cs-fixer.dist.php',
__FILE__,
])
// src/Thrift is generated by bin/thrift-gen.sh and must stay byte-for-byte reproducible from
// the IDL, so its shape is the thrift compiler's contract rather than ours.
->withSkip([
__DIR__ . '/src/Thrift',
])
->withPhpSets(php84: true)
->withPreparedSets(
deadCode: true,
codeQuality: true,
codingStyle: true,
typeDeclarations: true,
privatization: true,
earlyReturn: true,
)
->withImportNames(removeUnusedImports: true);
1 change: 1 addition & 0 deletions src/Client/ClientInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Jaeger\Client;
Expand Down
Loading