3838class Loader implements IMimeTypeLoader {
3939 use TTransactional;
4040
41- /** @var IDBConnection */
42- private $ dbConnection ;
41+ private IDBConnection $ dbConnection ;
4342
44- /** @var array [id => mimetype] */
45- protected $ mimetypes ;
43+ /** @psalm- var array<int, string> */
44+ protected array $ mimetypes ;
4645
47- /** @var array [mimetype => id] */
48- protected $ mimetypeIds ;
46+ /** @psalm- var array<string, int> */
47+ protected array $ mimetypeIds ;
4948
5049 /**
5150 * @param IDBConnection $dbConnection
@@ -58,11 +57,8 @@ public function __construct(IDBConnection $dbConnection) {
5857
5958 /**
6059 * Get a mimetype from its ID
61- *
62- * @param int $id
63- * @return string|null
6460 */
65- public function getMimetypeById ($ id ) {
61+ public function getMimetypeById (int $ id ): ? string {
6662 if (!$ this ->mimetypes ) {
6763 $ this ->loadMimetypes ();
6864 }
@@ -74,11 +70,8 @@ public function getMimetypeById($id) {
7470
7571 /**
7672 * Get a mimetype ID, adding the mimetype to the DB if it does not exist
77- *
78- * @param string $mimetype
79- * @return int
8073 */
81- public function getId ($ mimetype ) {
74+ public function getId (string $ mimetype ): int {
8275 if (!$ this ->mimetypeIds ) {
8376 $ this ->loadMimetypes ();
8477 }
@@ -90,11 +83,8 @@ public function getId($mimetype) {
9083
9184 /**
9285 * Test if a mimetype exists in the database
93- *
94- * @param string $mimetype
95- * @return bool
9686 */
97- public function exists ($ mimetype ) {
87+ public function exists (string $ mimetype ): bool {
9888 if (!$ this ->mimetypeIds ) {
9989 $ this ->loadMimetypes ();
10090 }
@@ -104,7 +94,7 @@ public function exists($mimetype) {
10494 /**
10595 * Clear all loaded mimetypes, allow for re-loading
10696 */
107- public function reset () {
97+ public function reset (): void {
10898 $ this ->mimetypes = [];
10999 $ this ->mimetypeIds = [];
110100 }
@@ -115,7 +105,7 @@ public function reset() {
115105 * @param string $mimetype
116106 * @return int inserted ID
117107 */
118- protected function store ($ mimetype ) {
108+ protected function store (string $ mimetype ): int {
119109 try {
120110 $ mimetypeId = $ this ->atomic (function () use ($ mimetype ) {
121111 $ insert = $ this ->dbConnection ->getQueryBuilder ();
@@ -153,29 +143,27 @@ protected function store($mimetype) {
153143 /**
154144 * Load all mimetypes from DB
155145 */
156- private function loadMimetypes () {
146+ private function loadMimetypes (): void {
157147 $ qb = $ this ->dbConnection ->getQueryBuilder ();
158148 $ qb ->select ('id ' , 'mimetype ' )
159149 ->from ('mimetypes ' );
160150
161- $ result = $ qb ->execute ();
151+ $ result = $ qb ->executeQuery ();
162152 $ results = $ result ->fetchAll ();
163153 $ result ->closeCursor ();
164154
165155 foreach ($ results as $ row ) {
166- $ this ->mimetypes [$ row ['id ' ]] = $ row ['mimetype ' ];
167- $ this ->mimetypeIds [$ row ['mimetype ' ]] = $ row ['id ' ];
156+ $ this ->mimetypes [( int ) $ row ['id ' ]] = $ row ['mimetype ' ];
157+ $ this ->mimetypeIds [$ row ['mimetype ' ]] = ( int ) $ row ['id ' ];
168158 }
169159 }
170160
171161 /**
172162 * Update filecache mimetype based on file extension
173163 *
174- * @param string $ext file extension
175- * @param int $mimeTypeId
176164 * @return int number of changed rows
177165 */
178- public function updateFilecache ($ ext , $ mimeTypeId ) {
166+ public function updateFilecache (string $ ext , int $ mimeTypeId ): int {
179167 $ folderMimeTypeId = $ this ->getId ('httpd/unix-directory ' );
180168 $ update = $ this ->dbConnection ->getQueryBuilder ();
181169 $ update ->update ('filecache ' )
0 commit comments