Skip to content

Commit

Permalink
Apply additional suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed May 25, 2021
1 parent d2adf4f commit 45ad50f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
48 changes: 17 additions & 31 deletions system/Publisher/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class Publisher
private static $discovered = [];

/**
* Directory to use for methods
* that need temporary storage.
* Directory to use for methods that need temporary storage.
* Created on-the-fly as needed.
*
* @var string|null
Expand All @@ -59,8 +58,7 @@ class Publisher
private $files = [];

/**
* Exceptions for specific files
* from the last write operation.
* Exceptions for specific files from the last write operation.
*
* @var array<string,Throwable>
*/
Expand All @@ -81,8 +79,7 @@ class Publisher
protected $destination = FCPATH;

/**
* Discovers and returns all Publishers
* in the specified namespace directory.
* Discovers and returns all Publishers in the specified namespace directory.
*
* @param string $directory
*
Expand Down Expand Up @@ -115,6 +112,7 @@ public static function discover(string $directory = 'Publishers'): array
self::$discovered[$directory][] = new $className();
}
}

sort(self::$discovered[$directory]);

return self::$discovered[$directory];
Expand All @@ -123,8 +121,7 @@ public static function discover(string $directory = 'Publishers'): array
//--------------------------------------------------------------------

/**
* Resolves a full path and verifies
* it is an actual directory.
* Resolves a full path and verifies it is an actual directory.
*
* @param string $directory
*
Expand Down Expand Up @@ -162,11 +159,10 @@ private static function resolveFile(string $file): string
//--------------------------------------------------------------------

/**
* Filters an array of files, removing files not
* part of the given directory (recursive).
* Removes files that are not part of the given directory (recursive).
*
* @param string[] $files
* @param string $directory
* @param string $directory
*
* @return string[]
*/
Expand Down Expand Up @@ -207,15 +203,14 @@ private static function matchFiles(array $files, string $pattern)

//--------------------------------------------------------------------

/**
* Removes a directory and all its files
* and subdirectories.
/*
* Removes a directory and all its files and subdirectories.
*
* @param string $directory
*
* @return void
*/
private static function wipeDirectory(string $directory)
private static function wipeDirectory(string $directory): void
{
if (is_dir($directory))
{
Expand Down Expand Up @@ -267,8 +262,7 @@ private static function safeCopyFile(string $from, string $to, bool $replace): v
}

// Make sure the directory exists
$directory = pathinfo($to, PATHINFO_DIRNAME);
if (! is_dir($directory))
if (! is_dir($directory = pathinfo($to, PATHINFO_DIRNAME)))
{
mkdir($directory, 0775, true);
}
Expand All @@ -280,8 +274,7 @@ private static function safeCopyFile(string $from, string $to, bool $replace): v
//--------------------------------------------------------------------

/**
* Loads the helper and verifies the
* source and destination directories.
* Loads the helper and verifies the source and destination directories.
*
* @param string|null $source
* @param string|null $destination
Expand Down Expand Up @@ -322,8 +315,7 @@ public function publish(): bool
//--------------------------------------------------------------------

/**
* Returns the temporary workspace,
* creating it if necessary.
* Returns the temporary workspace, creating it if necessary.
*
* @return string
*/
Expand Down Expand Up @@ -532,8 +524,7 @@ public function addPath(string $path, bool $recursive = true)
//--------------------------------------------------------------------

/**
* Downloads and stages files from
* an array of URIs.
* Downloads and stages files from an array of URIs.
*
* @param string[] $uris
*
Expand Down Expand Up @@ -609,15 +600,10 @@ public function retainPattern(string $pattern, string $scope = null)
}

// Start with all files or those in scope
$files = is_null($scope)
? $this->files
: self::filterFiles($this->files, $scope);

// Match the pattern within the scoped files
$matched = self::matchFiles($files, $pattern);
$files = is_null($scope) ? $this->files : self::filterFiles($this->files, $scope);

// ... and remove their inverse
return $this->removeFiles(array_diff($files, $matched));
// Matches the pattern within the scoped files and remove their inverse.
return $this->removeFiles(array_diff($files, self::matchFiles($files, $pattern)));
}

//--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/_support/Publishers/TestPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestPublisher extends Publisher
/**
* Runs the defined Operations.
*/
public function publish()
public function publish(): bool
{
$this->downloadFromUrls($urls)->mergeToDirectory(FCPATH . 'assets');
}
Expand Down

0 comments on commit 45ad50f

Please sign in to comment.