diff options
| author | 2018-01-02 23:53:35 +0100 | |
|---|---|---|
| committer | 2018-01-02 23:53:35 +0100 | |
| commit | 7642d334f827d1c077bb1444dfc4e79acf022891 (patch) | |
| tree | 904bb76cc119ff6d7a806cefd3c1fabbdebf2233 /app/Models | |
| parent | e3ffc048d7a10a6116cf80fb6fceda0b4037368c (diff) | |
Replace "keep history" magic value by a constant (#1759)
I think the use of a magic value repeated many times in the code is prone to have some errors made by people not knowing its meaning. Using a constant is a bit more safe. Judging by some comments in the code, I am not the only one.
Diffstat (limited to 'app/Models')
| -rw-r--r-- | app/Models/ConfigurationSetter.php | 4 | ||||
| -rw-r--r-- | app/Models/Feed.php | 7 | ||||
| -rw-r--r-- | app/Models/FeedDAO.php | 5 |
3 files changed, 10 insertions, 6 deletions
diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php index ca4709903..645ef644e 100644 --- a/app/Models/ConfigurationSetter.php +++ b/app/Models/ConfigurationSetter.php @@ -81,7 +81,7 @@ class FreshRSS_ConfigurationSetter { private function _keep_history_default(&$data, $value) { $value = intval($value); - $data['keep_history_default'] = $value >= -1 ? $value : 0; + $data['keep_history_default'] = $value >= FreshRSS_Feed::KEEP_HISTORY_INFINITE ? $value : 0; } // It works for system config too! @@ -154,7 +154,7 @@ class FreshRSS_ConfigurationSetter { private function _ttl_default(&$data, $value) { $value = intval($value); - $data['ttl_default'] = $value >= -1 ? $value : 3600; + $data['ttl_default'] = $value > FreshRSS_Feed::TTL_DEFAULT ? $value : 3600; } private function _view_mode(&$data, $value) { diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 216a26d44..13ab13df9 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -7,6 +7,9 @@ class FreshRSS_Feed extends Minz_Model { const TTL_DEFAULT = 0; + const KEEP_HISTORY_DEFAULT = -2; + const KEEP_HISTORY_INFINITE = -1; + private $id = 0; private $url; private $category = 1; @@ -21,7 +24,7 @@ class FreshRSS_Feed extends Minz_Model { private $pathEntries = ''; private $httpAuth = ''; private $error = false; - private $keep_history = -2; + private $keep_history = self::KEEP_HISTORY_DEFAULT; private $ttl = self::TTL_DEFAULT; private $mute = false; private $hash = null; @@ -222,7 +225,7 @@ class FreshRSS_Feed extends Minz_Model { public function _keepHistory($value) { $value = intval($value); $value = min($value, 1000000); - $value = max($value, -2); + $value = max($value, self::KEEP_HISTORY_DEFAULT); $this->keep_history = $value; } public function _ttl($value) { diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index deda02c63..011b3d112 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -18,7 +18,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { ttl ) VALUES - (?, ?, ?, ?, ?, ?, 10, ?, 0, -2, ?)'; + (?, ?, ?, ?, ?, ?, 10, ?, 0, ?, ?)'; $stm = $this->bd->prepare($sql); $valuesTmp['url'] = safe_ascii($valuesTmp['url']); @@ -32,6 +32,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { substr($valuesTmp['description'], 0, 1023), $valuesTmp['lastUpdate'], base64_encode($valuesTmp['httpAuth']), + FreshRSS_Feed::KEEP_HISTORY_DEFAULT, FreshRSS_Feed::TTL_DEFAULT, ); @@ -406,7 +407,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { $myFeed->_pathEntries(isset($dao['pathEntries']) ? $dao['pathEntries'] : ''); $myFeed->_httpAuth(isset($dao['httpAuth']) ? base64_decode($dao['httpAuth']) : ''); $myFeed->_error(isset($dao['error']) ? $dao['error'] : 0); - $myFeed->_keepHistory(isset($dao['keep_history']) ? $dao['keep_history'] : -2); + $myFeed->_keepHistory(isset($dao['keep_history']) ? $dao['keep_history'] : FreshRSS_Feed::KEEP_HISTORY_DEFAULT); $myFeed->_ttl(isset($dao['ttl']) ? $dao['ttl'] : FreshRSS_Feed::TTL_DEFAULT); $myFeed->_nbNotRead(isset($dao['cache_nbUnreads']) ? $dao['cache_nbUnreads'] : 0); $myFeed->_nbEntries(isset($dao['cache_nbEntries']) ? $dao['cache_nbEntries'] : 0); |
