Ver Fonte

[CI] PHPCS: check for opening brace on same line (#4122)

* [CI] PHPCS: check for opening brace on same line

* make fix-all

* Minor comments

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Frans de Jonge há 4 anos atrás
pai
commit
d339b6dd45
9 ficheiros alterados com 79 adições e 79 exclusões
  1. 8 2
      app/Models/EntryDAO.php
  2. 4 1
      app/Models/Feed.php
  3. 8 2
      app/Models/FeedDAO.php
  4. 8 16
      lib/Minz/Migrator.php
  5. 6 2
      lib/Minz/Pdo.php
  6. 9 3
      lib/lib_rss.php
  7. 24 48
      p/api/fever.php
  8. 10 5
      p/api/greader.php
  9. 2 0
      phpcs.xml

+ 8 - 2
app/Models/EntryDAO.php

@@ -580,7 +580,10 @@ SQL;
 		return $affected;
 	}
 
-	public function cleanOldEntries($id_feed, $options = []) { //Remember to call updateCachedValue($id_feed) or updateCachedValues() just after
+	/**
+	 * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after.
+	 */
+	public function cleanOldEntries($id_feed, $options = []) {
 		$sql = 'DELETE FROM `_entry` WHERE id_feed = :id_feed1';	//No alias for MySQL / MariaDB
 		$params = [];
 		$params[':id_feed1'] = $id_feed;
@@ -1085,8 +1088,11 @@ SQL;
 		}
 	}
 
+	/**
+	 * For API
+	 */
 	public function listIdsWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL,
-			$order = 'DESC', $limit = 1, $firstId = '', $filters = null) {	//For API
+			$order = 'DESC', $limit = 1, $firstId = '', $filters = null) {
 		list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filters);
 
 		$stm = $this->pdo->prepare($sql);

+ 4 - 1
app/Models/Feed.php

@@ -496,7 +496,10 @@ class FreshRSS_Feed extends Minz_Model {
 		}
 	}
 
-	public function cleanOldEntries() {	//Remember to call updateCachedValue($id_feed) or updateCachedValues() just after
+	/**
+	 * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after
+	 */
+	public function cleanOldEntries() {
 		$archiving = $this->attributes('archiving');
 		if ($archiving == null) {
 			$catDAO = FreshRSS_Factory::createCategoryDao();

+ 8 - 2
app/Models/FeedDAO.php

@@ -174,7 +174,10 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
 		return false;
 	}
 
-	public function updateLastUpdate($id, $inError = false, $mtime = 0) {	//See also updateCachedValue()
+	/**
+	 * @see updateCachedValue()
+	 */
+	public function updateLastUpdate($id, $inError = false, $mtime = 0) {
 		$sql = 'UPDATE `_feed` SET `lastUpdate`=?, error=? WHERE id=?';
 		$values = array(
 			$mtime <= 0 ? time() : $mtime,
@@ -321,7 +324,10 @@ SQL;
 		return $newestItemUsec;
 	}
 
-	public function arrayFeedCategoryNames() {	//For API
+	/**
+	 * For API
+	 */
+	public function arrayFeedCategoryNames() {
 		$sql = <<<'SQL'
 SELECT f.id, f.name, c.name as c_name FROM `_feed` f
 INNER JOIN `_category` c ON c.id = f.category

+ 8 - 16
lib/Minz/Migrator.php

@@ -126,8 +126,7 @@ class Minz_Migrator
 	 * @throws BadFunctionCallException if a callback isn't callable (i.e.
 	 *                                  cannot call a migrate method).
 	 */
-	public function __construct($directory = null)
-	{
+	public function __construct($directory = null) {
 		$this->applied_versions = [];
 
 		if (!is_dir($directory)) {
@@ -166,8 +165,7 @@ class Minz_Migrator
 	 *
 	 * @throws BadFunctionCallException if the callback isn't callable.
 	 */
-	public function addMigration($version, $callback)
-	{
+	public function addMigration($version, $callback) {
 		if (!is_callable($callback)) {
 			throw new BadFunctionCallException("{$version} migration cannot be called.");
 		}
@@ -182,8 +180,7 @@ class Minz_Migrator
 	 *
 	 * @return array
 	 */
-	public function migrations()
-	{
+	public function migrations() {
 		$migrations = $this->migrations;
 		uksort($migrations, 'strnatcmp');
 		return $migrations;
@@ -196,8 +193,7 @@ class Minz_Migrator
 	 *
 	 * @throws DomainException if there is no migrations corresponding to a version
 	 */
-	public function setAppliedVersions($versions)
-	{
+	public function setAppliedVersions($versions) {
 		foreach ($versions as $version) {
 			$version = trim($version);
 			if (!isset($this->migrations[$version])) {
@@ -210,8 +206,7 @@ class Minz_Migrator
 	/**
 	 * @return string[]
 	 */
-	public function appliedVersions()
-	{
+	public function appliedVersions() {
 		$versions = $this->applied_versions;
 		usort($versions, 'strnatcmp');
 		return $versions;
@@ -224,8 +219,7 @@ class Minz_Migrator
 	 *
 	 * @return string[]
 	 */
-	public function versions()
-	{
+	public function versions() {
 		$migrations = $this->migrations();
 		return array_keys($migrations);
 	}
@@ -235,8 +229,7 @@ class Minz_Migrator
 	 *                 otherwise. If no migrations are registered, it always
 	 *                 returns true.
 	 */
-	public function upToDate()
-	{
+	public function upToDate() {
 		// Counting versions is enough since we cannot apply a version which
 		// doesn't exist (see setAppliedVersions method).
 		return count($this->versions()) === count($this->applied_versions);
@@ -256,8 +249,7 @@ class Minz_Migrator
 	 *               exception was raised in a migration, its result is set to
 	 *               the exception message.
 	 */
-	public function migrate()
-	{
+	public function migrate() {
 		$result = [];
 		foreach ($this->migrations() as $version => $callback) {
 			if (in_array($version, $this->applied_versions)) {

+ 6 - 2
lib/Minz/Pdo.php

@@ -14,8 +14,12 @@ abstract class Minz_Pdo extends PDO {
 	abstract public function dbType();
 
 	private $prefix = '';
-	public function prefix() { return $this->prefix; }
-	public function setPrefix($prefix) { $this->prefix = $prefix; }
+	public function prefix() {
+		return $this->prefix;
+	}
+	public function setPrefix($prefix) {
+		$this->prefix = $prefix;
+	}
 
 	private function autoPrefix($sql) {
 		return str_replace('`_', '`' . $this->prefix, $sql);

+ 9 - 3
lib/lib_rss.php

@@ -115,19 +115,25 @@ if (function_exists('mb_convert_encoding')) {
 	 * @param string $text
 	 * @return string
 	 */
-	function safe_utf8($text) { return mb_convert_encoding($text, 'UTF-8', 'UTF-8'); }
+	function safe_utf8($text) {
+		return mb_convert_encoding($text, 'UTF-8', 'UTF-8');
+	}
 } elseif (function_exists('iconv')) {
 	/**
 	 * @param string $text
 	 * @return string
 	 */
-	function safe_utf8($text) { return iconv('UTF-8', 'UTF-8//IGNORE', $text); }
+	function safe_utf8($text) {
+		return iconv('UTF-8', 'UTF-8//IGNORE', $text);
+	}
 } else {
 	/**
 	 * @param string $text
 	 * @return string
 	 */
-	function safe_utf8($text) { return $text; }
+	function safe_utf8($text) {
+		return $text;
+	}
 }
 
 /**

+ 24 - 48
p/api/fever.php

@@ -69,8 +69,7 @@ class FeverDAO extends Minz_ModelPdo
 	 * @param array $bindArray
 	 * @return string
 	 */
-	protected function bindParamArray($prefix, $values, &$bindArray)
-	{
+	protected function bindParamArray($prefix, $values, &$bindArray) {
 		$str = '';
 		for ($i = 0; $i < count($values); $i++) {
 			$str .= ':' . $prefix . $i . ',';
@@ -86,8 +85,7 @@ class FeverDAO extends Minz_ModelPdo
 	 * @param int|null $since_id
 	 * @return FreshRSS_Entry[]
 	 */
-	public function findEntries(array $feed_ids, array $entry_ids, $max_id, $since_id)
-	{
+	public function findEntries(array $feed_ids, array $entry_ids, $max_id, $since_id) {
 		$values = array();
 		$order = '';
 		$entryDAO = FreshRSS_Factory::createEntryDao();
@@ -151,8 +149,7 @@ class FeverAPI
 	 * API Password sent from client is the result of the md5 sum of
 	 * your FreshRSS "username:your-api-password" combination
 	 */
-	private function authenticate()
-	{
+	private function authenticate() {
 		FreshRSS_Context::$user_conf = null;
 		Minz_Session::_param('currentUser');
 		$feverKey = empty($_POST['api_key']) ? '' : substr(trim($_POST['api_key']), 0, 128);
@@ -182,8 +179,7 @@ class FeverAPI
 	/**
 	 * @return bool
 	 */
-	public function isAuthenticatedApiUser()
-	{
+	public function isAuthenticatedApiUser() {
 		$this->authenticate();
 
 		if (FreshRSS_Context::$user_conf !== null) {
@@ -199,8 +195,7 @@ class FeverAPI
 	 * @return array
 	 * @throws Exception
 	 */
-	public function process()
-	{
+	public function process() {
 		$response_arr = array();
 
 		if (!$this->isAuthenticatedApiUser()) {
@@ -281,8 +276,7 @@ class FeverAPI
 	 * @param array $reply
 	 * @return string
 	 */
-	public function wrap($status, array $reply = array())
-	{
+	public function wrap($status, array $reply = array()) {
 		$arr = array('api_version' => self::API_LEVEL, 'auth' => $status);
 
 		if ($status === self::STATUS_OK) {
@@ -298,8 +292,7 @@ class FeverAPI
 	 *
 	 * @return int
 	 */
-	protected function lastRefreshedOnTime()
-	{
+	protected function lastRefreshedOnTime() {
 		$lastUpdate = 0;
 
 		$entries = $this->feedDAO->listFeedsOrderUpdate(-1, 1);
@@ -315,8 +308,7 @@ class FeverAPI
 	/**
 	 * @return array
 	 */
-	protected function getFeeds()
-	{
+	protected function getFeeds() {
 		$feeds = array();
 		$myFeeds = $this->feedDAO->listFeeds();
 
@@ -339,8 +331,7 @@ class FeverAPI
 	/**
 	 * @return array
 	 */
-	protected function getGroups()
-	{
+	protected function getGroups() {
 		$groups = array();
 
 		$categoryDAO = FreshRSS_Factory::createCategoryDao();
@@ -360,8 +351,7 @@ class FeverAPI
 	/**
 	 * @return array
 	 */
-	protected function getFavicons()
-	{
+	protected function getFavicons() {
 		$favicons = array();
 		$salt = FreshRSS_Context::$system_conf->salt;
 		$myFeeds = $this->feedDAO->listFeeds();
@@ -387,16 +377,14 @@ class FeverAPI
 	/**
 	 * @return int
 	 */
-	protected function getTotalItems()
-	{
+	protected function getTotalItems() {
 		return $this->entryDAO->count();
 	}
 
 	/**
 	 * @return array
 	 */
-	protected function getFeedsGroup()
-	{
+	protected function getFeedsGroup() {
 		$groups = array();
 		$ids = array();
 		$myFeeds = $this->feedDAO->listFeeds();
@@ -420,8 +408,7 @@ class FeverAPI
 	 * AFAIK there is no 'hot links' alternative in FreshRSS
 	 * @return array
 	 */
-	protected function getLinks()
-	{
+	protected function getLinks() {
 		return array();
 	}
 
@@ -429,16 +416,14 @@ class FeverAPI
 	 * @param array $ids
 	 * @return string
 	 */
-	protected function entriesToIdList($ids = array())
-	{
+	protected function entriesToIdList($ids = array()) {
 		return implode(',', array_values($ids));
 	}
 
 	/**
 	 * @return string
 	 */
-	protected function getUnreadItemIds()
-	{
+	protected function getUnreadItemIds() {
 		$entries = $this->entryDAO->listIdsWhere('a', '', FreshRSS_Entry::STATE_NOT_READ, 'ASC', 0);
 		return $this->entriesToIdList($entries);
 	}
@@ -446,37 +431,31 @@ class FeverAPI
 	/**
 	 * @return string
 	 */
-	protected function getSavedItemIds()
-	{
+	protected function getSavedItemIds() {
 		$entries = $this->entryDAO->listIdsWhere('a', '', FreshRSS_Entry::STATE_FAVORITE, 'ASC', 0);
 		return $this->entriesToIdList($entries);
 	}
 
-	protected function setItemAsRead($id)
-	{
+	protected function setItemAsRead($id) {
 		return $this->entryDAO->markRead($id, true);
 	}
 
-	protected function setItemAsUnread($id)
-	{
+	protected function setItemAsUnread($id) {
 		return $this->entryDAO->markRead($id, false);
 	}
 
-	protected function setItemAsSaved($id)
-	{
+	protected function setItemAsSaved($id) {
 		return $this->entryDAO->markFavorite($id, true);
 	}
 
-	protected function setItemAsUnsaved($id)
-	{
+	protected function setItemAsUnsaved($id) {
 		return $this->entryDAO->markFavorite($id, false);
 	}
 
 	/**
 	 * @return array
 	 */
-	protected function getItems()
-	{
+	protected function getItems() {
 		$feed_ids = array();
 		$entry_ids = array();
 		$max_id = null;
@@ -550,19 +529,16 @@ class FeverAPI
 	 * @param int $beforeTimestamp
 	 * @return int
 	 */
-	protected function convertBeforeToId($beforeTimestamp)
-	{
+	protected function convertBeforeToId($beforeTimestamp) {
 		return $beforeTimestamp == 0 ? 0 : $beforeTimestamp . '000000';
 	}
 
-	protected function setFeedAsRead($id, $before)
-	{
+	protected function setFeedAsRead($id, $before) {
 		$before = $this->convertBeforeToId($before);
 		return $this->entryDAO->markReadFeed($id, $before);
 	}
 
-	protected function setGroupAsRead($id, $before)
-	{
+	protected function setGroupAsRead($id, $before) {
 		$before = $this->convertBeforeToId($before);
 
 		// special case to mark all items as read

+ 10 - 5
p/api/greader.php

@@ -49,7 +49,8 @@ if (PHP_INT_SIZE < 8) {	//32-bit
 	 * @param string|int $dec
 	 * @return string
 	 */
-	function dec2hex($dec) {	//http://code.google.com/p/google-reader-api/wiki/ItemId
+	function dec2hex($dec) {
+		//http://code.google.com/p/google-reader-api/wiki/ItemId
 		return str_pad(dechex($dec), 16, '0', STR_PAD_LEFT);
 	}
 	/**
@@ -81,7 +82,8 @@ function headerVariable($headerName, $varName) {
 	return isset($pairs[$varName]) ? $pairs[$varName] : null;
 }
 
-function multiplePosts($name) {	//https://bugs.php.net/bug.php?id=51633
+function multiplePosts($name) {
+	//https://bugs.php.net/bug.php?id=51633
 	global $ORIGINAL_INPUT;
 	$inputs = explode('&', $ORIGINAL_INPUT);
 	$result = array();
@@ -197,7 +199,8 @@ function authorizationToUser() {
 	return '';
 }
 
-function clientLogin($email, $pass) {	//http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html
+function clientLogin($email, $pass) {
+	//http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html
 	if (FreshRSS_user_Controller::checkUsername($email)) {
 		FreshRSS_Context::initUser($email);
 		if (FreshRSS_Context::$user_conf == null) {
@@ -247,7 +250,8 @@ function checkToken($conf, $token) {
 	unauthorized();
 }
 
-function userInfo() {	//https://github.com/theoldreader/api#user-info
+function userInfo() {
+	//https://github.com/theoldreader/api#user-info
 	$user = Minz_Session::param('currentUser', '_');
 	exit(json_encode(array(
 			'userId' => $user,
@@ -459,7 +463,8 @@ function quickadd($url) {
 	}
 }
 
-function unreadCount() {	//http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count
+function unreadCount() {
+	//http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count
 	header('Content-Type: application/json; charset=UTF-8');
 
 	$totalUnreads = 0;

+ 2 - 0
phpcs.xml

@@ -105,6 +105,8 @@
 	<rule ref="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis">
 		<exclude-pattern>.phtml$</exclude-pattern>
 	</rule>
+	<!-- Opening brace on same line as function declaration -->
+	<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />
 	<!-- Newline required after opening brace -->
 	<rule ref="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace">
 		<exclude-pattern>.phtml$</exclude-pattern>