Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm.phar --threads=1",
"psalm": "psalm.phar --no-cache --threads=$(nproc)",
"psalm:update-baseline": "psalm.phar --threads=1 --update-baseline --set-baseline=tests/psalm-baseline.xml",
"psalm:clear": "psalm.phar --clear-cache && psalm.phar --clear-global-cache",
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
"test:unit": "echo 'Only testing installation of the app'"
},
"require-dev": {
Expand Down
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions lib/Cron/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ protected function run(mixed $argument): void {
*/
protected function loadFeed() {
$signature = $this->readFile('.signature');

if (!$signature) {
if ($signature === '' || $signature === null) {
throw new \Exception('Invalid signature fetched from the server');
}

Expand Down Expand Up @@ -161,6 +160,9 @@ protected function loadFeed() {
}

$feedBody = $this->readFile('.rss');
if ($feedBody === null) {
throw new \Exception('Feed body is empty');
}

// Check if the signature actually matches the downloaded content
$certificate = openssl_get_publickey(file_get_contents(__DIR__ . '/../../appinfo/certificate.crt'));
Expand All @@ -180,24 +182,27 @@ protected function loadFeed() {
}

/**
* @param string $file
* @return string
* @throws \Exception
*/
protected function readFile($file) {
protected function readFile(string $file): ?string {
$client = $this->clientService->newClient();
$response = $client->get(self::FEED_URL . $file);
if ($response->getStatusCode() !== Http::STATUS_OK) {
throw new \Exception('Could not load file');
}
return $response->getBody();
$body = $response->getBody();
if (is_resource($body)) {
$content = stream_get_contents($body);
return $content !== false ? $content : null;
}
return $body;
}

/**
* Get the list of users to notify
* @return string[]
*/
protected function getUsersToNotify() {
protected function getUsersToNotify(): array {
if (!empty($this->notifyUsers)) {
return array_keys($this->notifyUsers);
}
Expand Down
Loading