aboutsummaryrefslogtreecommitdiff
path: root/app/Services/ExportService.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Services/ExportService.php')
-rw-r--r--app/Services/ExportService.php47
1 files changed, 19 insertions, 28 deletions
diff --git a/app/Services/ExportService.php b/app/Services/ExportService.php
index 949556700..fd5d48f72 100644
--- a/app/Services/ExportService.php
+++ b/app/Services/ExportService.php
@@ -19,17 +19,15 @@ class FreshRSS_Export_Service {
/** @var FreshRSS_TagDAO */
private $tag_dao;
- const FRSS_NAMESPACE = 'https://freshrss.org/opml';
- const TYPE_HTML_XPATH = 'HTML+XPath';
- const TYPE_XML_XPATH = 'XML+XPath';
- const TYPE_RSS_ATOM = 'rss';
+ public const FRSS_NAMESPACE = 'https://freshrss.org/opml';
+ public const TYPE_HTML_XPATH = 'HTML+XPath';
+ public const TYPE_XML_XPATH = 'XML+XPath';
+ public const TYPE_RSS_ATOM = 'rss';
/**
* Initialize the service for the given user.
- *
- * @param string $username
*/
- public function __construct($username) {
+ public function __construct(string $username) {
$this->username = $username;
$this->category_dao = FreshRSS_Factory::createCategoryDao($username);
@@ -40,10 +38,9 @@ class FreshRSS_Export_Service {
/**
* Generate OPML file content.
- *
- * @return array First item is the filename, second item is the content
+ * @return array{0:string,1:string} First item is the filename, second item is the content
*/
- public function generateOpml() {
+ public function generateOpml(): array {
$view = new FreshRSS_View();
$day = date('Y-m-d');
$view->categories = $this->category_dao->listCategories(true, true);
@@ -61,14 +58,14 @@ class FreshRSS_Export_Service {
* Both starred and labelled entries are put into a "starred" file, that’s
* why there is only one method for both.
*
+ * @phpstan-param 'S'|'T'|'ST' $type
* @param string $type must be one of:
* 'S' (starred/favourite),
* 'T' (taggued/labelled),
* 'ST' (starred or labelled)
- *
- * @return array First item is the filename, second item is the content
+ * @return array{0:string,1:string} First item is the filename, second item is the content
*/
- public function generateStarredEntries($type) {
+ public function generateStarredEntries(string $type): array {
$view = new FreshRSS_View();
$view->categories = $this->category_dao->listCategories(true);
$day = date('Y-m-d');
@@ -90,14 +87,12 @@ class FreshRSS_Export_Service {
/**
* Generate the entries file content for the given feed.
- *
* @param integer $feed_id
* @param integer $max_number_entries
- *
- * @return array|null First item is the filename, second item is the content.
+ * @return array{0:string,1:string}|null First item is the filename, second item is the content.
* It also can return null if the feed doesn’t exist.
*/
- public function generateFeedEntries(int $feed_id, int $max_number_entries) {
+ public function generateFeedEntries(int $feed_id, int $max_number_entries): ?array {
$feed = $this->feed_dao->searchById($feed_id);
if (!$feed) {
return null;
@@ -128,12 +123,10 @@ class FreshRSS_Export_Service {
/**
* Generate the entries file content for all the feeds.
- *
- * @param integer $max_number_entries
- *
- * @return array Keys are filenames and values are contents.
+ * @param int $max_number_entries
+ * @return array<string,string> Keys are filenames and values are contents.
*/
- public function generateAllFeedEntries($max_number_entries) {
+ public function generateAllFeedEntries(int $max_number_entries): array {
$feed_ids = $this->feed_dao->listFeedsIds();
$exported_files = [];
@@ -143,7 +136,7 @@ class FreshRSS_Export_Service {
continue;
}
- list($filename, $content) = $result;
+ [$filename, $content] = $result;
$exported_files[$filename] = $content;
}
@@ -152,12 +145,10 @@ class FreshRSS_Export_Service {
/**
* Compress several files in a Zip file.
- *
- * @param array $files where first item is the filename, second item is the content
- *
- * @return array First item is the zip filename, second item is the zip content
+ * @param array<string,string> $files where the key is the filename, the value is the content
+ * @return array{0:string,1:string|false} First item is the zip filename, second item is the zip content
*/
- public function zip($files) {
+ public function zip(array $files): array {
$day = date('Y-m-d');
$zip_filename = 'freshrss_' . $this->username . '_' . $day . '_export.zip';