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

ENH PHP 8.1 compatibility #20

Merged
merged 1 commit into from
Apr 22, 2022
Merged
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
6 changes: 3 additions & 3 deletions src/RecipeCommandBehaviour.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ protected function findBestConstraint($existingVersion)
}

// Existing version is already a ^1.0.0 or ~1.0.0 constraint
if (preg_match('#^[~^]#', $existingVersion)) {
if (preg_match('#^[~^]#', $existingVersion ?? '')) {
return $existingVersion;
}

// Existing version is already a dev constraint
if (stristr($existingVersion, 'dev') !== false) {
if (stristr($existingVersion ?? '', 'dev') !== false) {
return $existingVersion;
}

// Numeric-only version maps to semver constraint
if (preg_match('#^([\d.]+)$#', $existingVersion)) {
if (preg_match('#^([\d.]+)$#', $existingVersion ?? '')) {
return "^{$existingVersion}";
}

Expand Down
30 changes: 16 additions & 14 deletions src/RecipeInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function installProjectFiles(
$relativePath = $this->installProjectFile($sourceRoot, $destinationRoot, $path, $installedFiles);

// Add file to installed (even if already exists)
if (!in_array($relativePath, $installedFiles)) {
if (!in_array($relativePath, $installedFiles ?? [])) {
$installedFiles[] = $relativePath;
}
}
Expand All @@ -87,15 +87,15 @@ protected function installProjectFiles(
protected function installProjectFile($sourceRoot, $destinationRoot, $sourcePath, $installedFiles)
{
// Relative path
$relativePath = substr($sourcePath, strlen($sourceRoot) + 1); // Name path without leading '/'
$relativePath = substr($sourcePath ?? '', strlen($sourceRoot ?? '') + 1); // Name path without leading '/'

// Get destination path
$relativeDestination = $this->rewriteFilePath($destinationRoot, $relativePath);
$destination = $destinationRoot . DIRECTORY_SEPARATOR . $relativeDestination;

// Check if file exists
if (file_exists($destination)) {
if (file_get_contents($destination) === file_get_contents($sourcePath)) {
if (file_exists($destination ?? '')) {
if (file_get_contents($destination ?? '') === file_get_contents($sourcePath ?? '')) {
$this->io->write(
" - Skipping <info>$relativePath</info> (<comment>existing, but unchanged</comment>)"
);
Expand All @@ -104,15 +104,17 @@ protected function installProjectFile($sourceRoot, $destinationRoot, $sourcePath
" - Skipping <info>$relativePath</info> (<comment>existing and modified in project</comment>)"
);
}
} elseif (in_array($relativePath, $installedFiles) || in_array($relativeDestination, $installedFiles)) {
} elseif (in_array($relativePath, $installedFiles ?? []) ||
in_array($relativeDestination, $installedFiles ?? [])
) {
// Don't re-install previously installed files that have been deleted
$this->io->write(
" - Skipping <info>$relativePath</info> (<comment>previously installed</comment>)"
);
} else {
$this->io->write(" - Copying <info>$relativePath</info>");
$this->filesystem->ensureDirectoryExists(dirname($destination));
copy($sourcePath, $destination);
$this->filesystem->ensureDirectoryExists(dirname($destination ?? ''));
copy($sourcePath ?? '', $destination ?? '');
}
return $relativePath;
}
Expand Down Expand Up @@ -155,10 +157,10 @@ protected function getFileIterator($sourceRoot, $patterns)
*/
protected function globToRegexp($glob)
{
$sourceParts = explode('*', $glob);
$sourceParts = explode('*', $glob ?? '');
$regexParts = array_map(function ($part) {
return preg_quote($part, '#');
}, $sourceParts);
return preg_quote($part ?? '', '#');
}, $sourceParts ?? []);
return implode('(.+)', $regexParts);
}

Expand All @@ -176,11 +178,11 @@ public function installLibrary(PackageInterface $package)
$recipePath = $this->getInstallPath($package);

// Find project path
$projectPath = dirname(realpath(Factory::getComposerFile()));
$projectPath = dirname(realpath(Factory::getComposerFile() ?? '') ?? '');

// Find public path
$candidatePublicPath = $projectPath . DIRECTORY_SEPARATOR . RecipePlugin::PUBLIC_PATH;
$publicPath = is_dir($candidatePublicPath) ? $candidatePublicPath : $projectPath;
$publicPath = is_dir($candidatePublicPath ?? '') ? $candidatePublicPath : $projectPath;

// Copy project files to root
$name = $package->getName();
Expand Down Expand Up @@ -238,8 +240,8 @@ protected function rewriteFilePath($destinationRoot, $relativePath)
'app' => 'mysite',
];
foreach ($rewrites as $from => $to) {
if (stripos($relativePath, $from) === 0) {
return $to . substr($relativePath, strlen($from));
if (stripos($relativePath ?? '', $from ?? '') === 0) {
return $to . substr($relativePath ?? '', strlen($from ?? ''));
}
}
return $relativePath;
Expand Down
2 changes: 0 additions & 2 deletions src/RecipePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ public function getCapabilities()

public function deactivate(Composer $composer, IOInterface $io)
{

}

public function uninstall(Composer $composer, IOInterface $io)
{

}
}