diff --git a/src/Dev/Tasks/FileMigrationHelper.php b/src/Dev/Tasks/FileMigrationHelper.php index c02252c7..2c258962 100644 --- a/src/Dev/Tasks/FileMigrationHelper.php +++ b/src/Dev/Tasks/FileMigrationHelper.php @@ -210,7 +210,7 @@ protected function ss3Migration($base) * If `$initialStrategy` is not suitable for a migration, we return null. * We're overriding the helpers to avoid doing unnecessary checks. * @param FileResolutionStrategy $initialStrategy - * @return int|FileIDHelperResolutionStrategy + * @return int|FileIDHelperResolutionStrategy|null */ private function buildSS3MigrationStrategy(FileResolutionStrategy $initialStrategy) { diff --git a/src/Dev/TestAssetStore.php b/src/Dev/TestAssetStore.php index bdd53667..e464215b 100644 --- a/src/Dev/TestAssetStore.php +++ b/src/Dev/TestAssetStore.php @@ -105,7 +105,7 @@ public static function activate($basedir) /** * Get absolute path to basedir * - * @return string + * @return string|null */ public static function base_path() { diff --git a/src/File.php b/src/File.php index ae411b8c..7f116300 100644 --- a/src/File.php +++ b/src/File.php @@ -609,7 +609,7 @@ public function getStatusTitle() * Possible group values are: "audio", "mov", "zip", "image". * * @param string $ext Extension to check - * @return string + * @return string|false */ public static function get_app_category($ext) { @@ -732,7 +732,7 @@ protected function onBeforeWrite() // and any file extensions removed. $this->setField( 'Title', - str_replace(['-','_'], ' ', preg_replace('/\.[^.]+$/', '', $name)) + str_replace(['-','_'], ' ', preg_replace('/\.[^.]+$/', '', $name) ?: '') ); } @@ -872,7 +872,7 @@ protected function getNameGenerator($filename) /** * Gets the URL of this file * - * @return string + * @return string|null */ public function getAbsoluteURL() { @@ -888,7 +888,7 @@ public function getAbsoluteURL() * * @uses Director::baseURL() * @param bool $grant Ensures that the url for any protected assets is granted for the current user. - * @return string + * @return string|null */ public function getURL($grant = true) { @@ -902,7 +902,7 @@ public function getURL($grant = true) * Get URL, but without resampling. * * @param bool $grant Ensures that the url for any protected assets is granted for the current user. - * @return string + * @return string|null */ public function getSourceURL($grant = true) { @@ -1019,7 +1019,7 @@ public static function get_file_extension($filename) * Given an extension, determine the icon that should be used * * @param string $extension - * @return string Icon filename relative to base url + * @return string|null Icon filename relative to base url */ public static function get_icon_for_extension($extension) { diff --git a/src/FilenameParsing/FileIDHelperResolutionStrategy.php b/src/FilenameParsing/FileIDHelperResolutionStrategy.php index f13a36d5..4e8e33f6 100644 --- a/src/FilenameParsing/FileIDHelperResolutionStrategy.php +++ b/src/FilenameParsing/FileIDHelperResolutionStrategy.php @@ -523,7 +523,7 @@ public function stripVariant($fileID) * * @param ParsedFileID $parsedFileID * @param FileIDHelper $helper - * @return ParsedFileID + * @return ParsedFileID|null */ private function stripVariantFromParsedFileID(ParsedFileID $parsedFileID, FileIDHelper $helper) { diff --git a/src/FilenameParsing/LegacyFileIDHelper.php b/src/FilenameParsing/LegacyFileIDHelper.php index 18380924..7097b1cd 100644 --- a/src/FilenameParsing/LegacyFileIDHelper.php +++ b/src/FilenameParsing/LegacyFileIDHelper.php @@ -133,7 +133,7 @@ public function parseFileID($fileID) return new ParsedFileID( $filename, '', - isset($matches['variant']) ? str_replace('/', '_', $matches['variant']) : '', + isset($matches['variant']) ? str_replace('/', '_', $matches['variant'] ?: '') : '', $fileID ); } diff --git a/src/Folder.php b/src/Folder.php index d8cd036f..bbff876f 100644 --- a/src/Folder.php +++ b/src/Folder.php @@ -238,7 +238,7 @@ public function getURL($grant = true) /** * Folders do not have public URLs * - * @return string + * @return string|null */ public function getAbsoluteURL() { diff --git a/src/ImageManipulation.php b/src/ImageManipulation.php index ab2efc67..1e2254b7 100644 --- a/src/ImageManipulation.php +++ b/src/ImageManipulation.php @@ -1024,7 +1024,7 @@ public function variantParts($variantName) // Regex needs to be case insensitive since allMethodNames() is all lowercased $regex = '#^(?(' . implode('|', $methods) . '))(?(.*))#i'; - preg_match($regex, $variantName, $matches); + preg_match($regex, (string) $variantName, $matches); if (!$matches) { throw new InvalidArgumentException('Invalid variant name: ' . $variantName); diff --git a/src/InterventionBackend.php b/src/InterventionBackend.php index 8a01913b..6b51f416 100644 --- a/src/InterventionBackend.php +++ b/src/InterventionBackend.php @@ -214,7 +214,7 @@ public function loadFromContainer(AssetContainer $assetContainer) * Get the currently assigned image resource, or generates one if not yet assigned. * Note: This method may return null if error * - * @return InterventionImage + * @return InterventionImage|null */ public function getImageResource() { @@ -351,7 +351,7 @@ public function setImageResource($image) * @param string $hash Hash of original file, if storing a variant. * @param string $variant Name of variant, if storing a variant. * @param array $config Write options. {@see AssetStore} - * @return array Tuple associative array (Filename, Hash, Variant) Unless storing a variant, the hash + * @return array|null Tuple associative array (Filename, Hash, Variant) Unless storing a variant, the hash * will be calculated from the given data. * @throws BadMethodCallException If image isn't valid */ diff --git a/src/Shortcodes/FileShortcodeProvider.php b/src/Shortcodes/FileShortcodeProvider.php index 6d20f06c..ffa0587c 100644 --- a/src/Shortcodes/FileShortcodeProvider.php +++ b/src/Shortcodes/FileShortcodeProvider.php @@ -70,7 +70,7 @@ public static function get_shortcodes() * @param string $shortcode Name of shortcode used to register this handler * @param array $extra Extra arguments * - * @return string Result of the handled shortcode + * @return string|null Result of the handled shortcode */ public static function handle_shortcode($arguments, $content, $parser, $shortcode, $extra = []) { @@ -202,7 +202,7 @@ public static function find_shortcode_record($args, &$errorCode = null) * * @param int $errorCode HTTP Error value * - * @return File|SiteTree File or SiteTree object to use for the given error + * @return File|SiteTree|null File or SiteTree object to use for the given error */ protected static function find_error_record($errorCode) { diff --git a/src/Storage/DBFile.php b/src/Storage/DBFile.php index 0f826cad..b1a493e5 100644 --- a/src/Storage/DBFile.php +++ b/src/Storage/DBFile.php @@ -151,7 +151,7 @@ public function getTag() /** * Determine the template to render as on the frontend * - * @return string Name of template + * @return string|null Name of template */ public function getFrontendTemplate() { @@ -173,7 +173,7 @@ public function getFrontendTemplate() /** * Get trailing part of filename * - * @return string + * @return string|null */ public function getBasename() { @@ -186,7 +186,7 @@ public function getBasename() /** * Get file extension * - * @return string + * @return string|null */ public function getExtension() { @@ -318,7 +318,7 @@ public function getSourceURL($grant = true) /** * Get the absolute URL to this resource * - * @return string + * @return string|null */ public function getAbsoluteURL() { diff --git a/src/Storage/DefaultAssetNameGenerator.php b/src/Storage/DefaultAssetNameGenerator.php index f2ebe347..fd70a692 100644 --- a/src/Storage/DefaultAssetNameGenerator.php +++ b/src/Storage/DefaultAssetNameGenerator.php @@ -100,7 +100,7 @@ public function __construct($filename) $this->name = $matches['name']; // Check if number is padded if (strpos($matches['version'], '0') === 0) { - $this->padding = strlen($matches['version']); + $this->padding = strlen((string) $matches['version']); } } else { $this->first = 1; diff --git a/src/Storage/ProtectedFileController.php b/src/Storage/ProtectedFileController.php index d3f0480c..083b3241 100644 --- a/src/Storage/ProtectedFileController.php +++ b/src/Storage/ProtectedFileController.php @@ -75,7 +75,7 @@ public function handleFile(HTTPRequest $request) public function isValidFilename($filename) { // Block hidden files - return !preg_match('#(^|[\\\\/])\\..*#', $filename); + return !preg_match('#(^|[\\\\/])\\..*#', (string) $filename); } /** diff --git a/tests/php/RedirectFileControllerTest.php b/tests/php/RedirectFileControllerTest.php index 14ec74e3..f00e512d 100644 --- a/tests/php/RedirectFileControllerTest.php +++ b/tests/php/RedirectFileControllerTest.php @@ -530,7 +530,7 @@ protected function assertResponse($code, $body, $location, HTTPResponse $respons */ protected function normaliseUrl($path) { - return str_replace('RedirectFileControllerTest/', '', $path); + return str_replace('RedirectFileControllerTest/', '', $path ?: ''); } public function get($url, $session = null, $headers = null, $cookies = null)