Skip to content

Commit

Permalink
transpile #769
Browse files Browse the repository at this point in the history
Transpile fixes and updates from main branch.
  • Loading branch information
lucatume committed Dec 9, 2024
1 parent 95ce98c commit dcbdd93
Show file tree
Hide file tree
Showing 46 changed files with 215 additions and 113 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Fixed

- Ensure plugin activation is respected indifferent of plugins that might deactivate others during activation.

## [3.7.10] 2024-11-29;

## Fixed
Expand Down
1 change: 1 addition & 0 deletions config/typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extend-exclude = [
".git/",
"includes/",
"vendor/",
"tests/_data"
]
ignore-hidden = false

Expand Down
2 changes: 1 addition & 1 deletion includes/opis/closure/src/ReflectionClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ReflectionClosure extends ReflectionFunction
*
* @throws \ReflectionException
*/
public function __construct(Closure $closure, string $code = null)
public function __construct(Closure $closure, ?string $code = null)
{
parent::__construct($closure);
}
Expand Down
4 changes: 2 additions & 2 deletions includes/opis/closure/src/SerializableClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public static function getSecurityProvider(): ?ISecurityProvider
*
* @internal
*/
public static function wrapClosures(&$data, SplObjectStorage $storage = null)
public static function wrapClosures(&$data, ?SplObjectStorage $storage = null)
{
if ($storage === null) {
$storage = static::$context->scope;
Expand Down Expand Up @@ -395,7 +395,7 @@ public static function wrapClosures(&$data, SplObjectStorage $storage = null)
*
* @internal
*/
public static function unwrapClosures(&$data, SplObjectStorage $storage = null)
public static function unwrapClosures(&$data, ?SplObjectStorage $storage = null)
{
if ($storage === null) {
$storage = static::$context->scope;
Expand Down
6 changes: 3 additions & 3 deletions src/Adapters/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class Process extends SymfonyProcess
*/
public function __construct(
array $command,
string $cwd = null,
array $env = null,
?string $cwd = null,
?array $env = null,
$input = null,
?float $timeout = 60,
array $options = null
?array $options = null
) {
parent::__construct($command, $cwd, $env, $input, $timeout, $options); //@phpstan-ignore-line

Expand Down
2 changes: 1 addition & 1 deletion src/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Dispatcher
*/
private static $eventDispatcher;

public static function setEventDispatcher(EventDispatcherInterface $eventDispatcher = null): void
public static function setEventDispatcher(?EventDispatcherInterface $eventDispatcher = null): void
{
$previousEventDispatcher = self::$eventDispatcher;

Expand Down
2 changes: 1 addition & 1 deletion src/Extension/PidBasedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function isProcessRunning(string $pidFile):bool
return false;
}

if (PHP_OS_FAMILY === 'Windows') {
if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
$output = [];
exec("tasklist /FI \"PID eq $pid\" 2>NUL", $output);

Expand Down
4 changes: 2 additions & 2 deletions src/ManagedProcess/MysqlServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MysqlServer implements ManagedProcessInterface
/**
* @throws RuntimeException
*/
public function __construct(string $directory = null, int $port = self::PORT_DEFAULT, string $database = 'wordpress', string $user = 'wordpress', string $password = 'wordpress', ?string $binary = null, ?string $shareDir = null)
public function __construct(?string $directory = null, int $port = self::PORT_DEFAULT, string $database = 'wordpress', string $user = 'wordpress', string $password = 'wordpress', ?string $binary = null, ?string $shareDir = null)
{
$this->port = $port;
$this->database = $database;
Expand Down Expand Up @@ -584,7 +584,7 @@ public function isUsingCustomBinary(): bool
return $this->usingCustomBinary;
}

public function setOutput(OutputInterface $output = null): void
public function setOutput(?OutputInterface $output = null): void
{
$this->output = $output;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Support/DbDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function getOriginalUrlFromSqlString(string $sql)
* @param string|null $originalUrl The site URL that should be replaced in the dump, or `null` to unset the
* property.
*/
public function setOriginalUrl(string $originalUrl = null): void
public function setOriginalUrl(?string $originalUrl = null): void
{
if ($originalUrl === null) {
$this->originalUrl = null;
Expand Down
6 changes: 3 additions & 3 deletions src/Module/WPBrowserMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function _initialize(): void
*
* @return FacebookWebdriverCookie|Cookie|null The WordPress authorization cookie or `null` if not found.
*/
protected function grabWordPressAuthCookie(string $pattern = null)
protected function grabWordPressAuthCookie(?string $pattern = null)
{
$pattern = $pattern ?: '/^wordpress_[a-z0-9]{32}$/';
$cookies = $this->grabCookiesWithPattern($pattern);
Expand All @@ -147,7 +147,7 @@ protected function grabWordPressAuthCookie(string $pattern = null)
*
* @return FacebookWebdriverCookie|Cookie|null The WordPress login cookie or `null` if not found.
*/
protected function grabWordPressLoginCookie(string $pattern = null)
protected function grabWordPressLoginCookie(?string $pattern = null)
{
$pattern = $pattern ?: '/^wordpress_logged_in_[a-z0-9]{32}$/';
$cookies = $this->grabCookiesWithPattern($pattern);
Expand Down Expand Up @@ -365,7 +365,7 @@ public function seeMessage($classes = ''): void
*
* @return Cookie|null Either a cookie object or `null`.
*/
public function grabWordPressTestCookie(string $name = null): ?Cookie
public function grabWordPressTestCookie(?string $name = null): ?Cookie
{
$name = $name ?: 'wordpress_test_cookie';

Expand Down
2 changes: 1 addition & 1 deletion src/Module/WPCLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function grabLastShellErrorOutput(): string
*/
public function cliToArray(
array $command,
callable $splitCallback = null,
?callable $splitCallback = null,
?array $env = null,
$input = null
): array {
Expand Down
22 changes: 11 additions & 11 deletions src/Module/WPDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class WPDb extends Db
*
* @return void
*/
public function __construct(ModuleContainer $moduleContainer, ?array $config = null, DbDump $dbDump = null)
public function __construct(ModuleContainer $moduleContainer, ?array $config = null, ?DbDump $dbDump = null)
{
parent::__construct($moduleContainer, $config);
$this->dbDump = $dbDump ?? new DbDump();
Expand Down Expand Up @@ -356,7 +356,7 @@ protected function validateConfig(): void
*
* @throws ModuleException It the database cannot be correctly initialized.
*/
public function _initialize(Tables $table = null): void
public function _initialize(?Tables $table = null): void
{
/**
* Dispatches an event before the WPDb module initializes.
Expand Down Expand Up @@ -396,7 +396,7 @@ public function _initialize(Tables $table = null): void
*
* @throws ModuleConfigException|ModuleException If there's an issue during the cleanup phase.
*/
public function importSqlDumpFile(string $dumpFile = null): void
public function importSqlDumpFile(?string $dumpFile = null): void
{
if ($dumpFile !== null) {
if (!is_file($dumpFile) || !is_readable($dumpFile)) {
Expand Down Expand Up @@ -611,8 +611,8 @@ public function dontSeePostMetaInDatabase(array $criteria): void
public function seePostWithTermInDatabase(
int $post_id,
int $term_taxonomy_id,
int $term_order = null,
string $taxonomy = null
?int $term_order = null,
?string $taxonomy = null
): void {
if ($taxonomy !== null) {
$match = $this->grabTermTaxonomyIdFromDatabase([
Expand Down Expand Up @@ -3574,7 +3574,7 @@ public function dontSeeBlogInDatabase(array $criteria): void
* @param string|null $themeName The theme name, e.g. `Acme`, defaults to the "title" version of
* `$stylesheet`.
*/
public function useTheme(string $stylesheet, string $template = null, string $themeName = null): void
public function useTheme(string $stylesheet, ?string $template = null, ?string $themeName = null): void
{
$template = $template ?: $stylesheet;
$themeName = $themeName ?: ucwords($stylesheet, ' _');
Expand Down Expand Up @@ -3654,7 +3654,7 @@ public function haveMenuInDatabase(string $slug, string $location, array $overri
public function haveMenuItemInDatabase(
string $menuSlug,
string $title,
int $menuOrder = null,
?int $menuOrder = null,
array $meta = []
): int {
if (empty($this->stylesheet)) {
Expand Down Expand Up @@ -3751,7 +3751,7 @@ public function haveAttachmentInDatabase(
string $file,
$date = 'now',
array $overrides = [],
array $imageSizes = null
?array $imageSizes = null
): int {
if (!class_exists(ImageResize::class)) {
$message = 'The "haveAttachmentInDatabase" method requires the "gumlet/php-image-resize:^1.6" package.' .
Expand Down Expand Up @@ -3902,7 +3902,7 @@ public function haveAttachmentInDatabase(
*
* @return string The current site URL
*/
public function grabSiteUrl(string $path = null): string
public function grabSiteUrl(?string $path = null): string
{
/** @var array{url: string} $config Validated module config. */
$config = $this->config;
Expand Down Expand Up @@ -4528,8 +4528,8 @@ public function _loadDump($databaseKey = null, $databaseConfig = null)
public function dontSeePostWithTermInDatabase(
int $post_id,
int $term_taxonomy_id,
int $term_order = null,
string $taxonomy = null
?int $term_order = null,
?string $taxonomy = null
): void {
if ($taxonomy !== null) {
$match = $this->grabTermTaxonomyIdFromDatabase([
Expand Down
2 changes: 1 addition & 1 deletion src/Module/WPFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public function deleteUploadedFile(string $file, $date = null): void
*
* @param string|null $dir The path to the directory to delete, relative to the uploads folder.
*/
public function cleanUploadsDir(string $dir = null, $date = null): void
public function cleanUploadsDir(?string $dir = null, $date = null): void
{
$dir = null === $dir ? $this->config['uploads'] : $this->getUploadsPath(
$dir,
Expand Down
18 changes: 12 additions & 6 deletions src/Module/WPLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public function _initialize(): void
if (empty($config['dbHost']) && strncmp($config['dbName'], codecept_root_dir(), strlen(codecept_root_dir())) === 0) {
$dbFile = (array_reverse(explode(DIRECTORY_SEPARATOR, $config['dbName']))[0]);
$dbDir = rtrim(str_replace($dbFile, '', $config['dbName']), DIRECTORY_SEPARATOR);
$db = new SqliteDatabase($dbDir, $dbFile);
$db = new SqliteDatabase($dbDir, $dbFile, $config['tablePrefix']);
} else {
$db = new MysqlDatabase(
$config['dbName'],
Expand Down Expand Up @@ -590,7 +590,7 @@ public function _beforeSuite($settings = [])
*
* @return string The absolute path to the WordPress root folder or a path within it.
*/
public function getWpRootFolder(string $path = null): string
public function getWpRootFolder(?string $path = null): string
{
return $this->installation->getWpRootDir($path);
}
Expand Down Expand Up @@ -1171,20 +1171,26 @@ private function activatePluginsTheme(array $plugins): array
$database->updateOption('stylesheet', $database->getOption('stylesheet'));
}

// Flush the cache to force the refetch of the options' value.
wp_cache_delete('alloptions', 'options');

// Do not include external plugins, it would create issues at this stage.
$pluginsDir = $this->getPluginsFolder();

return array_values(
$activePlugins = array_values(
array_filter(
$plugins,
static function (string $plugin) use ($pluginsDir) {
return is_file($pluginsDir . "/$plugin");
}
)
);

// During activation some plugins could deactivate other plugins: protect from it.
$database->updateOption('active_plugins', $activePlugins);

// Flush the cache to force the refetch of the options' value.
wp_cache_delete('alloptions', 'options');


return $activePlugins;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Module/WPLoader/FiltersGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class FiltersGroup
*/
public function __construct(
array $filters = [],
callable $removeWith = null,
callable $addWith = null
?callable $removeWith = null,
?callable $addWith = null
) {
/**
* An array detailing each filter callback, priority and arguments.
Expand Down
6 changes: 3 additions & 3 deletions src/Module/WPQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private function readQueries(): void
*
* @param wpdb|null $wpdb
*/
public function _getFilteredQueriesIterator(wpdb $wpdb = null): SetupTearDownQueriesFilter
public function _getFilteredQueriesIterator(?wpdb $wpdb = null): SetupTearDownQueriesFilter
{
if (null === $wpdb) {
$wpdb = $this->_getWpdb();
Expand Down Expand Up @@ -1029,7 +1029,7 @@ public function assertQueriesCountByStatementAndFilter(
*
* @return int The current count of performed queries.
*/
public function countQueries(wpdb $wpdb = null): int
public function countQueries(?wpdb $wpdb = null): int
{
return count($this->getQueries($wpdb));
}
Expand All @@ -1050,7 +1050,7 @@ public function countQueries(wpdb $wpdb = null): int
*
* @return array{0: string, 1: float, 2: string, 3: float, 4?: array<int|string,mixed>}[] An array of queries.
*/
public function getQueries(wpdb $wpdb = null): array
public function getQueries(?wpdb $wpdb = null): array
{
/** @var array{0: string, 1: float, 2: string, 3: float, 4?: array<int|string,mixed>}[] $logicQueries */
$logicQueries = iterator_to_array($this->_getFilteredQueriesIterator($wpdb), false);
Expand Down
6 changes: 3 additions & 3 deletions src/MonkeyPatch/FileStreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function setPatcherForFile(
string $file,
PatcherInterface $patcher,
bool $redirectOpenedPath = true,
string $context = null
?string $context = null
): void {
$fromFilePath = FS::realpath($file) ?: $file;
self::$fileToPatcherMap[$fromFilePath] = [$patcher, $redirectOpenedPath, $context ?? ''];
Expand Down Expand Up @@ -74,7 +74,7 @@ public function __destruct()
/**
* @throws MonkeyPatchingException
*/
public function stream_open(string $path, string $mode, int $options, string &$openedPath = null): bool
public function stream_open(string $path, string $mode, int $options, ?string &$openedPath = null): bool
{
self::unregister();

Expand Down Expand Up @@ -231,7 +231,7 @@ public function rename(string $from, string $to): bool
return $result;
}

public function rmdir(string $path, int $options = null): bool
public function rmdir(string $path, ?int $options = null): bool
{
static::unregister();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(string $fileContents)
/**
* @throws MonkeyPatchingException
*/
public function patch(string $fileContents, string $pathname, string $context = null): array
public function patch(string $fileContents, string $pathname, ?string $context = null): array
{
$replacementFile = MonkeyPatch::getReplacementFileName($pathname, $context ?? $this->fileContents);

Expand Down
2 changes: 1 addition & 1 deletion src/MonkeyPatch/Patchers/FileReplacementPatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(string $replacementFile)
/**
* @throws MonkeyPatchingException
*/
public function patch(string $fileContents, string $pathname, string $context = null): array
public function patch(string $fileContents, string $pathname, ?string $context = null): array
{
$replacementFileContents = file_get_contents($this->replacementFile);

Expand Down
2 changes: 1 addition & 1 deletion src/MonkeyPatch/Patchers/PatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface PatcherInterface
/**
* @return array{string, string}
*/
public function patch(string $fileContents, string $pathname, string $context = null): array;
public function patch(string $fileContents, string $pathname, ?string $context = null): array;

/**
* @return array{
Expand Down
Loading

0 comments on commit dcbdd93

Please sign in to comment.