Skip to content

Commit

Permalink
Use PHP 8.1 readonly properties (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Feb 15, 2025
1 parent c949279 commit cf16c44
Show file tree
Hide file tree
Showing 26 changed files with 138 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';

$cfg['minimum_target_php_version'] = '8.0';
$cfg['minimum_target_php_version'] = '8.1';

$cfg['directory_list'] = array_merge(
$cfg['directory_list'], [
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"requires": {
"MediaWiki": ">= 1.43.0",
"platform": {
"php": ">= 8.0"
"php": ">= 8.1"
}
},
"MessagesDirs": {
Expand Down
2 changes: 1 addition & 1 deletion includes/CreateWiki/CreateWikiLogFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CreateWikiLogFormatter extends LogFormatter {

public function __construct(
LogEntry $entry,
private LinkRenderer $linkRenderer
private readonly LinkRenderer $linkRenderer
) {
parent::__construct( $entry );
}
Expand Down
4 changes: 2 additions & 2 deletions includes/CreateWiki/SpecialCreateWiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
class SpecialCreateWiki extends FormSpecialPage {

public function __construct(
private CreateWikiDatabaseUtils $databaseUtils,
private WikiManagerFactory $wikiManagerFactory
private readonly CreateWikiDatabaseUtils $databaseUtils,
private readonly WikiManagerFactory $wikiManagerFactory
) {
parent::__construct( 'CreateWiki', 'createwiki' );
}
Expand Down
2 changes: 1 addition & 1 deletion includes/Hooks/CreateWikiHookRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CreateWikiHookRunner implements
{

public function __construct(
private HookContainer $hookContainer
private readonly HookContainer $hookContainer
) {
}

Expand Down
8 changes: 4 additions & 4 deletions includes/Hooks/Handlers/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class Main implements
UserGetReservedNamesHook
{

private Config $config;
private readonly Config $config;

public function __construct(
ConfigFactory $configFactory,
private IConnectionProvider $connectionProvider,
private CreateWikiDataFactory $dataFactory,
private RemoteWikiFactory $remoteWikiFactory
private readonly IConnectionProvider $connectionProvider,
private readonly CreateWikiDataFactory $dataFactory,
private readonly RemoteWikiFactory $remoteWikiFactory
) {
$this->config = $configFactory->makeConfig( 'CreateWiki' );
}
Expand Down
22 changes: 11 additions & 11 deletions includes/Jobs/CreateWikiJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ class CreateWikiJob extends Job {

public const JOB_NAME = 'CreateWikiJob';

private int $id;
private bool $private;
private readonly int $id;
private readonly bool $private;

private string $category;
private string $creator;
private string $dbname;
private string $language;
private string $requester;
private string $sitename;
private readonly string $category;
private readonly string $creator;
private readonly string $dbname;
private readonly string $language;
private readonly string $requester;
private readonly string $sitename;

private array $extra;
private readonly array $extra;

public function __construct(
array $params,
private WikiManagerFactory $wikiManagerFactory,
private WikiRequestManager $wikiRequestManager
private readonly WikiManagerFactory $wikiManagerFactory,
private readonly WikiRequestManager $wikiRequestManager
) {
parent::__construct( self::JOB_NAME, $params );

Expand Down
10 changes: 5 additions & 5 deletions includes/Jobs/RequestWikiAIJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ class RequestWikiAIJob extends Job {

public const JOB_NAME = 'RequestWikiAIJob';

private Config $config;
private readonly Config $config;

private int $id;
private string $reason;
private readonly int $id;
private readonly string $reason;

public function __construct(
array $params,
ConfigFactory $configFactory,
private CreateWikiHookRunner $hookRunner,
private WikiRequestManager $wikiRequestManager
private readonly CreateWikiHookRunner $hookRunner,
private readonly WikiRequestManager $wikiRequestManager
) {
parent::__construct( self::JOB_NAME, $params );

Expand Down
78 changes: 39 additions & 39 deletions includes/Jobs/RequestWikiRemoteAIJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MainConfigNames;
use MediaWiki\User\User;
use MessageLocalizer;
use Miraheze\CreateWiki\ConfigNames;
use Miraheze\CreateWiki\CreateWikiRegexConstraint;
use Miraheze\CreateWiki\Services\WikiRequestManager;
Expand All @@ -20,38 +21,29 @@ class RequestWikiRemoteAIJob extends Job {

public const JOB_NAME = 'RequestWikiRemoteAIJob';

private Config $config;
private LoggerInterface $logger;
private RequestContext $context;
private string $baseApiUrl;
private string $apiKey;

private int $id;
private string $reason;
private string $sitename;
private string $subdomain;
private string $username;
private string $language;
private bool $bio;
private bool $private;
private string $category;
private array $extraData;
private readonly Config $config;
private readonly LoggerInterface $logger;
private readonly MessageLocalizer $messageLocalizer;

private readonly string $apiKey;
private readonly string $baseApiUrl;
private readonly int $id;

public function __construct(
array $params,
ConfigFactory $configFactory,
private WikiRequestManager $wikiRequestManager,
private HttpRequestFactory $httpRequestFactory
private readonly WikiRequestManager $wikiRequestManager,
private readonly HttpRequestFactory $httpRequestFactory
) {
parent::__construct( self::JOB_NAME, $params );

$this->config = $configFactory->makeConfig( 'CreateWiki' );
$this->logger = LoggerFactory::getInstance( 'CreateWiki' );
$this->context = RequestContext::getMain();
$this->messageLocalizer = RequestContext::getMain();

$this->baseApiUrl = 'https://api.openai.com/v1';
$this->apiKey = $this->config->get( ConfigNames::OpenAIConfig )['apikey'] ?? '';

$this->baseApiUrl = 'https://api.openai.com/v1';
$this->id = $params['id'];
}

Expand Down Expand Up @@ -108,7 +100,7 @@ public function run(): bool {
);

if ( !$apiResponse ) {
$commentText = $this->context->msg( 'requestwiki-ai-error' )
$commentText = $this->messageLocalizer->msg( 'requestwiki-ai-error' )
->inContentLanguage()
->parse();

Expand All @@ -124,11 +116,11 @@ public function run(): bool {
}

if ( $apiResponse['error'] ) {
$publicCommentText = $this->context->msg( 'requestwiki-ai-error-reason' )
$publicCommentText = $this->messageLocalizer->msg( 'requestwiki-ai-error-reason' )
->inContentLanguage()
->parse();

$requestHistoryComment = $this->context->msg( 'requestwiki-ai-error-history-reason' )
$requestHistoryComment = $this->messageLocalizer->msg( 'requestwiki-ai-error-history-reason' )
->params( $apiResponse['error'] )
->inContentLanguage()
->parse();
Expand Down Expand Up @@ -170,9 +162,13 @@ public function run(): bool {
return $this->handleLiveRun( $outcome, $comment, $confidence );
}

private function handleDryRun( string $outcome, string $comment, int $confidence ): bool {
$outcomeMessage = $this->context->msg( 'requestwikiqueue-' . $outcome )->text();
$commentText = $this->context->msg( 'requestwiki-ai-decision-dryrun' )
private function handleDryRun(
string $outcome,
string $comment,
int $confidence
): bool {
$outcomeMessage = $this->messageLocalizer->msg( 'requestwikiqueue-' . $outcome )->text();
$commentText = $this->messageLocalizer->msg( 'requestwiki-ai-decision-dryrun' )
->params( $outcomeMessage, $comment, $confidence )
->inContentLanguage()
->parse();
Expand Down Expand Up @@ -204,14 +200,18 @@ private function handleDryRun( string $outcome, string $comment, int $confidence
return true;
}

private function handleLiveRun( string $outcome, string $comment, int $confidence ): bool {
private function handleLiveRun(
string $outcome,
string $comment,
int $confidence
): bool {
$systemUser = User::newSystemUser( 'CreateWiki AI' );
$commentText = $this->context->msg( 'requestwiki-ai-decision-' . $outcome )
$commentText = $this->messageLocalizer->msg( 'requestwiki-ai-decision-' . $outcome )
->params( $comment, $confidence )
->inContentLanguage()
->parse();

$unknownCommentText = $this->context->msg( 'requestwiki-ai-error' )
$unknownCommentText = $this->messageLocalizer->msg( 'requestwiki-ai-error' )
->inContentLanguage()
->parse();

Expand Down Expand Up @@ -315,18 +315,18 @@ private function queryOpenAI(
int $userRequestsNum
): ?array {
try {
$isBio = $bio ? "Yes" : "No";
$isFork = !empty( $extraData['source'] ) ? "Yes" : "No";
$isNsfw = !empty( $extraData['nsfw'] ) ? "Yes" : "No";
$isPrivate = $private ? "Yes" : "No";
$isBio = $bio ? 'Yes' : 'No';
$isFork = !empty( $extraData['source'] ) ? 'Yes' : 'No';
$isNsfw = !empty( $extraData['nsfw'] ) ? 'Yes' : 'No';
$isPrivate = $private ? 'Yes' : 'No';
$forkText = !empty( $extraData['sourceurl'] )
? "This wiki is forking from this URL: \"" .
htmlspecialchars( $extraData['sourceurl'], ENT_QUOTES ) . "\". "
: "";
? 'This wiki is forking from this URL: "' .
htmlspecialchars( $extraData['sourceurl'], ENT_QUOTES ) . '". '
: '';
$nsfwReasonText = !empty( $extraData['nsfwtext'] )
? "What type of NSFW content will it feature? \"" .
htmlspecialchars( $extraData['nsfwtext'], ENT_QUOTES ) . "\". "
: "";
? 'What type of NSFW content will it feature? "' .
htmlspecialchars( $extraData['nsfwtext'], ENT_QUOTES ) . '". '
: '';

$sanitizedReason = sprintf(
'Wiki name: "%s". Subdomain: "%s". Requester: "%s". ' .
Expand Down
8 changes: 3 additions & 5 deletions includes/Jobs/SetContainersAccessJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ class SetContainersAccessJob extends Job {

public const JOB_NAME = 'SetContainersAccessJob';

private Config $config;

private bool $isPrivate;
private readonly Config $config;
private readonly bool $isPrivate;

public function __construct(
array $params,
ConfigFactory $configFactory,
private RepoGroup $repoGroup
private readonly RepoGroup $repoGroup
) {
parent::__construct( self::JOB_NAME, $params );

$this->isPrivate = $params['private'];

$this->config = $configFactory->makeConfig( 'CreateWiki' );
}

Expand Down
2 changes: 1 addition & 1 deletion includes/RequestWiki/FormFields/DetailsWithIconField.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DetailsWithIconField extends HTMLInfoField {

private bool $fieldCheck;
private readonly bool $fieldCheck;

/** @inheritDoc */
public function __construct( $info ) {
Expand Down
6 changes: 3 additions & 3 deletions includes/RequestWiki/Handler/RestWikiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
class RestWikiRequest extends SimpleHandler {

public function __construct(
private IConnectionProvider $connectionProvider,
private CreateWikiRestUtils $restUtils,
private UserFactory $userFactory
private readonly IConnectionProvider $connectionProvider,
private readonly CreateWikiRestUtils $restUtils,
private readonly UserFactory $userFactory
) {
}

Expand Down
4 changes: 2 additions & 2 deletions includes/RequestWiki/Handler/RestWikiRequestComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
class RestWikiRequestComment extends SimpleHandler {

public function __construct(
private CreateWikiRestUtils $restUtils,
private WikiRequestManager $wikiRequestManager
private readonly CreateWikiRestUtils $restUtils,
private readonly WikiRequestManager $wikiRequestManager
) {
}

Expand Down
6 changes: 3 additions & 3 deletions includes/RequestWiki/Handler/RestWikiRequestsByUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
class RestWikiRequestsByUser extends SimpleHandler {

public function __construct(
private CreateWikiRestUtils $restUtils,
private UserFactory $userFactory,
private WikiRequestManager $wikiRequestManager
private readonly CreateWikiRestUtils $restUtils,
private readonly UserFactory $userFactory,
private readonly WikiRequestManager $wikiRequestManager
) {
}

Expand Down
18 changes: 9 additions & 9 deletions includes/RequestWiki/RequestWikiQueuePager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class RequestWikiQueuePager extends TablePager {

public function __construct(
IContextSource $context,
private IConnectionProvider $connectionProvider,
private LanguageNameUtils $languageNameUtils,
private LinkRenderer $linkRenderer,
private UserFactory $userFactory,
private WikiRequestManager $wikiRequestManager,
private string $dbname,
private string $language,
private string $requester,
private string $status
IConnectionProvider $connectionProvider,
private readonly LanguageNameUtils $languageNameUtils,
private readonly LinkRenderer $linkRenderer,
private readonly UserFactory $userFactory,
private readonly WikiRequestManager $wikiRequestManager,
private readonly string $dbname,
private readonly string $language,
private readonly string $requester,
private readonly string $status
) {
$this->mDb = $connectionProvider->getReplicaDatabase( 'virtual-createwiki-central' );
parent::__construct( $context, $linkRenderer );
Expand Down
14 changes: 7 additions & 7 deletions includes/RequestWiki/RequestWikiRequestViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class RequestWikiRequestViewer {
private array $extraFields = [];

public function __construct(
private Config $config,
private IContextSource $context,
private CreateWikiHookRunner $hookRunner,
private LanguageNameUtils $languageNameUtils,
private PermissionManager $permissionManager,
private WikiManagerFactory $wikiManagerFactory,
private WikiRequestManager $wikiRequestManager
private readonly Config $config,
private readonly IContextSource $context,
private readonly CreateWikiHookRunner $hookRunner,
private readonly LanguageNameUtils $languageNameUtils,
private readonly PermissionManager $permissionManager,
private readonly WikiManagerFactory $wikiManagerFactory,
private readonly WikiRequestManager $wikiRequestManager
) {
}

Expand Down
6 changes: 3 additions & 3 deletions includes/RequestWiki/Specials/SpecialRequestWiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class SpecialRequestWiki extends FormSpecialPage {
private array $extraFields = [];

public function __construct(
private CreateWikiDatabaseUtils $databaseUtils,
private CreateWikiHookRunner $hookRunner,
private WikiRequestManager $wikiRequestManager
private readonly CreateWikiDatabaseUtils $databaseUtils,
private readonly CreateWikiHookRunner $hookRunner,
private readonly WikiRequestManager $wikiRequestManager
) {
parent::__construct( 'RequestWiki', 'requestwiki' );
}
Expand Down
Loading

0 comments on commit cf16c44

Please sign in to comment.