Просмотр исходного кода

More PHP type hints for Fever (#4202)

* More PHP type hints for Fever
Follow-up of https://github.com/FreshRSS/FreshRSS/pull/4201
Related to https://github.com/FreshRSS/FreshRSS/issues/4200
Alexandre Alapetite 4 лет назад
Родитель
Сommit
7c2da31418
3 измененных файлов с 39 добавлено и 24 удалено
  1. 20 11
      app/Models/EntryDAO.php
  2. 8 6
      app/Models/EntryDAOSQLite.php
  3. 11 7
      p/api/fever.php

+ 20 - 11
app/Models/EntryDAO.php

@@ -83,7 +83,10 @@ SQL;
 		return false;
 	}
 
-	private $addEntryPrepared = null;
+	/**
+	 * @var PDOStatement|null|false
+	 */
+	private $addEntryPrepared = false;
 
 	public function addEntry(array $valuesTmp, bool $useTmpTable = true) {
 		if ($this->addEntryPrepared == null) {
@@ -178,7 +181,7 @@ SQL;
 
 	private $updateEntryPrepared = null;
 
-	public function updateEntry($valuesTmp) {
+	public function updateEntry(array $valuesTmp) {
 		if (!isset($valuesTmp['is_read'])) {
 			$valuesTmp['is_read'] = null;
 		}
@@ -343,7 +346,7 @@ SQL;
 	 * @param boolean $is_read
 	 * @return integer|false affected rows
 	 */
-	public function markRead($ids, $is_read = true) {
+	public function markRead($ids, bool $is_read = true) {
 		FreshRSS_UserDAO::touch();
 		if (is_array($ids)) {	//Many IDs at once
 			if (count($ids) < 6) {	//Speed heuristics
@@ -411,12 +414,13 @@ SQL;
 	 * place. It will be reused also for the filtering making every thing
 	 * separated.
 	 *
-	 * @param integer $idMax fail safe article ID
+	 * @param string $idMax fail safe article ID
 	 * @param boolean $onlyFavorites
 	 * @param integer $priorityMin
+	 * @param FreshRSS_BooleanSearch|null $filters
 	 * @return integer|false affected rows
 	 */
-	public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filters = null, $state = 0, $is_read = true) {
+	public function markReadEntries(string $idMax = '0', bool $onlyFavorites = false, int $priorityMin = 0, $filters = null, int $state = 0, bool $is_read = true) {
 		FreshRSS_UserDAO::touch();
 		if ($idMax == 0) {
 			$idMax = time() . '000000';
@@ -456,12 +460,13 @@ SQL;
 	 * If $idMax equals 0, a deprecated debug message is logged
 	 *
 	 * @param integer $id category ID
-	 * @param integer $idMax fail safe article ID
+	 * @param string $idMax fail safe article ID
+	 * @param FreshRSS_BooleanSearch|null $filters
 	 * @return integer|false affected rows
 	 */
-	public function markReadCat($id, $idMax = 0, $filters = null, $state = 0, $is_read = true) {
+	public function markReadCat(int $id, string $idMax = '0', $filters = null, int $state = 0, bool $is_read = true) {
 		FreshRSS_UserDAO::touch();
-		if ($idMax == 0) {
+		if ($idMax == '0') {
 			$idMax = time() . '000000';
 			Minz_Log::debug('Calling markReadCat(0) is deprecated!');
 		}
@@ -495,9 +500,10 @@ SQL;
 	 *
 	 * @param integer $id_feed feed ID
 	 * @param string $idMax fail safe article ID
+	 * @param FreshRSS_BooleanSearch|null $filters
 	 * @return integer|false affected rows
 	 */
-	public function markReadFeed($id_feed, $idMax = '0', $filters = null, $state = 0, $is_read = true) {
+	public function markReadFeed(int $id_feed, string $idMax = '0', $filters = null, int $state = 0, bool $is_read = true) {
 		FreshRSS_UserDAO::touch();
 		if ($idMax == '0') {
 			$idMax = time() . '000000';
@@ -692,8 +698,11 @@ SQL;
 		return 'CONCAT(' . $s1 . ',' . $s2 . ')';	//MySQL
 	}
 
-	protected function sqlListEntriesWhere($alias = '', $filters = null, $state = FreshRSS_Entry::STATE_ALL,
-			$order = 'DESC', $firstId = '', $date_min = 0) {
+	/**
+	 * @param FreshRSS_BooleanSearch|null $filters
+	 */
+	protected function sqlListEntriesWhere(string $alias = '', $filters = null, int $state = FreshRSS_Entry::STATE_ALL,
+			string $order = 'DESC', string $firstId = '', int $date_min = 0) {
 		$search = ' ';
 		$values = array();
 		if ($state & FreshRSS_Entry::STATE_NOT_READ) {

+ 8 - 6
app/Models/EntryDAOSQLite.php

@@ -166,14 +166,15 @@ DROP TABLE IF EXISTS `tmp`;
 	 * place. It will be reused also for the filtering making every thing
 	 * separated.
 	 *
-	 * @param integer $idMax fail safe article ID
+	 * @param string $idMax fail safe article ID
 	 * @param boolean $onlyFavorites
 	 * @param integer $priorityMin
+	 * @param FreshRSS_BooleanSearch|null $filters
 	 * @return integer|false affected rows
 	 */
-	public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filters = null, $state = 0, $is_read = true) {
+	public function markReadEntries(string $idMax = '0', bool $onlyFavorites = false, int $priorityMin = 0, $filters = null, int $state = 0, bool $is_read = true) {
 		FreshRSS_UserDAO::touch();
-		if ($idMax == 0) {
+		if ($idMax == '0') {
 			$idMax = time() . '000000';
 			Minz_Log::debug('Calling markReadEntries(0) is deprecated!');
 		}
@@ -209,12 +210,13 @@ DROP TABLE IF EXISTS `tmp`;
 	 * If $idMax equals 0, a deprecated debug message is logged
 	 *
 	 * @param integer $id category ID
-	 * @param integer $idMax fail safe article ID
+	 * @param string $idMax fail safe article ID
+	 * @param FreshRSS_BooleanSearch|null $filters
 	 * @return integer|false affected rows
 	 */
-	public function markReadCat($id, $idMax = 0, $filters = null, $state = 0, $is_read = true) {
+	public function markReadCat(int $id, string $idMax = '0', $filters = null, int $state = 0, bool $is_read = true) {
 		FreshRSS_UserDAO::touch();
-		if ($idMax == 0) {
+		if ($idMax == '0') {
 			$idMax = time() . '000000';
 			Minz_Log::debug('Calling markReadCat(0) is deprecated!');
 		}

+ 11 - 7
p/api/fever.php

@@ -130,7 +130,14 @@ class FeverAPI
 	const STATUS_OK = 1;
 	const STATUS_ERR = 0;
 
+	/**
+	 * @var FreshRSS_EntryDAO|null
+	 */
 	private $entryDAO = null;
+
+	/**
+	 * @var FreshRSS_FeedDAO|null
+	 */
 	private $feedDAO = null;
 
 	/**
@@ -345,7 +352,7 @@ class FeverAPI
 	}
 
 	/**
-	 * @return int
+	 * @return int|false
 	 */
 	protected function getTotalItems() {
 		return $this->entryDAO->count();
@@ -502,11 +509,8 @@ class FeverAPI
 
 	/**
 	 * TODO replace by a dynamic fetch for id <= $before timestamp
-	 *
-	 * @param int|string $beforeTimestamp
-	 * @return string
 	 */
-	protected function convertBeforeToId($beforeTimestamp): string {
+	protected function convertBeforeToId(string $beforeTimestamp): string {
 		return $beforeTimestamp == '0' ? '0' : $beforeTimestamp . '000000';
 	}
 
@@ -515,7 +519,7 @@ class FeverAPI
 	 */
 	protected function setFeedAsRead(string $id, string $before) {
 		$before = $this->convertBeforeToId($before);
-		return $this->entryDAO->markReadFeed($id, $before);
+		return $this->entryDAO->markReadFeed(intval($id), $before);
 	}
 
 	/**
@@ -529,7 +533,7 @@ class FeverAPI
 			return $this->entryDAO->markReadEntries($before);
 		}
 
-		return $this->entryDAO->markReadCat($id, $before);
+		return $this->entryDAO->markReadCat(intval($id), $before);
 	}
 }