Skip to content

Commit

Permalink
Drop PHP 7.4 support (#1244)
Browse files Browse the repository at this point in the history
* drop php 7.4 support
update composer.json minimums, and run rector over the code to update what it can. changed some static analysis
config to fix some rector-induced failures.

* adding union typehints

* reformat constructor property promotions

* updating/removing phpdoc

* suppress protobuf extension complaint
submitted a PR upstream to fix phan stubs

* don't validate packages against 7.4

* remove php8 polyfill

* fix readonly comments

* apply trailing commas to multiline fixer
upgrade php-cs-fixer, and apply a new rule for multiline comments

* remove unreachable default match arms for protobuf serializer

* adding more union types to vars

* use weakmap directly

* remove handling for not-supported WeakMap

* spacing
  • Loading branch information
brettmc authored Mar 4, 2024
1 parent cc56628 commit f798bb6
Show file tree
Hide file tree
Showing 223 changed files with 885 additions and 2,094 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
php-version: ['8.0', '8.1', '8.2', '8.3']
experimental: [false]
composer_args: [""]
include:
Expand Down Expand Up @@ -138,4 +138,5 @@ jobs:
needs: php
with:
matrix_extension: '["ast, json, grpc"]'
matrix_php_version: '["8.0", "8.1", "8.2", "8.3"]'
install_directory: '~/.test/.packages'
2 changes: 1 addition & 1 deletion .github/workflows/publish-otel-php-base-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: OpenTelemetry PHP base docker image creation
strategy:
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
php-version: ['8.0', '8.1', '8.2', '8.3']
runs-on: ubuntu-latest
permissions:
packages: write
Expand Down
2 changes: 1 addition & 1 deletion .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
//
// Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist.
// (See `backward_compatibility_checks` for additional options)
'target_php_version' => '7.4',
'target_php_version' => '8.0',

// If enabled, missing properties will be created when
// they are first seen. If false, we'll report an
Expand Down
8 changes: 4 additions & 4 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
'blank_line_before_statement' => true,
'cast_spaces' => true,
'declare_strict_types' => true,
'function_typehint_space' => true,
'type_declaration_spaces' => true,
'include' => true,
'lowercase_cast' => true,
'new_with_braces' => true,
'new_with_parentheses' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_trailing_whitespace' => true,
Expand All @@ -41,9 +41,9 @@
'phpdoc_scalar' => true,
'phpdoc_types' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'blank_lines_before_namespace' => true,
'single_quote' => true,
'trailing_comma_in_multiline' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'parameters', 'match']],
])
->setRiskyAllowed(true)
->setFinder($finder);
4 changes: 2 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ This does the following things:
### Other PHP versions

We aim to support officially supported PHP versions, according to https://www.php.net/supported-versions.php. The
developer image `ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base` is tagged as `7.4`, `8.0`, `8.1` and `8.2`
respectively, with `7.4` being the default. You can execute the test suite against other PHP versions by running the
developer image `ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base` is tagged as `8.0`, `8.1`, `8.2` and `8.3`
respectively, with `8.0` being the default. You can execute the test suite against other PHP versions by running the
following command:

```bash
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include .env

PHP_VERSION ?= 7.4
PHP_VERSION ?= 8.0
DOCKER_COMPOSE ?= docker-compose
DC_RUN_PHP = $(DOCKER_COMPOSE) run --rm php

Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"readme": "./README.md",
"license": "Apache-2.0",
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"ext-json": "*",
"google/protobuf": "^3.22",
"php-http/discovery": "^1.14",
Expand All @@ -17,7 +17,6 @@
"psr/http-message": "^1.0.1|^2.0",
"psr/log": "^1.1|^2.0|^3.0",
"symfony/polyfill-mbstring": "^1.23",
"symfony/polyfill-php80": "^1.26",
"symfony/polyfill-php81": "^1.26",
"symfony/polyfill-php82": "^1.26"
},
Expand Down Expand Up @@ -77,9 +76,9 @@
"ext-grpc": "*",
"grpc/grpc": "^1.30",
"assertwell/phpunit-global-state": "^0.2.2",
"composer/xdebug-handler": "^2.0",
"composer/xdebug-handler": "^3.0",
"dg/bypass-finals": "^1.4",
"friendsofphp/php-cs-fixer": "^3.4",
"friendsofphp/php-cs-fixer": "^3.51",
"guzzlehttp/guzzle": "^7.4",
"guzzlehttp/psr7": "^2.1",
"mikey179/vfsstream": "^1.6.11",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.collector.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.7'
services:
php:
image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-7.4}
image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-8.0}
volumes:
- ./:/usr/src/myapp
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
context: .
dockerfile: docker/examples/Dockerfile
args:
- PHP_VERSION=7.4-fpm
- PHP_VERSION=8.0-fpm
- EXT_ENABLE=redis
volumes:
- ./examples/prometheus/index.php:/var/www/public/index.php
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.w3cTraceContext.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.7'
services:
php:
image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-7.4}
image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-8.0}
volumes:
- ./:/usr/src/myapp
- ./:/usr/src/open-telemetry/
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.7'
services:
php:
image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-7.4}
image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-8.0}
volumes:
- ./:/usr/src/myapp
user: "${PHP_USER}:root"
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PHP_VERSION=7.4
ARG PHP_VERSION=8.0
FROM php:${PHP_VERSION}-cli-alpine as php_build

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
Expand Down
26 changes: 26 additions & 0 deletions examples/traces/features/batch_exporting_with_self_diagnostics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Example;

use OpenTelemetry\API\Globals;

putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_TRACES_EXPORTER=console');
putenv('OTEL_METRICS_EXPORTER=console');
putenv('OTEL_PHP_INTERNAL_METRICS_ENABLED=true');

require __DIR__ . '/../../../vendor/autoload.php';

/**
* Demonstrates batch span processing which also emits metrics for the internal state
* of the processor (eg spans received, queue length)
*/

echo 'Starting ConsoleSpanExporter with BatchSpanProcessor and metrics' . PHP_EOL;

$tracer = Globals::tracerProvider()->getTracer('io.opentelemetry.contrib.php');
$tracer->spanBuilder('root')->startSpan()->end();

echo PHP_EOL . 'Example complete! ' . PHP_EOL;
2 changes: 1 addition & 1 deletion proto/otel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"google/protobuf": "^3.3.0"
},
"autoload": {
Expand Down
7 changes: 7 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
<pluginClass class="Psalm\MockeryPlugin\Plugin"/>
</plugins>
<issueHandlers>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="GMP" />
</errorLevel>
</UndefinedClass>
</issueHandlers>
</psalm>
6 changes: 3 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\ValueObject\PhpVersion;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->phpVersion(PhpVersion::PHP_74);
$rectorConfig->phpVersion(PhpVersion::PHP_80);

$rectorConfig->paths([
__DIR__ . '/src',
]);

$rectorConfig->sets([
SetList::PHP_74,
SetList::PHP_80,
SetList::CODE_QUALITY,
]);
$rectorConfig->skip([
Expand Down
6 changes: 1 addition & 5 deletions src/API/Baggage/Baggage.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ public static function getEmpty(): BaggageInterface
return self::$emptyBaggage;
}

/** @var array<string, Entry> */
private array $entries;

/** @param array<string, Entry> $entries */
public function __construct(array $entries = [])
public function __construct(private array $entries = [])
{
$this->entries = $entries;
}

/** @inheritDoc */
Expand Down
6 changes: 1 addition & 5 deletions src/API/Baggage/BaggageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@

final class BaggageBuilder implements BaggageBuilderInterface
{
/** @var array<string, Entry> */
private array $entries;

/** @param array<string, Entry> $entries */
public function __construct(array $entries = [])
public function __construct(private array $entries = [])
{
$this->entries = $entries;
}

/** @inheritDoc */
Expand Down
3 changes: 1 addition & 2 deletions src/API/Baggage/BaggageBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ interface BaggageBuilderInterface
{
/**
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/baggage/api.md#set-value
* @param mixed $value
*/
public function set(string $key, $value, API\MetadataInterface $metadata = null): API\BaggageBuilderInterface;
public function set(string $key, mixed $value, API\MetadataInterface $metadata = null): API\BaggageBuilderInterface;

/**
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/baggage/api.md#remove-value
Expand Down
20 changes: 3 additions & 17 deletions src/API/Baggage/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,13 @@

final class Entry
{
/** @var mixed */
private $value;

private MetadataInterface $metadata;

/**
* @param mixed $value
* @param MetadataInterface $metadata
*/
public function __construct(
$value,
MetadataInterface $metadata
private mixed $value,
private MetadataInterface $metadata,
) {
$this->value = $value;
$this->metadata = $metadata;
}

/**
* @return mixed
*/
public function getValue()
public function getValue(): mixed
{
return $this->value;
}
Expand Down
5 changes: 1 addition & 4 deletions src/API/Baggage/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ public static function getEmpty(): Metadata
return self::$instance ??= new self('');
}

private string $metadata;

public function __construct(string $metadata)
public function __construct(private string $metadata)
{
$this->metadata = $metadata;
}

public function getValue(): string
Expand Down
10 changes: 4 additions & 6 deletions src/API/Baggage/Propagation/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ final class Parser
private const EXCLUDED_VALUE_CHARS = [' ', '"', ',', ';', '\\'];
private const EQUALS = '=';

/** @readonly */
private string $baggageHeader;

public function __construct(string $baggageHeader)
{
$this->baggageHeader = $baggageHeader;
public function __construct(
/** @readonly */
private string $baggageHeader,
) {
}

public function parseInto(BaggageBuilderInterface $baggageBuilder): void
Expand Down
5 changes: 1 addition & 4 deletions src/API/Behavior/Internal/LogWriter/Psr3LogWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

class Psr3LogWriter implements LogWriterInterface
{
private LoggerInterface $logger;

public function __construct(LoggerInterface $logger)
public function __construct(private LoggerInterface $logger)
{
$this->logger = $logger;
}

public function write($level, string $message, array $context): void
Expand Down
1 change: 1 addition & 0 deletions src/API/Behavior/Internal/LogWriterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function create(): LogWriterInterface
return new Psr3LogWriter($logger);
}
error_log('OpenTelemetry: cannot use OTEL_PHP_LOG_DESTINATION=psr3 without providing a PSR-3 logger');

//default to error log
return new ErrorLogWriter();
case 'error_log':
Expand Down
17 changes: 4 additions & 13 deletions src/API/Globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,12 @@ final class Globals
private static array $initializers = [];
private static ?self $globals = null;

private TracerProviderInterface $tracerProvider;
private MeterProviderInterface $meterProvider;
private TextMapPropagatorInterface $propagator;
private LoggerProviderInterface $loggerProvider;

public function __construct(
TracerProviderInterface $tracerProvider,
MeterProviderInterface $meterProvider,
LoggerProviderInterface $loggerProvider,
TextMapPropagatorInterface $propagator
private TracerProviderInterface $tracerProvider,
private MeterProviderInterface $meterProvider,
private LoggerProviderInterface $loggerProvider,
private TextMapPropagatorInterface $propagator,
) {
$this->tracerProvider = $tracerProvider;
$this->meterProvider = $meterProvider;
$this->loggerProvider = $loggerProvider;
$this->propagator = $propagator;
}

public static function tracerProvider(): TracerProviderInterface
Expand Down
Loading

0 comments on commit f798bb6

Please sign in to comment.