Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM composer:2.3 as composer
FROM composer:2.9 as composer

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

COPY ./composer.json /tmp/src1/composer.json
COPY ./composer.lock /tmp/src1/composer.lock
Expand All @@ -12,7 +12,7 @@
RUN composer install --no-dev --no-progress --optimize-autoloader --ignore-platform-req=ext-pcntl


FROM php:8.2-apache
FROM php:8.4-apache

RUN apt-get update \
# Needed for the imagick php extension install
Expand All @@ -27,12 +27,9 @@
&& docker-php-ext-install pdo pdo_mysql \
# For rewrite rules
&& a2enmod rewrite \
# Needed for gluedev/laravel-stackdriver
&& pecl install opencensus-alpha \
&& docker-php-ext-enable opencensus \
&& rm -rf /var/lib/apt/lists/*

ENV APACHE_DOCUMENT_ROOT /var/www/html/public

Check warning on line 32 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# Change the document root
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf \
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Invitation/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Create extends Command {
*/
public function handle() {
$code = trim($this->argument('code'));
$jobResult = (new InvitationCreateJob($code))->handle();
$jobResult = new InvitationCreateJob($code)->handle();

if ($jobResult) {
$this->line('Successfully created invitation: ' . $code);
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Invitation/CreateBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle() {

for ($i = 0; $i < $numCodes; $i++) {
$code = $helper->generate();
$jobResult = (new InvitationCreateJob($code))->handle();
$jobResult = new InvitationCreateJob($code)->handle();

if ($jobResult) {
$this->line('Successfully created invitation: ' . $code);
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Invitation/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Delete extends Command {
*/
public function handle() {
$code = trim($this->argument('code'));
(new InvitationDeleteJob($code))->handle();
new InvitationDeleteJob($code)->handle();

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/RebuildQueryserviceData.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private function getEntitiesForWiki(Wiki $wiki): array {
: [];

$merged = array_merge($items, $properties, $lexemes);
$this->stripPrefixes($merged);
self::stripPrefixes($merged);

return $merged;
}
Expand All @@ -111,7 +111,7 @@ private function getSparqlUrl(Wiki $wiki): string {

private static function stripPrefixes(array &$items): void {
foreach ($items as &$item) {
$e = explode(':', $item);
$e = explode(':', (string) $item);
$item = end($e);
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Kernel extends ConsoleKernel {
/**
* Define the application's command schedule.
*/
#[\Override]
protected function schedule(Schedule $schedule): void {
// Make sure that the DB and QS pools are always populated somewhat.
// This will create at most 1 new entry for each per minute...
Expand Down Expand Up @@ -66,6 +67,7 @@ protected function schedule(Schedule $schedule): void {
/**
* Register the commands for the application.
*/
#[\Override]
protected function commands(): void {
$this->load(__DIR__ . '/Commands');
$this->load(__DIR__ . '/Commands/User');
Expand Down
1 change: 1 addition & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Handler extends ExceptionHandler {
/**
* Register the exception handling callbacks for the application.
*/
#[\Override]
public function register(): void {
$this->reportable(function (Throwable $e): void {
(new ErrorReporting)->report($e);
Expand Down
16 changes: 6 additions & 10 deletions app/Helper/DomainHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@
class DomainHelper {
// @return string - the domain name encoded in ASCII-compatible form
public static function encode($string) {
$result = idn_to_ascii($string);

// return the original input if encoding failed
if ($result === false) {
$result = $string;
$result = $string;
if (!empty($string)) {
$result = idn_to_ascii($string);
}

return $result;
}

// @return string - the domain name in Unicode, encoded in UTF-8
public static function decode($string) {
$result = idn_to_utf8($string);

// return the original input if decoding failed
if ($result === false) {
$result = $string;
$result = $string;
if (!empty($string)) {
$result = idn_to_utf8($string);
}

return $result;
Expand Down
9 changes: 2 additions & 7 deletions app/Helper/DomainValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
use Illuminate\Support\Facades\Validator;

class DomainValidator {
public array $subdomainRules;

public string $subDomainSuffix;

public function __construct(string $subDomainSuffix, array $subdomainRules) {
$this->subDomainSuffix = $subDomainSuffix;
$this->subdomainRules = $subdomainRules;
public function __construct(public string $subDomainSuffix, public array $subdomainRules)
{
}

public function getValidator($domain): \Illuminate\Contracts\Validation\Validator {
Expand Down
11 changes: 3 additions & 8 deletions app/Helper/ElasticSearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
use App\Http\Curl\HttpRequest;

class ElasticSearchHelper {
private $elasticSearchHost;

private $elasticSearchBaseName;

public function __construct(string $elasticSearchHost, string $elasticSearchBaseName) {
$this->elasticSearchHost = $elasticSearchHost;
$this->elasticSearchBaseName = $elasticSearchBaseName;
public function __construct(private readonly string $elasticSearchHost, private readonly string $elasticSearchBaseName)
{
}

public function hasIndices(HttpRequest $request): bool {
Expand Down Expand Up @@ -44,7 +39,7 @@ public function hasIndices(HttpRequest $request): bool {
// index\n
// site1.localhost_content_blabla\n
// site1.localhost_general_bla\n
$wikiIndices = array_filter(explode("\n", $rawResponse));
$wikiIndices = array_filter(explode("\n", (string) $rawResponse));

// no indices to delete only index header
if (count($wikiIndices) <= 1) {
Expand Down
10 changes: 2 additions & 8 deletions app/Helper/InviteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@
namespace App\Helper;

class InviteHelper {
private $segments;

private $segmentLength;

private $prefix;

public function __construct(int $numSegments = 2, int $segmentLength = 4) {
public function __construct(private readonly int $segments = 2, private readonly int $segmentLength = 4) {
$this->prefix = 'wbcloud-';
$this->segments = $numSegments;
$this->segmentLength = $segmentLength;
}

private function generateSegment(int &$counter): string {
$segment = '';

for ($i = 0; $i < $this->segmentLength; $i++) {
$segment .= rand(0, 9);
$segment .= random_int(0, 9);
}

$counter++;
Expand Down
2 changes: 1 addition & 1 deletion app/Helper/MWTimestampHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Carbon\Exceptions\InvalidFormatException;

class MWTimestampHelper {
private const MWTimestampFormat = 'YmdHis';
private const string MWTimestampFormat = 'YmdHis';

public static function getCarbonFromMWTimestamp(string $MWTimestamp): CarbonImmutable {
$carbon = CarbonImmutable::createFromFormat(self::MWTimestampFormat, $MWTimestamp);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function deleteLogin(Request $request) {
return response()
->json()
->setStatusCode(204)
->withCookie($this->deleteCookie());
->withCookie(self::deleteCookie());
}

public function postLogin(Request $request): ?JsonResponse {
Expand Down Expand Up @@ -84,7 +84,7 @@ public function postLogin(Request $request): ?JsonResponse {
return response()->json([
'user' => $user, // <- we're sending the user info for frontend usage
])->withCookie(
$this->getCookie($user->createToken('yourAppName')->accessToken)
self::getCookie($user->createToken('yourAppName')->accessToken)
);
} else {
$this->incrementLoginAttempts($request);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public function register(Request $request) {

$user = null;
DB::transaction(function () use (&$user, $request): void {
$user = (new UserCreateJob(
$user = new UserCreateJob(
$request->input('email'),
$request->input('password')
))->handle();
)->handle();
(UserVerificationCreateTokenAndSendJob::newForAccountCreation($user))->handle();
});

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Backend/MediaWikiHostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function getWikiHostsForDomain(Request $request): JsonResponse {
$domain = $request->query('domain');
try {
$hosts = $mediawikiHostResolver->getHostsForDomain($domain);
} catch (UnknownWikiDomainException $e) {
} catch (UnknownWikiDomainException) {
return response()->json(['error' => 'Domain not found.'], 404);
} catch (UnknownDBVersionException $e) {
} catch (UnknownDBVersionException) {
return response()->json(['error' => 'Unknown database version.'], 500);
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Backend/QsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getBatches(Request $request): Response {

public function markBatchesDone(Request $request): Response {
$batches = (array) $request->json()->all('batches');
QsBatch::whereIn('id', $batches)->increment(
QsBatch::whereIn('id')->increment(
'processing_attempts', 1,
['done' => 1, 'pending_since' => null]
);
Expand All @@ -46,7 +46,7 @@ public function markBatchesDone(Request $request): Response {

public function markBatchesNotDone(Request $request): Response {
$batches = (array) $request->json()->all('batches');
QsBatch::whereIn('id', $batches)->increment(
QsBatch::whereIn('id')->increment(
'processing_attempts', 1,
['done' => 0, 'pending_since' => null]
);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/ComplaintController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function sendMessage(Request $request): JsonResponse {
* Get a validator for an incoming complaint report page request.
*/
protected function validator(array $data): \Illuminate\Contracts\Validation\Validator {
$data['name'] = $data['name'] ?? '';
$data['email'] = $data['email'] ?? '';
$data['name'] ??= '';
$data['email'] ??= '';

$validation = [
'recaptcha' => ['required', 'string', 'bail', $this->recaptchaValidation],
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/ConversionMetricController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function index(Request $request) {
private function returnCsv($output) {
ob_start();
$handle = fopen('php://output', 'r+');
fputcsv($handle, ['domain_name', 'time_to_engage_days', 'time_before_wiki_abandoned_days', 'number_of_active_editors', 'wiki_creation_time', 'first_edited_time', 'last_edited_time']);
fputcsv($handle, ['domain_name', 'time_to_engage_days', 'time_before_wiki_abandoned_days', 'number_of_active_editors', 'wiki_creation_time', 'first_edited_time', 'last_edited_time'], escape: '\\');
foreach ($output as $wikiMetrics) {
fputcsv($handle, array_values($wikiMetrics));
fputcsv($handle, array_values($wikiMetrics), escape: '\\');
}
$csv = ob_get_clean();

Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/DeletedWikiMetricsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ private function returnCsv($output) {
'number_of_users_for_wiki',
'wiki_creation_time',
'wiki_deletion_time',
]);
],
escape: '\\');
foreach ($output as $deletedWikiMetrics) {
fputcsv($handle, array_values($deletedWikiMetrics));
fputcsv($handle, array_values($deletedWikiMetrics), escape: '\\');
}
$csv = ob_get_clean();

Expand Down
20 changes: 8 additions & 12 deletions app/Http/Controllers/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@
use Illuminate\Validation\Rule;

class WikiController extends Controller {
private $domainValidator;

private $profileValidator;

public function __construct(DomainValidator $domainValidator, ProfileValidator $profileValidator) {
$this->profileValidator = $profileValidator;
$this->domainValidator = $domainValidator;
public function __construct(private readonly DomainValidator $domainValidator, private readonly ProfileValidator $profileValidator)
{
}

public function create(Request $request): Response {
Expand All @@ -46,16 +41,17 @@ public function create(Request $request): Response {
}
$user = $request->user();

$submittedDomain = strtolower($request->input('domain'));
$submittedDomain = strtolower((string) $request->input('domain'));
$submittedDomain = DomainHelper::encode($submittedDomain);

$domainValidator = $this->domainValidator->getValidator($submittedDomain);
$isSubdomain = $this->isSubDomain($submittedDomain);
$isSubdomain = static::isSubDomain($submittedDomain);

$domainValidator->validateWithBag('post');

// TODO extra validation that username is correct?
$request->validate([
'domain' => 'required',
'sitename' => 'required|min:3',
'username' => 'required',
'profile' => 'nullable|json',
Expand All @@ -72,7 +68,7 @@ public function create(Request $request): Response {

$rawProfile = false;
if ($request->filled('profile')) {
$rawProfile = json_decode($request->input('profile'), true);
$rawProfile = json_decode((string) $request->input('profile'), true);
$profileValidator = $this->profileValidator->getValidator($rawProfile);
$profileValidator->validateWithBag('post');
}
Expand Down Expand Up @@ -240,8 +236,8 @@ public function getWikiDetailsForIdForOwner(Request $request): Response {
}

public static function isSubDomain(string $domain, ?string $subDomainSuffix = null): bool {
$subDomainSuffix = $subDomainSuffix ?? Config::get('wbstack.subdomain_suffix');
$subDomainSuffix ??= Config::get('wbstack.subdomain_suffix');

return preg_match('/' . preg_quote($subDomainSuffix) . '$/', $domain) === 1;
return preg_match('/' . preg_quote((string) $subDomainSuffix) . '$/', $domain) === 1;
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/WikiEntityImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use Prometheus\Counter;

class WikiEntityImportController extends Controller {
private Counter $successfulCounter;
private readonly Counter $successfulCounter;

private Counter $failedCounter;
private readonly Counter $failedCounter;

public function __construct(CollectorRegistry $registry) {
$this->successfulCounter = $registry->getOrRegisterCounter(
Expand Down Expand Up @@ -75,7 +75,7 @@ public function create(Request $request): JsonResponse {
wikiId: $wiki->id,
sourceWikiUrl: $validatedInput['source_wiki_url'],
importId: $import->id,
entityIds: explode(',', $validatedInput['entity_ids']),
entityIds: explode(',', (string) $validatedInput['entity_ids']),
));

return response()->json(['data' => $import]);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/WikiLogoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function update(Request $request) {
$wiki = $request->attributes->get('wiki');

// run the job to set the wiki logo
(new SetWikiLogo('id', $wiki->id, $request->file('logo')->getRealPath()))->handle();
new SetWikiLogo('id', $wiki->id, $request->file('logo')->getRealPath())->handle();

// get the logo URL from the settings
$wgLogoSetting = $wiki->settings()->firstWhere(['name' => WikiSetting::wgLogo])->value;
Expand Down
Loading
Loading