From 7af9a41881ed0b9d44d18a0ce03a123a8441adf5 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 20 Oct 2016 11:31:52 +0200 Subject: [PATCH] Minor code cleanup: PHPDoc, spelling, unused variables, etc. --- CHANGELOG.md | 1 + application/ApplicationUtils.php | 8 ++++++-- application/CachedPage.php | 2 +- application/LinkUtils.php | 3 ++- application/NetscapeBookmarkUtils.php | 2 +- application/TimeZone.php | 10 +++------- application/Updater.php | 2 +- application/Url.php | 14 -------------- application/Utils.php | 8 +++++++- application/config/ConfigJson.php | 2 +- application/config/ConfigManager.php | 2 ++ index.php | 8 ++------ tests/config/ConfigJsonTest.php | 2 +- 13 files changed, 28 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60af7223..e32ef459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Release archives now have the same structure as GitHub-generated archives: - archives contain a `Shaarli` directory, itself containing sources + dependencies - the tarball is now gzipped +- Minor code cleanup: PHPDoc, spelling, unused variables, etc. ### Fixed - Fix the server `` value in Atom/RSS feeds diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php index e67b2902..7f963e97 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php @@ -15,6 +15,9 @@ class ApplicationUtils * * The code is read from the raw content of the version file on the Git server. * + * @param string $url URL to reach to get the latest version. + * @param int $timeout Timeout to check the URL (in seconds). + * * @return mixed the version code from the repository if available, else 'false' */ public static function getLatestGitVersionCode($url, $timeout=2) @@ -49,6 +52,7 @@ class ApplicationUtils * @param int $checkInterval the minimum interval between update checks (in seconds * @param bool $enableCheck whether to check for new versions * @param bool $isLoggedIn whether the user is logged in + * @param string $branch check update for the given branch * * @throws Exception an invalid branch has been set for update checks * @@ -152,7 +156,7 @@ class ApplicationUtils } } - // Check cache and data directories are readable and writeable + // Check cache and data directories are readable and writable foreach (array( $conf->get('resource.thumbnails_cache'), $conf->get('resource.data_dir'), @@ -167,7 +171,7 @@ class ApplicationUtils } } - // Check configuration files are readable and writeable + // Check configuration files are readable and writable foreach (array( $conf->getConfigFileExt(), $conf->get('resource.datastore'), diff --git a/application/CachedPage.php b/application/CachedPage.php index 50cfa9ac..5087d0c4 100644 --- a/application/CachedPage.php +++ b/application/CachedPage.php @@ -35,7 +35,7 @@ class CachedPage /** * Returns the cached version of a page, if it exists and should be cached * - * @return a cached version of the page if it exists, null otherwise + * @return string a cached version of the page if it exists, null otherwise */ public function cachedVersion() { diff --git a/application/LinkUtils.php b/application/LinkUtils.php index eeca631f..9d9ae3cb 100644 --- a/application/LinkUtils.php +++ b/application/LinkUtils.php @@ -81,7 +81,7 @@ function html_extract_charset($html) /** * Count private links in given linklist. * - * @param array $links Linklist. + * @param array|Countable $links Linklist. * * @return int Number of private links. */ @@ -162,6 +162,7 @@ function space2nbsp($text) * * @param string $description shaare's description. * @param string $redirector if a redirector is set, use it to gerenate links. + * @param string $indexUrl URL to Shaarli's index. * * @return string formatted description. */ diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php index c3181254..d6840d37 100644 --- a/application/NetscapeBookmarkUtils.php +++ b/application/NetscapeBookmarkUtils.php @@ -86,7 +86,7 @@ class NetscapeBookmarkUtils * Imports Web bookmarks from an uploaded Netscape bookmark dump * * @param array $post Server $_POST parameters - * @param array $file Server $_FILES parameters + * @param array $files Server $_FILES parameters * @param LinkDB $linkDb Loaded LinkDB instance * @param string $pagecache Page cache * diff --git a/application/TimeZone.php b/application/TimeZone.php index 26f2232d..36a8fb12 100644 --- a/application/TimeZone.php +++ b/application/TimeZone.php @@ -7,9 +7,9 @@ * Example: preselect Europe/Paris * list($htmlform, $js) = generateTimeZoneForm('Europe/Paris'); * - * @param string $preselected_timezone preselected timezone (optional) + * @param string $preselectedTimezone preselected timezone (optional) * - * @return an array containing the generated HTML form and Javascript code + * @return array containing the generated HTML form and Javascript code **/ function generateTimeZoneForm($preselectedTimezone='') { @@ -27,10 +27,6 @@ function generateTimeZoneForm($preselectedTimezone='') $pcity = substr($preselectedTimezone, $spos+1); } - // Display config form: - $timezoneForm = ''; - $timezoneJs = ''; - // The list is in the form 'Europe/Paris', 'America/Argentina/Buenos_Aires' // We split the list in continents/cities. $continents = array(); @@ -97,7 +93,7 @@ function generateTimeZoneForm($preselectedTimezone='') * @param string $continent the timezone continent * @param string $city the timezone city * - * @return whether continent/city is a valid timezone + * @return bool whether continent/city is a valid timezone */ function isTimeZoneValid($continent, $city) { diff --git a/application/Updater.php b/application/Updater.php index b6cbc56c..90913235 100644 --- a/application/Updater.php +++ b/application/Updater.php @@ -37,7 +37,7 @@ class Updater * * @param array $doneUpdates Updates which are already done. * @param LinkDB $linkDB LinkDB instance. - * @oaram ConfigManager $conf Configuration Manager instance. + * @param ConfigManager $conf Configuration Manager instance. * @param boolean $isLoggedIn True if the user is logged in. */ public function __construct($doneUpdates, $linkDB, $conf, $isLoggedIn) diff --git a/application/Url.php b/application/Url.php index c166ff6e..c5c7dd18 100644 --- a/application/Url.php +++ b/application/Url.php @@ -62,21 +62,7 @@ function add_trailing_slash($url) { return $url . (!endsWith($url, '/') ? '/' : ''); } -/** - * Converts an URL with an IDN host to a ASCII one. - * - * @param string $url Input URL. - * - * @return string converted URL. - */ -function url_with_idn_to_ascii($url) -{ - $parts = parse_url($url); - $parts['host'] = idn_to_ascii($parts['host']); - $httpUrl = new \http\Url($parts); - return $httpUrl->toString(); -} /** * URL representation and cleanup utilities * diff --git a/application/Utils.php b/application/Utils.php index 7d7eaffd..0166ee2a 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -32,6 +32,10 @@ function logm($logFile, $clientIp, $message) * * In Shaarli, they are used as a tinyurl-like link to individual entries, * e.g. smallHash('20111006_131924') --> yZH23w + * + * @param string $text Create a hash from this text. + * + * @return string generated small hash. */ function smallHash($text) { @@ -106,7 +110,9 @@ function unescape($str) } /** - * Link sanitization before templating + * Sanitize link before rendering. + * + * @param array $link Link to escape. */ function sanitizeLink(&$link) { diff --git a/application/config/ConfigJson.php b/application/config/ConfigJson.php index d07fefee..30007eb4 100644 --- a/application/config/ConfigJson.php +++ b/application/config/ConfigJson.php @@ -21,7 +21,7 @@ class ConfigJson implements ConfigIO $data = json_decode($data, true); if ($data === null) { $error = json_last_error(); - throw new Exception('An error occured while parsing JSON file: error code #'. $error); + throw new Exception('An error occurred while parsing JSON file: error code #'. $error); } return $data; } diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php index ff41772a..f5f753f8 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php @@ -37,6 +37,8 @@ class ConfigManager /** * Constructor. + * + * @param string $configFile Configuration file path without extension. */ public function __construct($configFile = 'data/config') { diff --git a/index.php b/index.php index f7e73bde..6d712aee 100644 --- a/index.php +++ b/index.php @@ -606,8 +606,6 @@ function showDailyRSS($conf) { $absurl = escape(index_url($_SERVER).'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page. // Build the HTML body of this RSS entry. - $html = ''; - $href = ''; $links = array(); // We pre-format some fields for proper output. @@ -833,7 +831,7 @@ function renderPage($conf, $pluginManager) // Get only links which have a thumbnail. foreach($links as $link) { - $permalink='?'.escape(smallhash($link['linkdate'])); + $permalink='?'.escape(smallHash($link['linkdate'])); $thumb=lazyThumbnail($conf, $link['url'],$permalink); if ($thumb!='') // Only output links which have a thumbnail. { @@ -867,7 +865,7 @@ function renderPage($conf, $pluginManager) $maxcount = max($maxcount, $value); } - // Sort tags alphabetically: case insensitive, support locale if avalaible. + // Sort tags alphabetically: case insensitive, support locale if available. uksort($tags, function($a, $b) { // Collator is part of PHP intl. if (class_exists('Collator')) { @@ -1670,8 +1668,6 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) $next_page_url = '?page=' . ($page-1) . $searchtermUrl . $searchtagsUrl; } - $token = isLoggedIn() ? getToken($conf) : ''; - // Fill all template fields. $data = array( 'previous_page_url' => $previous_page_url, diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php index 99c88820..07f6ab49 100644 --- a/tests/config/ConfigJsonTest.php +++ b/tests/config/ConfigJsonTest.php @@ -41,7 +41,7 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase * Read a non existent config file -> empty array. * * @expectedException Exception - * @expectedExceptionMessage An error occured while parsing JSON file: error code #4 + * @expectedExceptionMessage An error occurred while parsing JSON file: error code #4 */ public function testReadInvalidJson() { -- 2.41.0