Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT PHP 8.1 #482

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Dev/Tasks/FileMigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/TestAssetStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function activate($basedir)
/**
* Get absolute path to basedir
*
* @return string
* @return string|null
*/
public static function base_path()
{
Expand Down
12 changes: 6 additions & 6 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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) ?: '')
);
}

Expand Down Expand Up @@ -872,7 +872,7 @@ protected function getNameGenerator($filename)
/**
* Gets the URL of this file
*
* @return string
* @return string|null
*/
public function getAbsoluteURL()
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/FilenameParsing/FileIDHelperResolutionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/FilenameParsing/LegacyFileIDHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function getURL($grant = true)
/**
* Folders do not have public URLs
*
* @return string
* @return string|null
*/
public function getAbsoluteURL()
{
Expand Down
2 changes: 1 addition & 1 deletion src/ImageManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ public function variantParts($variantName)

// Regex needs to be case insensitive since allMethodNames() is all lowercased
$regex = '#^(?<format>(' . implode('|', $methods) . '))(?<encodedargs>(.*))#i';
preg_match($regex, $variantName, $matches);
preg_match($regex, (string) $variantName, $matches);

if (!$matches) {
throw new InvalidArgumentException('Invalid variant name: ' . $variantName);
Expand Down
4 changes: 2 additions & 2 deletions src/InterventionBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Shortcodes/FileShortcodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand Down Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Storage/DBFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -173,7 +173,7 @@ public function getFrontendTemplate()
/**
* Get trailing part of filename
*
* @return string
* @return string|null
*/
public function getBasename()
{
Expand All @@ -186,7 +186,7 @@ public function getBasename()
/**
* Get file extension
*
* @return string
* @return string|null
*/
public function getExtension()
{
Expand Down Expand Up @@ -318,7 +318,7 @@ public function getSourceURL($grant = true)
/**
* Get the absolute URL to this resource
*
* @return string
* @return string|null
*/
public function getAbsoluteURL()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/DefaultAssetNameGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/ProtectedFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/php/RedirectFileControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down