Merge pull request #102 from creative-commoners/pulls/4/php81

ENH PHP 8.1 compatibility
This commit is contained in:
Guy Sartorelli 2022-04-26 17:58:16 +12:00 committed by GitHub
commit 622864dc3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 34 deletions

View File

@ -305,7 +305,7 @@ class BasicFieldsTestPage extends TestPage
->setRightTitle($rightTitle)
->addExtraClass('my-extra-class');
if (in_array($field->getName(), $blacklist)) {
if (in_array($field->getName(), $blacklist ?? [])) {
continue;
}

View File

@ -111,10 +111,10 @@ class Employee extends DataObject
srand(5);
$companyIDs = Company::get()->column();
$companyCount = sizeof($companyIDs);
$companyCount = sizeof($companyIDs ?? []);
$words = $this->words();
$wordCount = sizeof($words);
$wordCount = sizeof($words ?? []);
$categories = ['marketing', 'management', 'rnd', 'hr'];
foreach ($this->data() as $employeeName) {

View File

@ -78,7 +78,7 @@ class TestMultiFormStepThree extends MultiFormStep
$fields->push(new LiteralField("Heading", "<h3>You have submitted the following information:</h3>"));
foreach ($savedData as $key=>$value) {
if (preg_match("/_copy$/", $key)) {
if (preg_match("/_copy$/", $key ?? '')) {
continue;
}

View File

@ -223,20 +223,20 @@ class FTFileMakerTask extends BuildTask
$fileCounts = $request->getVar('fileCounts');
if ($fileCounts) {
$counts = explode(',', $fileCounts);
$counts = explode(',', $fileCounts ?? '');
$this->fileCounts = array_map(function ($int) {
return (int) trim($int);
}, $counts);
return (int) trim($int ?? '');
}, $counts ?? []);
} else {
$this->fileCounts = self::config()->get('fileCountByDepth');
}
$folderCounts = $request->getVar('folderCounts');
if ($folderCounts) {
$counts = explode(',', $folderCounts);
$counts = explode(',', $folderCounts ?? '');
$this->folderCounts = array_map(function ($int) {
return (int) trim($int);
}, $counts);
return (int) trim($int ?? '');
}, $counts ?? []);
} else {
$this->folderCounts = self::config()->get('folderCountByDepth');
}
@ -277,8 +277,8 @@ class FTFileMakerTask extends BuildTask
$fixtureFileNames = $this->fixtureFileNames;
if (self::config()->get('documentsOnly')) {
$fixtureFileNames = array_filter($fixtureFileNames, function($v) {
return (bool) preg_match('%\.(docx|xlsx|pdf)$%', $v);
$fixtureFileNames = array_filter($fixtureFileNames ?? [], function($v) {
return (bool) preg_match('%\.(docx|xlsx|pdf)$%', $v ?? '');
});
}
@ -289,7 +289,7 @@ class FTFileMakerTask extends BuildTask
$path = TEMP_FOLDER . '/' . $filename;
$paths[$filename] = $path;
$url = "{$this->fixtureFileBaseUrl}/{$filename}";
if (!file_exists($path)) {
if (!file_exists($path ?? '')) {
$promises[$filename] = $client->getAsync($filename, [
'sink' => $path
]);
@ -373,20 +373,20 @@ class FTFileMakerTask extends BuildTask
$randomFileName = array_keys($fixtureFilePaths)[rand(0, count($fixtureFilePaths) - 1)];
$randomFilePath = $fixtureFilePaths[$randomFileName];
$fileName = pathinfo($randomFilePath, PATHINFO_FILENAME)
$fileName = pathinfo($randomFilePath ?? '', PATHINFO_FILENAME)
. "-{$prefix}-{$j}"
. "."
. pathinfo($randomFilePath, PATHINFO_EXTENSION);
. pathinfo($randomFilePath ?? '', PATHINFO_EXTENSION);
// Add a random prefix to avoid all types of files showing up on a single screen page
$fileName = substr(md5($fileName), 0, 5) . '-' . $fileName;
$fileName = substr(md5($fileName ?? ''), 0, 5) . '-' . $fileName;
$class = $this->fixtureFileTypes[$randomFileName];
// If we're uniquifying images, copy the path and watermark it.
if ($class === Image::class && $uniqueImages) {
$copyPath = Path::join(dirname($randomFilePath), $fileName);
copy($randomFilePath, $copyPath);
$copyPath = Path::join(dirname($randomFilePath ?? ''), $fileName);
copy($randomFilePath ?? '', $copyPath ?? '');
$newPath = $this->watermarkImage($absWatermarkPath, $copyPath);
if ($newPath) {
$randomFilePath = $newPath;
@ -457,7 +457,7 @@ class FTFileMakerTask extends BuildTask
protected function watermarkImage(string $stampPath, string $targetPath): ?string
{
// Load the stamp and the photo to apply the watermark to
$ext = strtolower(pathinfo($targetPath, PATHINFO_EXTENSION));
$ext = strtolower(pathinfo($targetPath ?? '', PATHINFO_EXTENSION) ?? '');
$functions = null;
if (in_array($ext, ['jpeg', 'jpg'])) {
$functions = ['imagecreatefromjpeg', 'imagejpeg'];
@ -468,7 +468,7 @@ class FTFileMakerTask extends BuildTask
return null;
}
$stamp = imagecreatefrompng($stampPath);
$stamp = imagecreatefrompng($stampPath ?? '');
$targetImage = call_user_func($functions[0], $targetPath);
// Set the margins for the stamp and get the height/width of the stamp image
@ -477,8 +477,8 @@ class FTFileMakerTask extends BuildTask
$stampX = imagesx($stamp);
$stampY = imagesy($stamp);
$marge_right = rand($stampX, $targetX - $stampX);
$marge_bottom = rand($stampY, $targetY - $stampY);
$marge_right = rand($stampX ?? 0, $targetX - $stampX);
$marge_bottom = rand($stampY ?? 0, $targetY - $stampY);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
@ -489,8 +489,8 @@ class FTFileMakerTask extends BuildTask
$targetY - $stampY - $marge_bottom,
0,
0,
$stampX,
$stampY
$stampX ?? 0,
$stampY ?? 0
);
call_user_func($functions[1], $targetImage, $targetPath);

View File

@ -59,10 +59,10 @@ class FTPageMakerTask extends BuildTask
// Allow pageCountByDepth to be passed as comma-separated value, e.g. pageCounts=5,100,1,1
$pageCounts = $request->getVar('pageCounts');
if ($pageCounts) {
$counts = explode(',', $pageCounts);
$counts = explode(',', $pageCounts ?? '');
$this->pageCountByDepth = array_map(function ($int) {
return (int) trim($int);
}, $counts);
return (int) trim($int ?? '');
}, $counts ?? []);
}
$this->generatePages(0, "", 0, $withBlocks);
@ -70,13 +70,13 @@ class FTPageMakerTask extends BuildTask
protected function generatePages($depth = 0, $prefix = "", $parentID = 0, $withBlocks = false)
{
$maxDepth = count($this->pageCountByDepth);
$maxDepth = count($this->pageCountByDepth ?? []);
$pageCount = $this->pageCountByDepth[$depth];
$testPageClasses = ClassInfo::implementorsOf('TestPageInterface');
for ($i=1; $i<=$pageCount; $i++) {
$fullPrefix = $prefix ? "{$prefix}-{$i}" : $i;
$randomIndex = array_rand($testPageClasses);
$randomIndex = array_rand($testPageClasses ?? []);
$pageClass = $testPageClasses[$randomIndex];
$page = new $pageClass();
$page->ParentID = $parentID;
@ -102,14 +102,14 @@ class FTPageMakerTask extends BuildTask
protected function generateBlocksForPage(Page $page)
{
$classes = array_filter($this->config()->get('block_generators'), function ($callable, $class) {
return class_exists($class);
$classes = array_filter($this->config()->get('block_generators') ?? [], function ($callable, $class) {
return class_exists($class ?? '');
}, ARRAY_FILTER_USE_BOTH);
// Generate a random amount of blocks in the preferred range
$range = $this->blockCountRange;
foreach(range($range[0], array_rand(range($range[0], $range[1]))) as $i) {
$class = array_rand($classes);
$class = array_rand($classes ?? []);
$callable = $classes[$class];
$block = call_user_func($callable, $page);

View File

@ -54,8 +54,8 @@ class FTPageTypeCreatorTask extends BuildTask
$className = null;
while (
!$className ||
in_array($className, $pageTypes) ||
class_exists(basename($className, 'php'))
in_array($className, $pageTypes ?? []) ||
class_exists(basename($className ?? '', 'php'))
) {
$className = $this->generateClassName();
}