Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stubs for ext-random (PHP 8.2) #8649

Merged
merged 1 commit into from Nov 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Psalm/Config.php
Expand Up @@ -2169,6 +2169,11 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null):
$this->internal_stubs[] = $ext_apcu_path;
}

if (extension_loaded('random')) {
$ext_random_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'ext-random.phpstub';
$this->internal_stubs[] = $ext_random_path;
}

foreach ($this->internal_stubs as $stub_path) {
if (!file_exists($stub_path)) {
throw new UnexpectedValueException('Cannot locate ' . $stub_path);
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Expand Up @@ -1299,7 +1299,7 @@ public function refactorCodeAfterCompletion(array $to_refactor): void
*/
public function setPhpVersion(string $version, string $source): void
{
if (!preg_match('/^(5\.[456]|7\.[01234]|8\.[01])(\..*)?$/', $version)) {
if (!preg_match('/^(5\.[456]|7\.[01234]|8\.[012])(\..*)?$/', $version)) {
throw new UnexpectedValueException('Expecting a version number in the format x.y');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Codebase/InternalCallMapHandler.php
Expand Up @@ -37,7 +37,7 @@
class InternalCallMapHandler
{
private const PHP_MAJOR_VERSION = 8;
private const PHP_MINOR_VERSION = 1;
private const PHP_MINOR_VERSION = 2;
private const LOWEST_AVAILABLE_DELTA = 71;

/**
Expand Down
112 changes: 112 additions & 0 deletions stubs/extensions/ext-random.phpstub
@@ -0,0 +1,112 @@
<?php

/**
* PHP 8.2 introduces a new PHP extension named "random".
* @see https://github.com/php/php-src/blob/master/ext/random/random.stub.php
* @see https://php.watch/versions/8.2/ext-random
*/

namespace Random\Engine
{
final class Mt19937 implements \Random\Engine
{
public function __construct(int|null $seed = null, int $mode = MT_RAND_MT19937) {}

/** @return non-empty-string */
public function generate(): string {}

public function __serialize(): array {}

public function __unserialize(array $data): void {}

public function __debugInfo(): array {}
}

final class PcgOneseq128XslRr64 implements \Random\Engine
{
public function __construct(string|int|null $seed = null) {}

public function generate(): string {}

public function jump(int $advance): void {}

public function __serialize(): array {}

public function __unserialize(array $data): void {}

public function __debugInfo(): array {}
}

final class Xoshiro256StarStar implements \Random\Engine
{
public function __construct(string|int|null $seed = null) {}

public function generate(): string {}

public function jump(): void {}

public function jumpLong(): void {}

public function __serialize(): array {}

public function __unserialize(array $data): void {}

public function __debugInfo(): array {}
}

final class Secure implements \Random\CryptoSafeEngine
{
public function generate(): string {}
}
}

namespace Random
{
interface Engine
{
public function generate(): string;
}

interface CryptoSafeEngine extends Engine
{
}

final class Randomizer
{
public readonly Engine $engine;

public function __construct(?Engine $engine = null) {}

public function nextInt(): int {}

public function getInt(int $min, int $max): int {}

/**
* @param positive-int $length
* @return non-empty-string
*/
public function getBytes(int $length): string {}

public function shuffleArray(array $array): array {}

public function shuffleBytes(string $bytes): string {}

public function pickArrayKeys(array $array, int $num): array {}

public function __serialize(): array {}

public function __unserialize(array $data): void {}
}

class RandomError extends \Error
{
}

class BrokenRandomEngineError extends RandomError
{
}

class RandomException extends \Exception
{
}
}