Skip to content

Commit

Permalink
drop php 8.0 support (#1256)
Browse files Browse the repository at this point in the history
* bump php to 8.1, apply rector
* readonly and typehints
* suppress a dodgy readonly property conversion
* remove some redundant readonly phpdocs
* dont run workflows against 8.0
* more readonly and typehints
* phpdoc reformat
* typehints
* remove php81 polyfill
* revert a rector BC breaking change, and disable that rector for ParentBased
  • Loading branch information
brettmc authored Mar 14, 2024
1 parent 1753fbe commit 4cb0499
Show file tree
Hide file tree
Showing 158 changed files with 393 additions and 639 deletions.
4 changes: 2 additions & 2 deletions .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: ['8.0', '8.1', '8.2', '8.3']
php-version: ['8.1', '8.2', '8.3']
experimental: [false]
composer_args: [""]
include:
Expand Down Expand Up @@ -138,5 +138,5 @@ jobs:
needs: php
with:
matrix_extension: '["ast, json, grpc"]'
matrix_php_version: '["8.0", "8.1", "8.2", "8.3"]'
matrix_php_version: '["8.1", "8.2", "8.3"]'
install_directory: '~/.test/.packages'
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' => '8.0',
'target_php_version' => '8.1',

// If enabled, missing properties will be created when
// they are first seen. If false, we'll report an
Expand Down
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"readme": "./README.md",
"license": "Apache-2.0",
"require": {
"php": "^8.0",
"ext-json": "*",
"php": "^8.1",
"google/protobuf": "^3.22",
"php-http/discovery": "^1.14",
"psr/http-client-implementation": "^1.0",
Expand All @@ -17,7 +16,6 @@
"psr/http-message": "^1.0.1|^2.0",
"psr/log": "^1.1|^2.0|^3.0",
"symfony/polyfill-mbstring": "^1.23",
"symfony/polyfill-php81": "^1.26",
"symfony/polyfill-php82": "^1.26"
},
"config": {
Expand Down
21 changes: 16 additions & 5 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
declare(strict_types=1);

use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
use Rector\CodeQuality\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\Config\RectorConfig;
use Rector\Php81\Rector\ClassMethod\NewInInitializerRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\ValueObject\PhpVersion;
use Rector\Set\ValueObject\SetList;

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

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

$rectorConfig->sets([
SetList::PHP_80,
SetList::PHP_81,
SetList::CODE_QUALITY,
]);
$rectorConfig->skip([
Expand All @@ -25,8 +30,14 @@
__DIR__ . '/src/SDK/SdkAutoloader.php',
],
FlipTypeControlToUseExclusiveTypeRector::class,
\Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector::class,
\Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector::class,
\Rector\CodeQuality\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector::class,
NewInInitializerRector::class => [
__DIR__ . '/src/SDK/Trace/Sampler/ParentBased.php',
],
ReadOnlyPropertyRector::class => [
__DIR__ . '/src/SDK/Metrics/Stream/SynchronousMetricStream.php',
],
DisallowedEmptyRuleFixerRector::class,
ExplicitBoolCompareRector::class,
LocallyCalledStaticMethodToNonStaticRector::class,
]);
};
2 changes: 1 addition & 1 deletion src/API/Baggage/Baggage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function getEmpty(): BaggageInterface
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/API/Baggage/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
final class Entry
{
public function __construct(
private mixed $value,
private MetadataInterface $metadata,
private readonly mixed $value,
private readonly MetadataInterface $metadata,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/API/Baggage/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static function getEmpty(): Metadata
return self::$instance ??= new self('');
}

public function __construct(private string $metadata)
public function __construct(private readonly string $metadata)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/API/Baggage/Propagation/BaggagePropagator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function inject(&$carrier, PropagationSetterInterface $setter = null, Con

/** @var Entry $entry */
foreach ($baggage->getAll() as $key => $entry) {
$value = urlencode($entry->getValue());
$value = urlencode((string) $entry->getValue());
$headerString.= "{$key}={$value}";

if (($metadata = $entry->getMetadata()->getValue()) !== '' && ($metadata = $entry->getMetadata()->getValue()) !== '0') {
Expand Down
3 changes: 1 addition & 2 deletions src/API/Baggage/Propagation/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ final class Parser
private const EQUALS = '=';

public function __construct(
/** @readonly */
private string $baggageHeader,
private readonly string $baggageHeader,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/API/Behavior/Internal/LogWriter/Psr3LogWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Psr3LogWriter implements LogWriterInterface
{
public function __construct(private LoggerInterface $logger)
public function __construct(private readonly LoggerInterface $logger)
{
}

Expand Down
8 changes: 4 additions & 4 deletions src/API/Globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ final class Globals
private static ?self $globals = null;

public function __construct(
private TracerProviderInterface $tracerProvider,
private MeterProviderInterface $meterProvider,
private LoggerProviderInterface $loggerProvider,
private TextMapPropagatorInterface $propagator,
private readonly TracerProviderInterface $tracerProvider,
private readonly MeterProviderInterface $meterProvider,
private readonly LoggerProviderInterface $loggerProvider,
private readonly TextMapPropagatorInterface $propagator,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/API/Instrumentation/CachedInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ final class CachedInstrumentation
* @psalm-suppress PropertyTypeCoercion
*/
public function __construct(
private string $name,
private ?string $version = null,
private ?string $schemaUrl = null,
private iterable $attributes = [],
private readonly string $name,
private readonly ?string $version = null,
private readonly ?string $schemaUrl = null,
private readonly iterable $attributes = [],
) {
$this->tracers = new \WeakMap();
$this->meters = new \WeakMap();
Expand Down
4 changes: 2 additions & 2 deletions src/API/Logs/EventLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
class EventLogger implements EventLoggerInterface
{
public function __construct(
private LoggerInterface $logger,
private string $domain,
private readonly LoggerInterface $logger,
private readonly string $domain,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/API/Trace/NonRecordingSpan.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
final class NonRecordingSpan extends Span
{
public function __construct(private SpanContextInterface $context)
public function __construct(private readonly SpanContextInterface $context)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/API/Trace/NoopSpanBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class NoopSpanBuilder implements SpanBuilderInterface
{
private ContextInterface|false|null $parentContext = null;

public function __construct(private ContextStorageInterface $contextStorage)
public function __construct(private readonly ContextStorageInterface $contextStorage)
{
}

Expand Down
8 changes: 4 additions & 4 deletions src/API/Trace/SpanContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ final class SpanContext implements SpanContextInterface
* @see https://www.w3.org/TR/trace-context/#trace-flags
* @see https://www.w3.org/TR/trace-context/#sampled-flag
*/
private bool $isSampled;
private readonly bool $isSampled;
private bool $isValid = true;

private function __construct(
private string $traceId,
private string $spanId,
private int $traceFlags,
private bool $isRemote,
private ?TraceStateInterface $traceState = null,
private readonly int $traceFlags,
private readonly bool $isRemote,
private readonly ?TraceStateInterface $traceState = null,
) {
// TraceId must be exactly 16 bytes (32 chars) and at least one non-zero byte
// SpanId must be exactly 8 bytes (16 chars) and at least one non-zero byte
Expand Down
4 changes: 1 addition & 3 deletions src/API/Trace/TraceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class TraceState implements TraceStateInterface
private const VALID_VALUE_BASE_REGEX = '/^[ -~]{0,255}[!-~]$/';
private const INVALID_VALUE_COMMA_EQUAL_REGEX = '/,|=/';

/**
* @var string[]
*/
/** @var string[] */
private array $traceState = [];

public function __construct(string $rawTracestate = null)
Expand Down
3 changes: 1 addition & 2 deletions src/API/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"open-telemetry/context": "^1.0",
"psr/log": "^1.1|^2.0|^3.0",
"symfony/polyfill-php81": "^1.26",
"symfony/polyfill-php82": "^1.26"
},
"conflict": {
Expand Down
15 changes: 3 additions & 12 deletions src/Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ final class Context implements ContextInterface
{
private const OTEL_PHP_DEBUG_SCOPES_DISABLED = 'OTEL_PHP_DEBUG_SCOPES_DISABLED';

/** @var ContextStorageInterface&ExecutionContextAwareInterface */
private static ContextStorageInterface $storage;
private static ContextStorageInterface&ExecutionContextAwareInterface $storage;

// Optimization for spans to avoid copying the context array.
private static ContextKeyInterface $spanContextKey;
Expand All @@ -37,20 +36,12 @@ public static function createKey(string $key): ContextKeyInterface
return new ContextKey($key);
}

/**
* @param ContextStorageInterface&ExecutionContextAwareInterface $storage
* @todo update type-hint (php >= 8.1)
*/
public static function setStorage(ContextStorageInterface $storage): void
public static function setStorage(ContextStorageInterface&ExecutionContextAwareInterface $storage): void
{
self::$storage = $storage;
}

/**
* @return ContextStorageInterface&ExecutionContextAwareInterface
* @todo update return type-hint (php >= 8.1)
*/
public static function storage(): ContextStorageInterface
public static function storage(): ContextStorageInterface&ExecutionContextAwareInterface
{
/** @psalm-suppress RedundantPropertyInitializationCheck */
return self::$storage ??= new ContextStorage();
Expand Down
2 changes: 1 addition & 1 deletion src/Context/ContextKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
final class ContextKey implements ContextKeyInterface
{
public function __construct(private ?string $name = null)
public function __construct(private readonly ?string $name = null)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/Context/ContextStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ public function __construct()
$this->current = $this->main = new ContextStorageHead($this);
}

public function fork($id): void
public function fork(int|string $id): void
{
$this->forks[$id] = clone $this->current;
}

public function switch($id): void
public function switch(int|string $id): void
{
$this->current = $this->forks[$id] ?? $this->main;
}

public function destroy($id): void
public function destroy(int|string $id): void
{
unset($this->forks[$id]);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Context/DebugScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ final class DebugScope implements ScopeInterface
{
private static bool $shutdownHandlerInitialized = false;
private static bool $finalShutdownPhase = false;
private ?int $fiberId;
private array $createdAt;
private readonly ?int $fiberId;
private readonly array $createdAt;
private ?array $detachedAt = null;

public function __construct(private ContextStorageScopeInterface $scope)
public function __construct(private readonly ContextStorageScopeInterface $scope)
{
$this->fiberId = self::currentFiberId();
$this->createdAt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
Expand Down Expand Up @@ -114,7 +114,7 @@ private static function formatBacktrace(array $trace): string
$s .= strtr($trace[$i]['function'] ?? '{main}', ['\\' => '.']);
$s .= '(';
if (isset($trace[$i - 1]['file'])) {
$s .= basename($trace[$i - 1]['file']);
$s .= basename((string) $trace[$i - 1]['file']);
if (isset($trace[$i - 1]['line'])) {
$s .= ':';
$s .= $trace[$i - 1]['line'];
Expand Down
15 changes: 3 additions & 12 deletions src/Context/ExecutionContextAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,9 @@

interface ExecutionContextAwareInterface
{
/**
* @param int|string $id
*/
public function fork($id): void;
public function fork(int|string $id): void;

/**
* @param int|string $id
*/
public function switch($id): void;
public function switch(int|string $id): void;

/**
* @param int|string $id
*/
public function destroy($id): void;
public function destroy(int|string $id): void;
}
11 changes: 4 additions & 7 deletions src/Context/FiberBoundContextStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,21 @@
*/
final class FiberBoundContextStorage implements ContextStorageInterface, ExecutionContextAwareInterface
{
/**
* @param ContextStorageInterface&ExecutionContextAwareInterface $storage
*/
public function __construct(private ContextStorageInterface $storage)
public function __construct(private readonly ContextStorageInterface&ExecutionContextAwareInterface $storage)
{
}

public function fork($id): void
public function fork(int|string $id): void
{
$this->storage->fork($id);
}

public function switch($id): void
public function switch(int|string $id): void
{
$this->storage->switch($id);
}

public function destroy($id): void
public function destroy(int|string $id): void
{
$this->storage->destroy($id);
}
Expand Down
Loading

0 comments on commit 4cb0499

Please sign in to comment.