phpstan level 7 for importExportController.php (#5361)

* phpstan level 7 for importExportController.php

* Update app/Controllers/importExportController.php

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>

* Update app/Controllers/importExportController.php

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>

* Update app/Controllers/importExportController.php

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>

* Update app/Controllers/importExportController.php

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>

* phpstan level 7 for importExportController.php

* phpstan level 7 for importExportController.php

* phpstan level 7 for importExportController.php

* A few edits

---------

Co-authored-by: Luc <sanchezluc+freshrss@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
This commit is contained in:
Luc SANCHEZ
2023-05-04 21:20:32 +02:00
committed by GitHub
parent fde4e79ed0
commit aa30635f97
24 changed files with 61 additions and 45 deletions

View File

@@ -50,12 +50,18 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
*/
private static function minimumMemory($mb): void {
$mb = (int)$mb;
$ini = self::megabytes(ini_get('memory_limit'));
$ini = self::megabytes(ini_get('memory_limit') ?: '0');
if ($ini < $mb) {
ini_set('memory_limit', $mb . 'M');
}
}
/**
* @throws FreshRSS_Zip_Exception
* @throws FreshRSS_ZipMissing_Exception
* @throws Minz_ConfigurationNamespaceException
* @throws Minz_PDOConnectionException
*/
public function importFile(string $name, string $path, ?string $username = null): bool {
self::minimumMemory(256);
@@ -81,6 +87,9 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
throw new FreshRSS_Zip_Exception($result);
}
for ($i = 0; $i < $zip->numFiles; $i++) {
if ($zip->getNameIndex($i) === false) {
continue;
}
$type_zipfile = self::guessFileType($zip->getNameIndex($i));
if ('unknown' !== $type_zipfile) {
$list_files[$type_zipfile][] = $zip->getFromIndex($i);
@@ -103,6 +112,9 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
$importService = new FreshRSS_Import_Service($username);
foreach ($list_files['opml'] as $opml_file) {
if ($opml_file === false) {
continue;
}
$importService->importOpml($opml_file);
if (!$importService->lastStatus()) {
$ok = false;
@@ -114,7 +126,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
}
}
foreach ($list_files['json_starred'] as $article_file) {
if (!$this->importJson($article_file, true)) {
if (!is_string($article_file) || !$this->importJson($article_file, true)) {
$ok = false;
if (FreshRSS_Context::$isCli) {
fwrite(STDERR, 'FreshRSS error during JSON stars import' . "\n");
@@ -124,7 +136,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
}
}
foreach ($list_files['json_feed'] as $article_file) {
if (!$this->importJson($article_file)) {
if (!is_string($article_file) || !$this->importJson($article_file)) {
$ok = false;
if (FreshRSS_Context::$isCli) {
fwrite(STDERR, 'FreshRSS error during JSON feeds import' . "\n");
@@ -134,8 +146,8 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
}
}
foreach ($list_files['ttrss_starred'] as $article_file) {
$json = $this->ttrssXmlToJson($article_file);
if (!$this->importJson($json, true)) {
$json = is_string($article_file) ? $this->ttrssXmlToJson($article_file) : false;
if ($json === false || !$this->importJson($json, true)) {
$ok = false;
if (FreshRSS_Context::$isCli) {
fwrite(STDERR, 'FreshRSS error during TT-RSS articles import' . "\n");
@@ -222,7 +234,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
*/
private function ttrssXmlToJson(string $xml) {
$table = (array)simplexml_load_string($xml, null, LIBXML_NOBLANKS | LIBXML_NOCDATA);
$table['items'] = isset($table['article']) ? $table['article'] : array();
$table['items'] = $table['article'] ?? [];
unset($table['article']);
for ($i = count($table['items']) - 1; $i >= 0; $i--) {
$item = (array)($table['items'][$i]);
@@ -232,7 +244,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
});
$item['updated'] = isset($item['updated']) ? strtotime($item['updated']) : '';
$item['published'] = $item['updated'];
$item['content'] = array('content' => isset($item['content']) ? $item['content'] : '');
$item['content'] = ['content' => $item['content'] ?? ''];
$item['categories'] = isset($item['tag_cache']) ? array($item['tag_cache']) : array();
if (!empty($item['marked'])) {
$item['categories'][] = 'user/-/state/com.google/starred';
@@ -250,12 +262,12 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
}
}
}
$item['alternate'][0]['href'] = isset($item['link']) ? $item['link'] : '';
$item['origin'] = array(
'title' => isset($item['feed_title']) ? $item['feed_title'] : '',
'feedUrl' => isset($item['feed_url']) ? $item['feed_url'] : '',
);
$item['id'] = isset($item['guid']) ? $item['guid'] : (isset($item['feed_url']) ? $item['feed_url'] : $item['published']);
$item['alternate'][0]['href'] = $item['link'] ?? '';
$item['origin'] = [
'title' => $item['feed_title'] ?? '',
'feedUrl' => $item['feed_url'] ?? '',
];
$item['id'] = $item['guid'] ?? ($item['feed_url'] ?? $item['published']);
$item['guid'] = $item['id'];
$table['items'][$i] = $item;
}
@@ -268,6 +280,8 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
* $article_file the JSON file content.
* true if articles from the file must be starred.
* @return bool false if an error occurred, true otherwise.
* @throws Minz_ConfigurationNamespaceException
* @throws Minz_PDOConnectionException
*/
private function importJson(string $article_file, bool $starred = false): bool {
$article_object = json_decode($article_file, true);
@@ -279,7 +293,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
}
return false;
}
$items = isset($article_object['items']) ? $article_object['items'] : $article_object;
$items = $article_object['items'] ?? $article_object;
$mark_as_read = FreshRSS_Context::$user_conf->mark_when['reception'] ? 1 : 0;
@@ -319,7 +333,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
$feed = new FreshRSS_Feed($feedUrl);
$feed = $this->feedDAO->searchByUrl($feed->url());
if ($feed == null) {
if ($feed === null) {
// Feed does not exist in DB,we should to try to add it.
if ((!FreshRSS_Context::$isCli) && ($nb_feeds >= $limits['max_feeds'])) {
// Oops, no more place!
@@ -328,7 +342,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
$feed = $this->addFeedJson($item['origin']);
}
if ($feed == null) {
if ($feed === null) {
// Still null? It means something went wrong.
$error = true;
} else {
@@ -346,7 +360,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
}
$tagDAO = FreshRSS_Factory::createTagDao();
$labels = $tagDAO->listTags();
$labels = $tagDAO->listTags() ?: [];
$knownLabels = array();
foreach ($labels as $label) {
$knownLabels[$label->name()]['id'] = $label->id();
@@ -371,7 +385,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
}
$feed_id = $article_to_feed[$item['guid']];
$author = isset($item['author']) ? $item['author'] : '';
$author = $item['author'] ?? '';
$is_starred = null; // null is used to preserve the current state if that item exists and is already starred
$is_read = null;
$tags = empty($item['categories']) ? array() : $item['categories'];
@@ -451,15 +465,13 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
}
$newGuids[$entry->guid()] = true;
/** @var FreshRSS_Entry|null */
$entry = Minz_ExtensionManager::callHook('entry_before_insert', $entry);
if ($entry == null) {
if (!($entry instanceof FreshRSS_Entry)) {
// An extension has returned a null value, there is nothing to insert.
continue;
}
$values = $entry->toArray();
$ok = false;
if (isset($existingHashForGuids['f_' . $feed_id][$entry->guid()])) {
$ok = $this->entryDAO->updateEntry($values);
} else {
@@ -625,7 +637,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
$nb_files = count($exported_files);
if ($nb_files <= 0) {
// Theres nothing to do, therere no files to export
// Theres nothing to do, there are no files to export
Minz_Request::forward(['c' => 'importExport', 'a' => 'index'], true);
return;
}
@@ -648,6 +660,11 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {
[$filename, $content] = $export_service->zip($exported_files);
}
if (!is_string($content)) {
Minz_Request::bad(_t('feedback.import_export.zip_error'), ['c' => 'importExport', 'a' => 'index']);
return;
}
$content_type = self::filenameToContentType($filename);
header('Content-Type: ' . $content_type);
header('Content-disposition: attachment; filename="' . $filename . '"');

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Vaše kanály byly naimportovány, došlo ale k nějakým chybám',
'file_cannot_be_uploaded' => 'Soubor nelze nahrát!',
'no_zip_extension' => 'Na serveru není přítomno rozšíření ZIP.',
'zip_error' => 'Během importu ZIP došlo k chybě.',
'zip_error' => 'Během importu ZIP došlo k chybě.', // DIRTY
),
'profile' => array(
'error' => 'Váš profil nelze změnit',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Ihre Feeds sind importiert worden, aber es traten einige Fehler auf',
'file_cannot_be_uploaded' => 'Die Datei kann nicht hochgeladen werden!',
'no_zip_extension' => 'Die ZIP-Erweiterung ist auf Ihrem Server nicht vorhanden.',
'zip_error' => 'Ein Fehler trat während des ZIP-Imports auf.',
'zip_error' => 'Ein Fehler trat während des ZIP-Imports auf.', // DIRTY
),
'profile' => array(
'error' => 'Ihr Profil kann nicht geändert werden',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Your feeds have been imported, but some errors occurred', // TODO
'file_cannot_be_uploaded' => 'File cannot be uploaded!', // TODO
'no_zip_extension' => 'The ZIP extension is not present on your server.', // TODO
'zip_error' => 'An error occurred during ZIP import.', // TODO
'zip_error' => 'An error occurred during ZIP processing.', // TODO
),
'profile' => array(
'error' => 'Your profile cannot be modified', // TODO

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Your feeds have been imported, but some errors occurred', // IGNORE
'file_cannot_be_uploaded' => 'File cannot be uploaded!', // IGNORE
'no_zip_extension' => 'The ZIP extension is not present on your server.', // IGNORE
'zip_error' => 'An error occurred during ZIP import.', // IGNORE
'zip_error' => 'An error occurred during ZIP processing.', // IGNORE
),
'profile' => array(
'error' => 'Your profile cannot be modified', // IGNORE

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Your feeds have been imported, but some errors occurred',
'file_cannot_be_uploaded' => 'File cannot be uploaded!',
'no_zip_extension' => 'The ZIP extension is not present on your server.',
'zip_error' => 'An error occurred during ZIP import.',
'zip_error' => 'An error occurred during ZIP processing.',
),
'profile' => array(
'error' => 'Your profile cannot be modified',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Se importaron tus fuentes; pero hubo algunos errores',
'file_cannot_be_uploaded' => 'No es posible enviar el archivo',
'no_zip_extension' => 'La extensión ZIP no está disponible en tu servidor.',
'zip_error' => 'Hubo un error durante la importación ZIP.',
'zip_error' => 'Hubo un error durante la importación ZIP.', // DIRTY
),
'profile' => array(
'error' => 'Tu perfil no puede ser modificado',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Vos flux ont été importés mais des erreurs sont survenues.',
'file_cannot_be_uploaded' => 'Le fichier ne peut pas être téléchargé !',
'no_zip_extension' => 'Lextension ZIP nest pas présente sur votre serveur.',
'zip_error' => 'Une erreur est survenue durant limport du fichier ZIP.',
'zip_error' => 'Une erreur est survenue durant le traintement du fichier ZIP.',
),
'profile' => array(
'error' => 'Votre profil na pas pu être mis à jour',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'ההזנות שלך יובאו אך אירעו מספר שגיאות',
'file_cannot_be_uploaded' => 'אין אפשרות להעלות את הקובץ!',
'no_zip_extension' => 'הרחבת ZIP אינה מותקנת על השרת.',
'zip_error' => 'אירעה שגיאה במהלך ייבוא קובץ הZIP.',
'zip_error' => 'אירעה שגיאה במהלך ייבוא קובץ הZIP.', // DIRTY
),
'profile' => array(
'error' => 'Your profile cannot be modified', // TODO

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Your feeds have been imported, but some errors occurred', // TODO
'file_cannot_be_uploaded' => 'File cannot be uploaded!', // TODO
'no_zip_extension' => 'The ZIP extension is not present on your server.', // TODO
'zip_error' => 'An error occurred during ZIP import.', // TODO
'zip_error' => 'An error occurred during ZIP processing.', // TODO
),
'profile' => array(
'error' => 'Your profile cannot be modified', // TODO

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'I tuoi feeds sono stati importati ma si sono verificati alcuni errori',
'file_cannot_be_uploaded' => 'Il file non può essere caricato!',
'no_zip_extension' => 'Estensione ZIP non presente sul server.',
'zip_error' => 'Si è verificato un errore importando il file ZIP',
'zip_error' => 'Si è verificato un errore importando il file ZIP', // DIRTY
),
'profile' => array(
'error' => 'Il tuo profilo non può essere modificato',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'あなたのフィードはインポートされましたが、エラーが起きました。',
'file_cannot_be_uploaded' => 'ファイルをアップロードすることはできません!',
'no_zip_extension' => 'ZIP拡張は現在あなたのサーバーに存在しません。',
'zip_error' => 'ZIPをインポートするときエラーが発生しました。',
'zip_error' => 'ZIPをインポートするときエラーが発生しました。', // DIRTY
),
'profile' => array(
'error' => 'あなたのプロフィールを変更することはできません',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => '피드를 불러왔지만, 문제가 발생했습니다',
'file_cannot_be_uploaded' => '파일을 업로드할 수 없습니다!',
'no_zip_extension' => 'ZIP 확장 기능을 서버에서 찾을 수 없습니다.',
'zip_error' => 'ZIP 파일을 불러오는 동안 문제가 발생했습니다.',
'zip_error' => 'ZIP 파일을 불러오는 동안 문제가 발생했습니다.', // DIRTY
),
'profile' => array(
'error' => '프로필을 변경할 수 없습니다',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Jūsu barotnes tika importētas, bet ir radušās dažas kļūdas',
'file_cannot_be_uploaded' => 'Failu nevar augšupielādēt!',
'no_zip_extension' => 'Jūsu serverī nav ZIP paplašinājuma.',
'zip_error' => 'ZIP importa laikā notika kļūda.',
'zip_error' => 'ZIP importa laikā notika kļūda.', // DIRTY
),
'profile' => array(
'error' => 'Jūsu profilu nevar mainīt',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Uw feeds zijn geimporteerd maar er zijn enige fouten opgetreden',
'file_cannot_be_uploaded' => 'Bestand kan niet worden verzonden!',
'no_zip_extension' => 'ZIP uitbreiding is niet aanwezig op uw server.',
'zip_error' => 'Er is een fout opgetreden tijdens het imporeren van het ZIP bestand.',
'zip_error' => 'Er is een fout opgetreden tijdens het imporeren van het ZIP bestand.', // DIRTY
),
'profile' => array(
'error' => 'Uw profiel kan niet worden aangepast',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Vòstres fluxes son estats importats mas i a agut derrors',
'file_cannot_be_uploaded' => 'Telecargament del fichièr impossible',
'no_zip_extension' => 'Lextension es pas presenta sul servidor.',
'zip_error' => 'Una error ses producha pendent limportacion del fichièr ZIP.',
'zip_error' => 'Una error ses producha pendent limportacion del fichièr ZIP.', // DIRTY
),
'profile' => array(
'error' => 'Impossible dactualizar vòstre perfil',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Kanały zostały zaimportowane, jednakże wystąpiło kilka błędów',
'file_cannot_be_uploaded' => 'Plik nie może zostać wgrany!',
'no_zip_extension' => 'Rozszerzenie ZIP nie jest dostępne na serwerze.',
'zip_error' => 'Wystąpił błąd podczas importu pliku ZIP.',
'zip_error' => 'Wystąpił błąd podczas importu pliku ZIP.', // DIRTY
),
'profile' => array(
'error' => 'Nie można modyfikować profilu',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Seus feeds foram importados, mas alguns erros ocorreram',
'file_cannot_be_uploaded' => 'Arquivo não pôde ser enviado',
'no_zip_extension' => 'extensão ZIP não está presente em seu servidor.',
'zip_error' => 'Um erro ocorreu durante a importação do arquivo ZIP.',
'zip_error' => 'Um erro ocorreu durante a importação do arquivo ZIP.', // DIRTY
),
'profile' => array(
'error' => 'Seu perfil não pode ser editado',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Ваши ленты импортированы, но возникли ошибки',
'file_cannot_be_uploaded' => 'Файл не может быть загружен!',
'no_zip_extension' => 'На вашем сервере нет расширения ZIP.',
'zip_error' => 'Ошибка возникла при импорте ZIP.',
'zip_error' => 'Ошибка возникла при импорте ZIP.', // DIRTY
),
'profile' => array(
'error' => 'Ваш профиль не может быть изменён',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Vaše kanály boli importované, ale vyskytli sa chyby',
'file_cannot_be_uploaded' => 'Súbor sa nepodarilo nahrať!',
'no_zip_extension' => 'ZIP rozšírenie sa na vašom serveri nenachádza.',
'zip_error' => 'Počas importovania ZIP sa vyskytla chyba.',
'zip_error' => 'Počas importovania ZIP sa vyskytla chyba.', // DIRTY
),
'profile' => array(
'error' => 'Váš profil nie je možné upraviť',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => 'Akışlarınız içeri aktarıldı ama bazı hatalar meydana geldi',
'file_cannot_be_uploaded' => 'Dosya yüklenemedi!',
'no_zip_extension' => 'ZIP eklentisi mevcut sunucunuzda yer almıyor.',
'zip_error' => 'ZIP içe aktarımı sırasında hata meydana geldi.',
'zip_error' => 'ZIP içe aktarımı sırasında hata meydana geldi.', // DIRTY
),
'profile' => array(
'error' => 'Profiliniz düzenlenemedi',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => '你的订阅源已导入,但发生错误',
'file_cannot_be_uploaded' => '文件未能上传!',
'no_zip_extension' => '服务器未启用 ZIP 扩展。',
'zip_error' => '导入 ZIP 文件时出错',
'zip_error' => '导入 ZIP 文件时出错', // DIRTY
),
'profile' => array(
'error' => '你的帐户无法修改',

View File

@@ -61,7 +61,7 @@ return array(
'feeds_imported_with_errors' => '你的訂閱源已導入,但發生錯誤',
'file_cannot_be_uploaded' => '文件未能上傳!',
'no_zip_extension' => '伺服器未啟用 ZIP 擴展。',
'zip_error' => '導入 ZIP 文件時出錯',
'zip_error' => '導入 ZIP 文件時出錯', // DIRTY
),
'profile' => array(
'error' => '你的帳戶修改失敗',

View File

@@ -4,7 +4,6 @@
# find . -type d -name 'vendor' -prune -o -name '*.php' -exec sh -c 'vendor/bin/phpstan analyse --level 7 --memory-limit 512M {} >/dev/null 2>/dev/null || echo {}' \;
./app/Controllers/feedController.php
./app/Controllers/importExportController.php
./app/Controllers/indexController.php
./app/Controllers/updateController.php
./app/Controllers/userController.php