Skip to content

Commit

Permalink
ENH PHP 8.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Apr 4, 2022
1 parent e74f4b8 commit ce845b2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
16 changes: 8 additions & 8 deletions src/Console/VendorExposeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function getAllLibraries()
foreach ($this->getModulePaths() as $modulePath) {
// Filter by non-composer folders
$composerPath = Util::joinPaths($modulePath, 'composer.json');
if (!file_exists($composerPath)) {
if (!file_exists((string) $composerPath)) {
continue;
}

Expand Down Expand Up @@ -113,29 +113,29 @@ protected function getModulePaths()

// Get vendor modules
$search = Util::joinPaths($basePath, 'vendor', '*', '*');
foreach (glob($search, GLOB_ONLYDIR) as $modulePath) {
foreach (glob((string) $search, GLOB_ONLYDIR) as $modulePath) {
if ($this->isPathModule($modulePath)) {
yield $modulePath;
}
}

// Check if public/ folder exists
$publicExists = is_dir(Util::joinPaths($basePath, Library::PUBLIC_PATH));
$publicExists = is_dir((string) Util::joinPaths($basePath, Library::PUBLIC_PATH));
if (!$publicExists) {
return;
}

// Search all base folders / modules
$search = Util::joinPaths($basePath, '*');
foreach (glob($search, GLOB_ONLYDIR) as $modulePath) {
foreach (glob((string) $search, GLOB_ONLYDIR) as $modulePath) {
if ($this->isPathModule($modulePath)) {
yield $modulePath;
}
}

// Check all themes
$search = Util::joinPaths($basePath, 'themes', '*');
foreach (glob($search, GLOB_ONLYDIR) as $themePath) {
foreach (glob((string) $search, GLOB_ONLYDIR) as $themePath) {
yield $themePath;
}
}
Expand All @@ -148,15 +148,15 @@ protected function getModulePaths()
*/
protected function isPathModule($path)
{
return file_exists(Util::joinPaths($path, '_config'))
|| file_exists(Util::joinPaths($path, '_config.php'));
return file_exists((string) Util::joinPaths($path, '_config'))
|| file_exists((string) Util::joinPaths($path, '_config.php'));
}

/**
* @return string
*/
protected function getProjectPath()
{
return dirname(realpath(Factory::getComposerFile()));
return dirname((string) realpath((string) Factory::getComposerFile()));
}
}
22 changes: 11 additions & 11 deletions src/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public function __construct(
$libraryPath,
$name = null
) {
$this->basePath = realpath($basePath);
$this->path = realpath($libraryPath);
$this->basePath = realpath((string) $basePath);
$this->path = realpath((string) $libraryPath);
$this->name = $name;
}

Expand Down Expand Up @@ -146,7 +146,7 @@ public function getPath()
*/
public function getRelativePath()
{
return trim(substr($this->path, strlen($this->basePath)), self::TRIM_CHARS);
return trim(substr((string) $this->path, strlen((string) $this->basePath)), (string) self::TRIM_CHARS);
}

/**
Expand All @@ -161,7 +161,7 @@ public function getPublicPath()
// 4.0 compatibility: If there is no public folder, and this is a vendor path,
// remove the leading `vendor` from the destination
if (!$this->publicPathExists() && $this->installedIntoVendor()) {
$relativePath = substr($relativePath, strlen('vendor/'));
$relativePath = substr((string) $relativePath, strlen('vendor/'));
}

return Util::joinPaths($this->getBasePublicPath(), $relativePath);
Expand All @@ -185,7 +185,7 @@ protected function getJson()
return $this->json;
}
$composer = Util::joinPaths($this->getPath(), 'composer.json');
if (!file_exists($composer)) {
if (!file_exists((string) $composer)) {
return [];
}
$file = new JsonFile($composer);
Expand Down Expand Up @@ -264,13 +264,13 @@ public function getExposedFolders()
*/
protected function validateFolder($exposeFolder)
{
if (strstr($exposeFolder, '.')) {
if (strstr((string) $exposeFolder, '.')) {
return false;
}
if (strpos($exposeFolder, '/') === 0) {
if (strpos((string) $exposeFolder, '/') === 0) {
return false;
}
if (strpos($exposeFolder, '\\') === 0) {
if (strpos((string) $exposeFolder, '\\') === 0) {
return false;
}
return true;
Expand All @@ -283,7 +283,7 @@ protected function validateFolder($exposeFolder)
*/
public function publicPathExists()
{
return is_dir(Util::joinPaths($this->getBasePath(), self::PUBLIC_PATH));
return is_dir((string) Util::joinPaths($this->getBasePath(), self::PUBLIC_PATH));
}

/**
Expand All @@ -293,7 +293,7 @@ public function publicPathExists()
*/
protected function installedIntoVendor()
{
return preg_match('#^vendor[/\\\\]#', $this->getRelativePath());
return preg_match('#^vendor[/\\\\]#', (string) $this->getRelativePath());
}

/**
Expand All @@ -316,7 +316,7 @@ public function getResourcesDir()
: self::DEFAULT_RESOURCES_DIR;


if (preg_match('/^[_\-a-z0-9]+$/i', $resourcesDir)) {
if (preg_match('/^[_\-a-z0-9]+$/i', (string) $resourcesDir)) {
return $resourcesDir;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Methods/CopyMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function exposeDirectory($source, $target)
*/
public function copy($source, $target)
{
if (!is_dir($source)) {
return copy($source, $target);
if (!is_dir((string) $source)) {
return copy((string) $source, (string) $target);
}
$it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
/** @var RecursiveDirectoryIterator $ri */
Expand All @@ -59,7 +59,7 @@ public function copy($source, $target)
if ($file->isDir()) {
$this->filesystem->ensureDirectoryExists($targetPath);
} else {
$result = $result && copy($file->getPathname(), $targetPath);
$result = $result && copy((string) $file->getPathname(), (string) $targetPath);
}
}
return $result;
Expand Down
4 changes: 2 additions & 2 deletions src/Methods/SymlinkMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function __construct(Filesystem $filesystem = null)
public function exposeDirectory($source, $target)
{
// Remove trailing slash
$target = rtrim($target, DIRECTORY_SEPARATOR);
$target = rtrim((string) $target, DIRECTORY_SEPARATOR);

// Remove destination directory to ensure it is clean
$this->filesystem->removeDirectory($target);

// Ensure parent dir exist
$parent = dirname($target);
$parent = dirname((string) $target);
$this->filesystem->ensureDirectoryExists($parent);

// Ensure symlink exists
Expand Down
4 changes: 2 additions & 2 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class Util
public static function joinPaths(...$parts)
{
$combined = null;
$parts = array_filter($parts);
$parts = array_filter($parts ?: []);
array_walk_recursive($parts, function ($part) use (&$combined) {
// Normalise path
$part = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $part);
$part = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $part ?: '');
$combined = $combined
? (rtrim($combined, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $part)
: $part;
Expand Down
10 changes: 5 additions & 5 deletions src/VendorExposeTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ protected function setupResources(IOInterface $io)
$files = new DirectoryIterator(__DIR__.'/../resources');
foreach ($files as $file) {
$targetPath = $resourcesPath . DIRECTORY_SEPARATOR . $file->getFilename();
if ($file->isFile() && !file_exists($targetPath)) {
if ($file->isFile() && !file_exists((string) $targetPath)) {
$name = $file->getFilename();
$io->write("Writing <info>{$name}</info> to resources folder");
copy($file->getPathname(), $targetPath);
copy((string) $file->getPathname(), (string) $targetPath);
}
}
}
Expand Down Expand Up @@ -169,8 +169,8 @@ protected function getMethodKey()
{
// Switch if `resources/.method` contains a file
$methodFilePath = $this->getMethodFilePath();
if (file_exists($methodFilePath) && is_readable($methodFilePath)) {
return trim(file_get_contents($methodFilePath));
if (file_exists((string) $methodFilePath) && is_readable((string) $methodFilePath)) {
return trim((string) file_get_contents((string) $methodFilePath));
}

// Switch based on SS_VENDOR_METHOD arg
Expand All @@ -191,7 +191,7 @@ protected function getMethodKey()
protected function saveMethodKey($key)
{
$methodFilePath = $this->getMethodFilePath();
file_put_contents($methodFilePath, $key);
file_put_contents((string) $methodFilePath, $key);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/VendorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function installRootPackage(Event $event)
*/
protected function getProjectPath()
{
return dirname(realpath(Factory::getComposerFile()));
return dirname((string) realpath((string) Factory::getComposerFile()));
}

/**
Expand All @@ -184,7 +184,7 @@ public function uninstallPackage(PackageEvent $event)

// Check path to remove
$target = $library->getPublicPath();
if (!is_dir($target)) {
if (!is_dir((string) $target)) {
return;
}

Expand All @@ -194,7 +194,7 @@ public function uninstallPackage(PackageEvent $event)
$this->filesystem->removeDirectory($target);

// Cleanup empty vendor dir if this is the last module
$targetParent = dirname($target);
$targetParent = dirname((string) $target);
if ($this->filesystem->isDirEmpty($targetParent)) {
$this->filesystem->removeDirectory($targetParent);
}
Expand Down

0 comments on commit ce845b2

Please sign in to comment.