diff --git a/lib/private/TagManager.php b/lib/private/TagManager.php index 82c4dd2188d8d..9b5bfb7166d2f 100644 --- a/lib/private/TagManager.php +++ b/lib/private/TagManager.php @@ -42,30 +42,26 @@ * @template-implements IEventListener */ class TagManager implements ITagManager, IEventListener { - private TagMapper $mapper; - private IUserSession $userSession; - private IDBConnection $connection; - private LoggerInterface $logger; - - public function __construct(TagMapper $mapper, IUserSession $userSession, IDBConnection $connection, LoggerInterface $logger) { - $this->mapper = $mapper; - $this->userSession = $userSession; - $this->connection = $connection; - $this->logger = $logger; + public function __construct( + private TagMapper $mapper, + private IUserSession $userSession, + private IDBConnection $connection, + private LoggerInterface $logger, + ) { } /** * Create a new \OCP\ITags instance and load tags from db. * - * @see \OCP\ITags * @param string $type The type identifier e.g. 'contact' or 'event'. * @param array $defaultTags An array of default tags to be used if none are stored. * @param boolean $includeShared Whether to include tags for items shared with this user by others. - * @param string $userId user for which to retrieve the tags, defaults to the currently + * @param string|null $userId user for which to retrieve the tags, defaults to the currently * logged in user * @return \OCP\ITags * * since 20.0.0 $includeShared isn't used anymore + * @see \OCP\ITags */ public function load($type, $defaultTags = [], $includeShared = false, $userId = null) { if (is_null($userId)) { diff --git a/lib/private/Tags.php b/lib/private/Tags.php index 8da1e7edc3b8a..b0cff4b3f5b32 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -45,10 +45,6 @@ class Tags implements ITags { * Used for storing objectid/categoryname pairs while rescanning. */ private static array $relations = []; - private string $type; - private string $user; - private IDBConnection $db; - private LoggerInterface $logger; private array $tags = []; /** @@ -62,11 +58,6 @@ class Tags implements ITags { */ private array $owners = []; - /** - * The Mapper we are using to communicate our Tag objects to the database. - */ - private TagMapper $mapper; - /** * The sharing backend for objects of $this->type. Required if * $this->includeShared === true to determine ownership of items. @@ -86,14 +77,16 @@ class Tags implements ITags { * * since 20.0.0 $includeShared isn't used anymore */ - public function __construct(TagMapper $mapper, string $user, string $type, LoggerInterface $logger, IDBConnection $connection, array $defaultTags = []) { - $this->mapper = $mapper; - $this->user = $user; - $this->type = $type; + public function __construct( + private TagMapper $mapper, + private string $user, + private string $type, + private LoggerInterface $logger, + private IDBConnection $db, + array $defaultTags = [], + ) { $this->owners = [$this->user]; $this->tags = $this->mapper->loadTags($this->owners, $this->type); - $this->db = $connection; - $this->logger = $logger; if (count($defaultTags) > 0 && count($this->tags) === 0) { $this->addMultiple($defaultTags, true); @@ -116,7 +109,7 @@ public function isEmpty(): bool { * @param string $id The ID of the tag that is going to be mapped * @return array|false */ - public function getTag(string $id) { + public function getTag(string $id): bool|array { $key = $this->getTagById($id); if ($key !== false) { return $this->tagMap($this->tags[$key]); @@ -175,7 +168,7 @@ function ($tag) use ($user) { * @return array|false of tags id as key to array of tag names * or false if an error occurred */ - public function getTagsForObjects(array $objIds) { + public function getTagsForObjects(array $objIds): bool|array { $entries = []; try { @@ -213,7 +206,7 @@ public function getTagsForObjects(array $objIds) { } /** - * Get the a list if items tagged with $tag. + * Get the list if items tagged with $tag. * * Throws an exception if the tag could not be found. * @@ -221,7 +214,7 @@ public function getTagsForObjects(array $objIds) { * @return int[]|false An array of object ids or false on error. * @throws \Exception */ - public function getIdsForTag($tag) { + public function getIdsForTag($tag): array|bool { $tagId = false; if (is_numeric($tag)) { $tagId = $tag; @@ -291,7 +284,7 @@ public function hasTag(string $name): bool { * @param string $name A string with a name of the tag * @return false|int the id of the added tag or false on error. */ - public function add(string $name) { + public function add(string $name): bool|int { $name = trim($name); if ($name === '') { @@ -478,7 +471,7 @@ public function purgeObjects(array $ids): bool { * * @return array|false An array of object ids. */ - public function getFavorites() { + public function getFavorites(): array|bool { if (!$this->userHasTag(ITags::TAG_FAVORITE, $this->user)) { return []; } @@ -501,7 +494,7 @@ public function getFavorites() { * @param int $objid The id of the object * @return boolean */ - public function addToFavorites($objid) { + public function addToFavorites($objid): bool { if (!$this->userHasTag(ITags::TAG_FAVORITE, $this->user)) { $this->add(ITags::TAG_FAVORITE); } @@ -514,7 +507,7 @@ public function addToFavorites($objid) { * @param int $objid The id of the object * @return boolean */ - public function removeFromFavorites($objid) { + public function removeFromFavorites($objid): bool { return $this->unTag($objid, ITags::TAG_FAVORITE); } @@ -525,7 +518,7 @@ public function removeFromFavorites($objid) { * @param string $tag The id or name of the tag * @return boolean Returns false on error. */ - public function tagAs($objid, $tag) { + public function tagAs($objid, $tag): bool { if (is_string($tag) && !is_numeric($tag)) { $tag = trim($tag); if ($tag === '') { @@ -565,7 +558,7 @@ public function tagAs($objid, $tag) { * @param string $tag The id or name of the tag * @return boolean */ - public function unTag($objid, $tag) { + public function unTag($objid, $tag): bool { if (is_string($tag) && !is_numeric($tag)) { $tag = trim($tag); if ($tag === '') { @@ -601,7 +594,7 @@ public function unTag($objid, $tag) { * @param string[]|integer[] $names An array of tags (names or IDs) to delete * @return bool Returns false on error */ - public function delete($names) { + public function delete($names): bool { if (!is_array($names)) { $names = [$names]; } @@ -647,7 +640,7 @@ public function delete($names) { } // case-insensitive array_search - protected function array_searchi($needle, $haystack, $mem = 'getName') { + protected function array_searchi($needle, $haystack, $mem = 'getName'): bool|int|string { if (!is_array($haystack)) { return false; } @@ -664,7 +657,7 @@ function ($tag) use ($mem) { * @param string $name The tag name to look for. * @return string|bool The tag's id or false if no matching tag is found. */ - private function getTagId($name) { + private function getTagId(string $name): bool|string { $key = $this->array_searchi($name, $this->tags); if ($key !== false) { return $this->tags[$key]->getId(); @@ -676,10 +669,10 @@ private function getTagId($name) { * Get a tag by its name. * * @param string $name The tag name. - * @return integer|bool The tag object's offset within the $this->tags + * @return bool|int|string The tag object's offset within the $this->tags * array or false if it doesn't exist. */ - private function getTagByName($name) { + private function getTagByName(string $name): bool|int|string { return $this->array_searchi($name, $this->tags, 'getName'); } @@ -687,10 +680,10 @@ private function getTagByName($name) { * Get a tag by its ID. * * @param string $id The tag ID to look for. - * @return integer|bool The tag object's offset within the $this->tags + * @return bool|int|string The tag object's offset within the $this->tags * array or false if it doesn't exist. */ - private function getTagById($id) { + private function getTagById(string $id): bool|int|string { return $this->array_searchi($id, $this->tags, 'getId'); } @@ -701,7 +694,7 @@ private function getTagById($id) { * @param Tag $tag The tag that is going to be mapped * @return array */ - private function tagMap(Tag $tag) { + private function tagMap(Tag $tag): array { return [ 'id' => $tag->getId(), 'name' => $tag->getName(), diff --git a/lib/private/TempManager.php b/lib/private/TempManager.php index 0df31dce3fff1..1655f38d6a0ec 100644 --- a/lib/private/TempManager.php +++ b/lib/private/TempManager.php @@ -38,23 +38,18 @@ class TempManager implements ITempManager { /** @var string[] Current temporary files and folders, used for cleanup */ - protected $current = []; + protected array $current = []; /** @var string i.e. /tmp on linux systems */ - protected $tmpBaseDir; - /** @var LoggerInterface */ - protected $log; - /** @var IConfig */ - protected $config; - /** @var IniGetWrapper */ - protected $iniGetWrapper; + protected string $tmpBaseDir; /** Prefix */ public const TMP_PREFIX = 'oc_tmp_'; - public function __construct(LoggerInterface $logger, IConfig $config, IniGetWrapper $iniGetWrapper) { - $this->log = $logger; - $this->config = $config; - $this->iniGetWrapper = $iniGetWrapper; + public function __construct( + protected LoggerInterface $log, + protected IConfig $config, + protected IniGetWrapper $iniGetWrapper, + ) { $this->tmpBaseDir = $this->getTempBaseDir(); } @@ -66,7 +61,7 @@ public function __construct(LoggerInterface $logger, IConfig $config, IniGetWrap * @param string $postFix Postfix appended to the temporary file name, may be user controlled * @return string */ - private function buildFileNameWithSuffix($absolutePath, $postFix = '') { + private function buildFileNameWithSuffix(string $absolutePath, string $postFix = ''): string { if ($postFix !== '') { $postFix = '.' . ltrim($postFix, '.'); $postFix = str_replace(['\\', '/'], '', $postFix); @@ -84,7 +79,7 @@ private function buildFileNameWithSuffix($absolutePath, $postFix = '') { */ public function getTemporaryFile($postFix = '') { if (is_writable($this->tmpBaseDir)) { - // To create an unique file and prevent the risk of race conditions + // To create a unique file and prevent the risk of race conditions // or duplicated temporary files by other means such as collisions // we need to create the file using `tempnam` and append a possible // postfix to it later @@ -148,14 +143,14 @@ public function getTemporaryFolder($postFix = '') { /** * Remove the temporary files and folders generated during this request */ - public function clean() { + public function clean(): void { $this->cleanFiles($this->current); } /** * @param string[] $files */ - protected function cleanFiles($files) { + protected function cleanFiles(array $files): void { foreach ($files as $file) { if (file_exists($file)) { try { @@ -176,7 +171,7 @@ protected function cleanFiles($files) { /** * Remove old temporary files and folders that were failed to be cleaned */ - public function cleanOld() { + public function cleanOld(): void { $this->cleanFiles($this->getOldFiles()); } @@ -185,7 +180,7 @@ public function cleanOld() { * * @return string[] */ - protected function getOldFiles() { + protected function getOldFiles(): array { $cutOfTime = time() - 3600; $files = []; $dh = opendir($this->tmpBaseDir); @@ -209,7 +204,7 @@ protected function getOldFiles() { * @return string Path to the temporary directory or null * @throws \UnexpectedValueException */ - public function getTempBaseDir() { + public function getTempBaseDir(): string { if ($this->tmpBaseDir) { return $this->tmpBaseDir; } @@ -254,7 +249,7 @@ public function getTempBaseDir() { * @param mixed $directory * @return bool */ - private function checkTemporaryDirectory($directory) { + private function checkTemporaryDirectory(mixed $directory): bool { // suppress any possible errors caused by is_writable // checks missing or invalid path or characters, wrong permissions etc try { @@ -274,7 +269,7 @@ private function checkTemporaryDirectory($directory) { * * @param string $directory */ - public function overrideTempBaseDir($directory) { + public function overrideTempBaseDir(string $directory): void { $this->tmpBaseDir = $directory; } } diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 658a85152bf49..eb15f1e7b5130 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -57,22 +57,22 @@ use OCP\Util; class TemplateLayout extends \OC_Template { - private static $versionHash = ''; + private static string $versionHash = ''; /** @var CSSResourceLocator|null */ - public static $cssLocator = null; + public static ?CSSResourceLocator $cssLocator = null; /** @var JSResourceLocator|null */ - public static $jsLocator = null; + public static ?JSResourceLocator $jsLocator = null; /** @var IConfig */ - private $config; + private mixed $config; /** @var IInitialStateService */ - private $initialState; + private mixed $initialState; /** @var INavigationManager */ - private $navigationManager; + private mixed $navigationManager; /** * @param string $renderAs @@ -279,7 +279,7 @@ public function __construct($renderAs, $appId = '') { $web = $info[1]; $file = $info[2]; - if (substr($file, -strlen('print.css')) === 'print.css') { + if (str_ends_with($file, 'print.css')) { $this->append('printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix()); } else { $suffix = $this->getVersionHashSuffix($web, $file); @@ -299,11 +299,11 @@ public function __construct($renderAs, $appId = '') { } /** - * @param string $path - * @param string $file + * @param bool|string $path + * @param bool|string $file * @return string */ - protected function getVersionHashSuffix($path = false, $file = false) { + protected function getVersionHashSuffix(bool|string $path = false, bool|string $file = false): string { if ($this->config->getSystemValueBool('debug', false)) { // allows chrome workspace mapping in debug mode return ""; @@ -342,7 +342,7 @@ protected function getVersionHashSuffix($path = false, $file = false) { * @param array $styles * @return array */ - public static function findStylesheetFiles($styles, $compileScss = true) { + public static function findStylesheetFiles(array $styles, $compileScss = true): array { if (!self::$cssLocator) { self::$cssLocator = \OCP\Server::get(CSSResourceLocator::class); } @@ -354,7 +354,7 @@ public static function findStylesheetFiles($styles, $compileScss = true) { * @param string $path * @return string|boolean */ - public function getAppNamefromPath($path) { + public function getAppNamefromPath(string $path): bool|string { if ($path !== '' && is_string($path)) { $pathParts = explode('/', $path); if ($pathParts[0] === 'css') { @@ -370,7 +370,7 @@ public function getAppNamefromPath($path) { * @param array $scripts * @return array */ - public static function findJavascriptFiles($scripts) { + public static function findJavascriptFiles(array $scripts): array { if (!self::$jsLocator) { self::$jsLocator = \OCP\Server::get(JSResourceLocator::class); } @@ -380,11 +380,12 @@ public static function findJavascriptFiles($scripts) { /** * Converts the absolute file path to a relative path from \OC::$SERVERROOT + * * @param string $filePath Absolute path * @return string Relative path * @throws \Exception If $filePath is not under \OC::$SERVERROOT */ - public static function convertToRelativePath($filePath) { + public static function convertToRelativePath(string $filePath): string { $relativePath = explode(\OC::$SERVERROOT, $filePath); if (count($relativePath) !== 2) { throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index 3a52b99889c05..7e7f7e547dfc7 100644 --- a/lib/private/URLGenerator.php +++ b/lib/private/URLGenerator.php @@ -55,31 +55,17 @@ * Class to generate URLs */ class URLGenerator implements IURLGenerator { - /** @var IConfig */ - private $config; - /** @var IUserSession */ - public $userSession; - /** @var ICacheFactory */ - private $cacheFactory; - /** @var IRequest */ - private $request; - /** @var Router */ - private $router; /** @var null|string */ - private $baseUrl = null; + private ?string $baseUrl = null; private ?IAppManager $appManager = null; - public function __construct(IConfig $config, - IUserSession $userSession, - ICacheFactory $cacheFactory, - IRequest $request, - Router $router + public function __construct( + private IConfig $config, + public IUserSession $userSession, + private ICacheFactory $cacheFactory, + private IRequest $request, + private Router $router, ) { - $this->config = $config; - $this->userSession = $userSession; - $this->cacheFactory = $cacheFactory; - $this->request = $request; - $this->router = $router; } private function getAppManager(): IAppManager { @@ -147,7 +133,7 @@ public function linkTo(string $appName, string $file, array $args = []): string $app_path = $this->getAppManager()->getAppPath($appName); // Check if the app is in the app folder if (file_exists($app_path . '/' . $file)) { - if (substr($file, -3) === 'php') { + if (str_ends_with($file, 'php')) { $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $appName; if ($frontControllerActive) { $urlLinkTo = \OC::$WEBROOT . '/apps/' . $appName; @@ -183,7 +169,7 @@ public function linkTo(string $appName, string $file, array $args = []): string * * @param string $appName app * @param string $file image name - * @throws \RuntimeException If the image does not exist + * @throws \RuntimeException|AppPathNotFoundException If the image does not exist * @return string the url * * Returns the path to the image. @@ -198,7 +184,7 @@ public function imagePath(string $appName, string $file): string { // Read the selected theme from the config file $theme = \OC_Util::getTheme(); - //if a theme has a png but not an svg always use the png + //if a theme has a png but not a svg always use the png $basename = substr(basename($file), 0, -4); try { diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 5a14bb1750779..e7fe016ce47ea 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -73,19 +73,7 @@ * - failure(string $message) */ class Updater extends BasicEmitter { - /** @var LoggerInterface */ - private $log; - - /** @var IConfig */ - private $config; - - /** @var Checker */ - private $checker; - - /** @var Installer */ - private $installer; - - private $logLevelNames = [ + private array $logLevelNames = [ 0 => 'Debug', 1 => 'Info', 2 => 'Warning', @@ -93,14 +81,12 @@ class Updater extends BasicEmitter { 4 => 'Fatal', ]; - public function __construct(IConfig $config, - Checker $checker, - ?LoggerInterface $log, - Installer $installer) { - $this->log = $log; - $this->config = $config; - $this->checker = $checker; - $this->installer = $installer; + public function __construct( + private IConfig $config, + private Checker $checker, + private ?LoggerInterface $log, + private Installer $installer, + ) { } /** @@ -271,7 +257,7 @@ private function doUpgrade(string $currentVersion, string $installedVersion): vo $this->checkAppsRequirements(); $this->doAppUpgrade(); - // Update the appfetchers version so it downloads the correct list from the appstore + // Update the appfetchers version, so it downloads the correct list from the appstore \OC::$server->getAppFetcher()->setVersion($currentVersion); /** @var AppManager $appManager */