Merge pull request #11760 from owncloud/add-type-hints-where-sensible

Add type hinting to functions
This commit is contained in:
Lukas Reschke 2014-10-25 14:09:48 +02:00
commit acec1afe17
10 changed files with 66 additions and 73 deletions

View File

@ -8,6 +8,8 @@
namespace OCA\Files; namespace OCA\Files;
use OCP\Files\FileInfo;
/** /**
* Helper class for manipulating file information * Helper class for manipulating file information
*/ */
@ -58,7 +60,7 @@ class Helper
* @param \OCP\Files\FileInfo $b file * @param \OCP\Files\FileInfo $b file
* @return int -1 if $a must come before $b, 1 otherwise * @return int -1 if $a must come before $b, 1 otherwise
*/ */
public static function compareFileNames($a, $b) { public static function compareFileNames(FileInfo $a, FileInfo $b) {
$aType = $a->getType(); $aType = $a->getType();
$bType = $b->getType(); $bType = $b->getType();
if ($aType === 'dir' and $bType !== 'dir') { if ($aType === 'dir' and $bType !== 'dir') {
@ -77,7 +79,7 @@ class Helper
* @param \OCP\Files\FileInfo $b file * @param \OCP\Files\FileInfo $b file
* @return int -1 if $a must come before $b, 1 otherwise * @return int -1 if $a must come before $b, 1 otherwise
*/ */
public static function compareTimestamp($a, $b) { public static function compareTimestamp(FileInfo $a, FileInfo $b) {
$aTime = $a->getMTime(); $aTime = $a->getMTime();
$bTime = $b->getMTime(); $bTime = $b->getMTime();
return $aTime - $bTime; return $aTime - $bTime;
@ -90,7 +92,7 @@ class Helper
* @param \OCP\Files\FileInfo $b file * @param \OCP\Files\FileInfo $b file
* @return int -1 if $a must come before $b, 1 otherwise * @return int -1 if $a must come before $b, 1 otherwise
*/ */
public static function compareSize($a, $b) { public static function compareSize(FileInfo $a, FileInfo $b) {
$aSize = $a->getSize(); $aSize = $a->getSize();
$bSize = $b->getSize(); $bSize = $b->getSize();
return ($aSize < $bSize) ? -1 : 1; return ($aSize < $bSize) ? -1 : 1;
@ -102,7 +104,7 @@ class Helper
* @param \OCP\Files\FileInfo $i * @param \OCP\Files\FileInfo $i
* @return array formatted file info * @return array formatted file info
*/ */
public static function formatFileInfo($i) { public static function formatFileInfo(FileInfo $i) {
$entry = array(); $entry = array();
$entry['id'] = $i['fileid']; $entry['id'] = $i['fileid'];
@ -147,6 +149,7 @@ class Helper
/** /**
* Format file info for JSON * Format file info for JSON
* @param \OCP\Files\FileInfo[] $fileInfos file infos * @param \OCP\Files\FileInfo[] $fileInfos file infos
* @return array
*/ */
public static function formatFileInfos($fileInfos) { public static function formatFileInfos($fileInfos) {
$files = array(); $files = array();

View File

@ -89,7 +89,7 @@ class Helper {
* @param string $password * @param string $password
* @return bool * @return bool
*/ */
public static function setupUser($util, $password) { public static function setupUser(Util $util, $password) {
// Check files_encryption infrastructure is ready for action // Check files_encryption infrastructure is ready for action
if (!$util->ready()) { if (!$util->ready()) {
@ -333,7 +333,7 @@ class Helper {
* @param string $path * @param string $path
* @param \OC\Files\View $view * @param \OC\Files\View $view
*/ */
public static function mkdirr($path, $view) { public static function mkdirr($path, \OC\Files\View $view) {
$dirname = \OC\Files\Filesystem::normalizePath(dirname($path)); $dirname = \OC\Files\Filesystem::normalizePath(dirname($path));
$dirParts = explode('/', $dirname); $dirParts = explode('/', $dirname);
$dir = ""; $dir = "";
@ -348,8 +348,10 @@ class Helper {
/** /**
* redirect to a error page * redirect to a error page
* @param Session $session * @param Session $session
* @param int|null $errorCode
* @throws \Exception
*/ */
public static function redirectToErrorPage($session, $errorCode = null) { public static function redirectToErrorPage(Session $session, $errorCode = null) {
if ($errorCode === null) { if ($errorCode === null) {
$init = $session->getInitialized(); $init = $session->getInitialized();
@ -439,7 +441,7 @@ class Helper {
* @param \OC\Files\View $rootView root view, relative to data/ * @param \OC\Files\View $rootView root view, relative to data/
* @return array list of share key files, path relative to data/$user * @return array list of share key files, path relative to data/$user
*/ */
public static function findShareKeys($filePath, $shareKeyPath, $rootView) { public static function findShareKeys($filePath, $shareKeyPath, \OC\Files\View $rootView) {
$result = array(); $result = array();
$user = \OCP\User::getUser(); $user = \OCP\User::getUser();

View File

@ -740,7 +740,7 @@ class OC_Mount_Config {
* @param string $backend * @param string $backend
* @return string * @return string
*/ */
private static function getSingleDependencyMessage($l, $module, $backend) { private static function getSingleDependencyMessage(OC_L10N $l, $module, $backend) {
switch (strtolower($module)) { switch (strtolower($module)) {
case 'curl': case 'curl':
return $l->t('<b>Note:</b> The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend); return $l->t('<b>Note:</b> The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);

View File

@ -434,10 +434,10 @@ class Trashbin {
* @param string $filename name of file once it was deleted * @param string $filename name of file once it was deleted
* @param string $uniqueFilename new file name to restore the file without overwriting existing files * @param string $uniqueFilename new file name to restore the file without overwriting existing files
* @param string $location location if file * @param string $location location if file
* @param int $timestamp deleteion time * @param int $timestamp deletion time
* * @return bool
*/ */
private static function restoreVersions($view, $file, $filename, $uniqueFilename, $location, $timestamp) { private static function restoreVersions(\OC\Files\View $view, $file, $filename, $uniqueFilename, $location, $timestamp) {
if (\OCP\App::isEnabled('files_versions')) { if (\OCP\App::isEnabled('files_versions')) {
// disable proxy to prevent recursive calls // disable proxy to prevent recursive calls
@ -488,10 +488,10 @@ class Trashbin {
* @param string $filename name of file * @param string $filename name of file
* @param string $uniqueFilename new file name to restore the file without overwriting existing files * @param string $uniqueFilename new file name to restore the file without overwriting existing files
* @param string $location location of file * @param string $location location of file
* @param int $timestamp deleteion time * @param int $timestamp deletion time
* * @return bool
*/ */
private static function restoreEncryptionKeys($view, $file, $filename, $uniqueFilename, $location, $timestamp) { private static function restoreEncryptionKeys(\OC\Files\View $view, $file, $filename, $uniqueFilename, $location, $timestamp) {
// Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!) // Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!)
if (\OCP\App::isEnabled('files_encryption')) { if (\OCP\App::isEnabled('files_encryption')) {
$user = \OCP\User::getUser(); $user = \OCP\User::getUser();
@ -639,8 +639,12 @@ class Trashbin {
/** /**
* @param \OC\Files\View $view * @param \OC\Files\View $view
* @param $file
* @param $filename
* @param $timestamp
* @return int
*/ */
private static function deleteVersions($view, $file, $filename, $timestamp) { private static function deleteVersions(\OC\Files\View $view, $file, $filename, $timestamp) {
$size = 0; $size = 0;
if (\OCP\App::isEnabled('files_versions')) { if (\OCP\App::isEnabled('files_versions')) {
$user = \OCP\User::getUser(); $user = \OCP\User::getUser();
@ -664,8 +668,12 @@ class Trashbin {
/** /**
* @param \OC\Files\View $view * @param \OC\Files\View $view
* @param $file
* @param $filename
* @param $timestamp
* @return int
*/ */
private static function deleteEncryptionKeys($view, $file, $filename, $timestamp) { private static function deleteEncryptionKeys(\OC\Files\View $view, $file, $filename, $timestamp) {
$size = 0; $size = 0;
if (\OCP\App::isEnabled('files_encryption')) { if (\OCP\App::isEnabled('files_encryption')) {
$user = \OCP\User::getUser(); $user = \OCP\User::getUser();
@ -879,8 +887,10 @@ class Trashbin {
* @param string $source source path, relative to the users files directory * @param string $source source path, relative to the users files directory
* @param string $destination destination path relative to the users root directoy * @param string $destination destination path relative to the users root directoy
* @param \OC\Files\View $view file view for the users root directory * @param \OC\Files\View $view file view for the users root directory
* @return int
* @throws Exceptions\CopyRecursiveException
*/ */
private static function copy_recursive($source, $destination, $view) { private static function copy_recursive($source, $destination, \OC\Files\View $view) {
$size = 0; $size = 0;
if ($view->is_dir($source)) { if ($view->is_dir($source)) {
$view->mkdir($destination); $view->mkdir($destination);
@ -955,7 +965,7 @@ class Trashbin {
* @param \OC\Files\View $view filesystem view relative to users root directory * @param \OC\Files\View $view filesystem view relative to users root directory
* @return string with unique extension * @return string with unique extension
*/ */
private static function getUniqueFilename($location, $filename, $view) { private static function getUniqueFilename($location, $filename, \OC\Files\View $view) {
$ext = pathinfo($filename, PATHINFO_EXTENSION); $ext = pathinfo($filename, PATHINFO_EXTENSION);
$name = pathinfo($filename, PATHINFO_FILENAME); $name = pathinfo($filename, PATHINFO_FILENAME);
$l = \OC::$server->getL10N('files_trashbin'); $l = \OC::$server->getL10N('files_trashbin');
@ -1036,6 +1046,7 @@ class Trashbin {
/** /**
* check if trash bin is empty for a given user * check if trash bin is empty for a given user
* @param string $user * @param string $user
* @return bool
*/ */
public static function isEmpty($user) { public static function isEmpty($user) {
@ -1050,6 +1061,10 @@ class Trashbin {
return true; return true;
} }
/**
* @param $path
* @return string
*/
public static function preview_icon($path) { public static function preview_icon($path) {
return \OC_Helper::linkToRoute('core_ajax_trashbin_preview', array('x' => 36, 'y' => 36, 'file' => $path)); return \OC_Helper::linkToRoute('core_ajax_trashbin_preview', array('x' => 36, 'y' => 36, 'file' => $path));
} }

View File

@ -144,7 +144,7 @@ class MDB2SchemaManager {
} }
/** /**
* @param \Doctrine\DBAL\Schema\Schema $schema * @param \Doctrine\DBAL\Schema\Schema|\Doctrine\DBAL\Schema\SchemaDiff $schema
* @return bool * @return bool
*/ */
private function executeSchemaChange($schema) { private function executeSchemaChange($schema) {

View File

@ -195,7 +195,7 @@ class OC_Files {
* @param ZipStreamer $zip * @param ZipStreamer $zip
* @param string $internalDir * @param string $internalDir
*/ */
public static function zipAddDir($dir, $zip, $internalDir='') { public static function zipAddDir($dir, ZipStreamer $zip, $internalDir='') {
$dirname=basename($dir); $dirname=basename($dir);
$rootDir = $internalDir.$dirname; $rootDir = $internalDir.$dirname;
if (!empty($rootDir)) { if (!empty($rootDir)) {

View File

@ -19,7 +19,7 @@ class Manager {
/** /**
* @param Mount $mount * @param Mount $mount
*/ */
public function addMount($mount) { public function addMount(Mount $mount) {
$this->mounts[$mount->getMountPoint()] = $mount; $this->mounts[$mount->getMountPoint()] = $mount;
} }

View File

@ -779,7 +779,7 @@ class Preview {
* @param \OC\Files\FileInfo $file * @param \OC\Files\FileInfo $file
* @return bool * @return bool
*/ */
public static function isAvailable($file) { public static function isAvailable(\OC\Files\FileInfo $file) {
if (!\OC_Config::getValue('enable_previews', true)) { if (!\OC_Config::getValue('enable_previews', true)) {
return false; return false;
} }

View File

@ -72,15 +72,15 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('PreviewManager', function ($c) { $this->registerService('PreviewManager', function ($c) {
return new PreviewManager(); return new PreviewManager();
}); });
$this->registerService('TagMapper', function($c) { $this->registerService('TagMapper', function(Server $c) {
return new TagMapper($c->getDb()); return new TagMapper($c->getDb());
}); });
$this->registerService('TagManager', function ($c) { $this->registerService('TagManager', function (Server $c) {
$tagMapper = $c->query('TagMapper'); $tagMapper = $c->query('TagMapper');
$user = \OC_User::getUser(); $user = \OC_User::getUser();
return new TagManager($tagMapper, $user); return new TagManager($tagMapper, $user);
}); });
$this->registerService('RootFolder', function ($c) { $this->registerService('RootFolder', function (Server $c) {
// TODO: get user and user manager from container as well // TODO: get user and user manager from container as well
$user = \OC_User::getUser(); $user = \OC_User::getUser();
/** @var $c SimpleContainer */ /** @var $c SimpleContainer */
@ -90,28 +90,16 @@ class Server extends SimpleContainer implements IServerContainer {
$view = new View(); $view = new View();
return new Root($manager, $view, $user); return new Root($manager, $view, $user);
}); });
$this->registerService('UserManager', function ($c) { $this->registerService('UserManager', function (Server $c) {
/** $config = $c->getConfig();
* @var SimpleContainer $c
* @var \OC\AllConfig $config
*/
$config = $c->query('AllConfig');
return new \OC\User\Manager($config); return new \OC\User\Manager($config);
}); });
$this->registerService('GroupManager', function ($c) { $this->registerService('GroupManager', function (Server $c) {
/** $userManager = $c->getUserManager();
* @var SimpleContainer $c
* @var \OC\User\Manager $userManager
*/
$userManager = $c->query('UserManager');
return new \OC\Group\Manager($userManager); return new \OC\Group\Manager($userManager);
}); });
$this->registerService('UserSession', function ($c) { $this->registerService('UserSession', function (Server $c) {
/** $manager = $c->getUserManager();
* @var SimpleContainer $c
* @var \OC\User\Manager $manager
*/
$manager = $c->query('UserManager');
$userSession = new \OC\User\Session($manager, new \OC\Session\Memory('')); $userSession = new \OC\User\Session($manager, new \OC\Session\Memory(''));
$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
@ -160,9 +148,8 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('L10NFactory', function ($c) { $this->registerService('L10NFactory', function ($c) {
return new \OC\L10N\Factory(); return new \OC\L10N\Factory();
}); });
$this->registerService('URLGenerator', function ($c) { $this->registerService('URLGenerator', function (Server $c) {
/** @var $c SimpleContainer */ $config = $c->getConfig();
$config = $c->query('AllConfig');
return new \OC\URLGenerator($config); return new \OC\URLGenerator($config);
}); });
$this->registerService('AppHelper', function ($c) { $this->registerService('AppHelper', function ($c) {
@ -181,25 +168,18 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('AvatarManager', function ($c) { $this->registerService('AvatarManager', function ($c) {
return new AvatarManager(); return new AvatarManager();
}); });
$this->registerService('Logger', function ($c) { $this->registerService('Logger', function (Server $c) {
/** @var $c SimpleContainer */
$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud'); $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
$logger = 'OC_Log_' . ucfirst($logClass); $logger = 'OC_Log_' . ucfirst($logClass);
call_user_func(array($logger, 'init')); call_user_func(array($logger, 'init'));
return new Log($logger); return new Log($logger);
}); });
$this->registerService('JobList', function ($c) { $this->registerService('JobList', function (Server $c) {
/**
* @var Server $c
*/
$config = $c->getConfig(); $config = $c->getConfig();
return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
}); });
$this->registerService('Router', function ($c) { $this->registerService('Router', function (Server $c) {
/**
* @var Server $c
*/
$cacheFactory = $c->getMemCacheFactory(); $cacheFactory = $c->getMemCacheFactory();
if ($cacheFactory->isAvailable()) { if ($cacheFactory->isAvailable()) {
$router = new \OC\Route\CachingRouter($cacheFactory->create('route')); $router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
@ -214,13 +194,10 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('SecureRandom', function ($c) { $this->registerService('SecureRandom', function ($c) {
return new SecureRandom(); return new SecureRandom();
}); });
$this->registerService('Crypto', function ($c) { $this->registerService('Crypto', function (Server $c) {
return new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom()); return new Crypto($c->getConfig(), $c->getSecureRandom());
}); });
$this->registerService('DatabaseConnection', function ($c) { $this->registerService('DatabaseConnection', function (Server $c) {
/**
* @var Server $c
*/
$factory = new \OC\DB\ConnectionFactory(); $factory = new \OC\DB\ConnectionFactory();
$type = $c->getConfig()->getSystemValue('dbtype', 'sqlite'); $type = $c->getConfig()->getSystemValue('dbtype', 'sqlite');
if (!$factory->isValidType($type)) { if (!$factory->isValidType($type)) {
@ -231,18 +208,14 @@ class Server extends SimpleContainer implements IServerContainer {
$connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
return $connection; return $connection;
}); });
$this->registerService('Db', function ($c) { $this->registerService('Db', function (Server $c) {
/**
* @var Server $c
*/
return new Db($c->getDatabaseConnection()); return new Db($c->getDatabaseConnection());
}); });
$this->registerService('HTTPHelper', function (SimpleContainer $c) { $this->registerService('HTTPHelper', function (Server $c) {
$config = $c->query('AllConfig'); $config = $c->getConfig();
return new HTTPHelper($config); return new HTTPHelper($config);
}); });
$this->registerService('EventLogger', function ($c) { $this->registerService('EventLogger', function (Server $c) {
/** @var Server $c */
if (defined('DEBUG') and DEBUG) { if (defined('DEBUG') and DEBUG) {
return new EventLogger(); return new EventLogger();
} else { } else {

View File

@ -420,7 +420,7 @@ class OC_Util {
* @param \OCP\IConfig $config * @param \OCP\IConfig $config
* @return array arrays with error messages and hints * @return array arrays with error messages and hints
*/ */
public static function checkServer($config) { public static function checkServer(\OCP\IConfig $config) {
$l = \OC::$server->getL10N('lib'); $l = \OC::$server->getL10N('lib');
$errors = array(); $errors = array();
$CONFIG_DATADIRECTORY = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data'); $CONFIG_DATADIRECTORY = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data');
@ -1309,7 +1309,7 @@ class OC_Util {
* @param \OCP\IConfig $config * @param \OCP\IConfig $config
* @return bool whether the core or any app needs an upgrade * @return bool whether the core or any app needs an upgrade
*/ */
public static function needUpgrade($config) { public static function needUpgrade(\OCP\IConfig $config) {
if ($config->getSystemValue('installed', false)) { if ($config->getSystemValue('installed', false)) {
$installedVersion = $config->getSystemValue('version', '0.0.0'); $installedVersion = $config->getSystemValue('version', '0.0.0');
$currentVersion = implode('.', OC_Util::getVersion()); $currentVersion = implode('.', OC_Util::getVersion());