Skip to content

Commit

Permalink
[TASK] Annotate that methods from InaccessibleFolder never return
Browse files Browse the repository at this point in the history
Methods from InaccessibleFolder should not be called and always
throw an exception when called. Annotate this to help static code
analysis understand this.

Resolves: #97859
Releases: main, 11.5
Change-Id: Id3f563e5cd2780715a860de7faf567f9cb960d30
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75034
Tested-by: core-ci <typo3@b13.com>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
oliverklee authored and bmack committed Jul 7, 2022
1 parent 35c5490 commit e06c7d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 92 deletions.
70 changes: 0 additions & 70 deletions Build/phpstan/phpstan-baseline.neon
Expand Up @@ -1040,76 +1040,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Resource/Folder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:addFile\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:addUploadedFile\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:copyTo\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:createFile\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:createFolder\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:delete\\(\\) should return bool but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:getFileCount\\(\\) should return int but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:getFiles\\(\\) should return array\\<TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File\\> but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:getSubfolder\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:getSubfolders\\(\\) should return array\\<TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder\\> but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:hasFile\\(\\) should return bool but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:hasFolder\\(\\) should return bool but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:moveTo\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\InaccessibleFolder\\:\\:rename\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/InaccessibleFolder.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Index\\\\ExtractorRegistry\\:\\:getExtractorsWithDriverSupport\\(\\) should return array\\<TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Index\\\\ExtractorInterface\\> but returns array\\<int, array\\<int, TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Index\\\\ExtractorInterface\\>\\>\\.$#"
count: 1
Expand Down
41 changes: 19 additions & 22 deletions typo3/sysext/core/Classes/Resource/InaccessibleFolder.php
Expand Up @@ -33,7 +33,7 @@ class InaccessibleFolder extends Folder
*
* @throws Exception\InsufficientFolderReadPermissionsException
*/
protected function throwInaccessibleException()
protected function throwInaccessibleException(): never
{
throw new InsufficientFolderReadPermissionsException(
'You are trying to use a method on the inaccessible folder "' . $this->getName() . '".',
Expand All @@ -48,7 +48,7 @@ protected function throwInaccessibleException()
*
* @param string $name The new name
*/
public function setName($name)
public function setName($name): never
{
$this->throwInaccessibleException();
}
Expand All @@ -58,13 +58,10 @@ public function setName($name)
*
* WARNING: Access to the folder may be restricted by further means, e.g. some
* web-based authentication. You have to take care of this yourself.
*
* @return string|null NULL if file is missing or deleted, the generated url otherwise
*/
public function getPublicUrl()
public function getPublicUrl(): never
{
$this->throwInaccessibleException();
return null;
}

/**
Expand All @@ -81,7 +78,7 @@ public function getPublicUrl()
* @param bool $sortRev
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function getFiles($start = 0, $numberOfItems = 0, $filterMode = self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive = false, $sort = '', $sortRev = false)
public function getFiles($start = 0, $numberOfItems = 0, $filterMode = self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive = false, $sort = '', $sortRev = false): never
{
$this->throwInaccessibleException();
}
Expand All @@ -94,7 +91,7 @@ public function getFiles($start = 0, $numberOfItems = 0, $filterMode = self::FIL
* @param bool $recursive
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function getFileCount(array $filterMethods = [], $recursive = false)
public function getFileCount(array $filterMethods = [], $recursive = false): never
{
$this->throwInaccessibleException();
}
Expand All @@ -105,7 +102,7 @@ public function getFileCount(array $filterMethods = [], $recursive = false)
* @param string $name Name of the subfolder
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function getSubfolder($name)
public function getSubfolder($name): never
{
$this->throwInaccessibleException();
}
Expand All @@ -119,7 +116,7 @@ public function getSubfolder($name)
* @param bool $recursive
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function getSubfolders($start = 0, $numberOfItems = 0, $filterMode = self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive = false)
public function getSubfolders($start = 0, $numberOfItems = 0, $filterMode = self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive = false): never
{
$this->throwInaccessibleException();
}
Expand All @@ -133,7 +130,7 @@ public function getSubfolders($start = 0, $numberOfItems = 0, $filterMode = self
* @param string $conflictMode a value of the DuplicationBehavior enumeration
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function addFile($localFilePath, $fileName = null, $conflictMode = DuplicationBehavior::CANCEL)
public function addFile($localFilePath, $fileName = null, $conflictMode = DuplicationBehavior::CANCEL): never
{
$this->throwInaccessibleException();
}
Expand All @@ -145,7 +142,7 @@ public function addFile($localFilePath, $fileName = null, $conflictMode = Duplic
* @param string $conflictMode a value of the DuplicationBehavior enumeration
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function addUploadedFile(array $uploadedFileData, $conflictMode = DuplicationBehavior::CANCEL)
public function addUploadedFile(array $uploadedFileData, $conflictMode = DuplicationBehavior::CANCEL): never
{
$this->throwInaccessibleException();
}
Expand All @@ -156,7 +153,7 @@ public function addUploadedFile(array $uploadedFileData, $conflictMode = Duplica
* @param string $newName
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function rename($newName)
public function rename($newName): never
{
$this->throwInaccessibleException();
}
Expand All @@ -167,7 +164,7 @@ public function rename($newName)
* @param bool $deleteRecursively
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function delete($deleteRecursively = true)
public function delete($deleteRecursively = true): never
{
$this->throwInaccessibleException();
}
Expand All @@ -178,7 +175,7 @@ public function delete($deleteRecursively = true)
* @param string $fileName
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function createFile($fileName)
public function createFile($fileName): never
{
$this->throwInaccessibleException();
}
Expand All @@ -189,7 +186,7 @@ public function createFile($fileName)
* @param string $folderName
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function createFolder($folderName)
public function createFolder($folderName): never
{
$this->throwInaccessibleException();
}
Expand All @@ -202,7 +199,7 @@ public function createFolder($folderName)
* @param string $conflictMode a value of the DuplicationBehavior enumeration
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function copyTo(Folder $targetFolder, $targetFolderName = null, $conflictMode = DuplicationBehavior::RENAME)
public function copyTo(Folder $targetFolder, $targetFolderName = null, $conflictMode = DuplicationBehavior::RENAME): never
{
$this->throwInaccessibleException();
}
Expand All @@ -215,7 +212,7 @@ public function copyTo(Folder $targetFolder, $targetFolderName = null, $conflict
* @param string $conflictMode a value of the DuplicationBehavior enumeration
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function moveTo(Folder $targetFolder, $targetFolderName = null, $conflictMode = DuplicationBehavior::RENAME)
public function moveTo(Folder $targetFolder, $targetFolderName = null, $conflictMode = DuplicationBehavior::RENAME): never
{
$this->throwInaccessibleException();
}
Expand All @@ -226,7 +223,7 @@ public function moveTo(Folder $targetFolder, $targetFolderName = null, $conflict
* @param string $name
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function hasFile($name)
public function hasFile($name): never
{
$this->throwInaccessibleException();
}
Expand All @@ -237,7 +234,7 @@ public function hasFile($name)
* @param string $name
* @throws Exception\InsufficientFolderReadPermissionsException
*/
public function hasFolder($name)
public function hasFolder($name): never
{
$this->throwInaccessibleException();
}
Expand All @@ -250,7 +247,7 @@ public function hasFolder($name)
* @param array $properties
* @internal
*/
public function updateProperties(array $properties)
public function updateProperties(array $properties): never
{
$this->throwInaccessibleException();
}
Expand All @@ -261,7 +258,7 @@ public function updateProperties(array $properties)
*
* @param array $filters
*/
public function setFileAndFolderNameFilters(array $filters)
public function setFileAndFolderNameFilters(array $filters): never
{
$this->throwInaccessibleException();
}
Expand Down

0 comments on commit e06c7d6

Please sign in to comment.