diff --git a/src/Archive.php b/src/Archive.php index d454634..6ce8cae 100755 --- a/src/Archive.php +++ b/src/Archive.php @@ -100,7 +100,7 @@ public function getFoundUnexpectedArtifacts(): array /** * Has repository a HEAD. * - * @throws \Stolt\LeanPackage\Exceptions\GitNotAvailable + * @throws GitNotAvailable * * @return boolean */ @@ -115,46 +115,45 @@ public function hasHead(): bool } /** - * Is the Git command available? - * - * @param string $command The command to check availabilty of. Defaults to git. + * Create a Git archive from the current HEAD. * + * @throws GitHeadNotAvailable|GitNotAvailable * @return boolean */ - public function isGitCommandAvailable($command = 'git'): bool + public function createArchive(): bool { - \exec('where ' . $command . ' 2>&1', $output, $returnValue); - if ((new OsHelper())->isWindows() === false) { - \exec('which ' . $command . ' 2>&1', $output, $returnValue); + if ($this->hasHead()) { + $command = 'git archive -o ' . $this->getFilename() . ' HEAD 2>&1'; + \exec($command, $output, $returnValue); + + return $returnValue === 0; } - return $returnValue === 0; + throw new GitHeadNotAvailable('No Git HEAD present to create an archive from.'); } /** - * Create a Git archive from the current HEAD. + * Is the Git command available? * - * @throws \Stolt\LeanPackage\Exceptions\GitHeadNotAvailable + * @param string $command The command to check availabilty of. Defaults to git. * * @return boolean */ - public function createArchive(): bool + public function isGitCommandAvailable($command = 'git'): bool { - if ($this->hasHead()) { - $command = 'git archive -o ' . $this->getFilename() . ' HEAD 2>&1'; - \exec($command, $output, $returnValue); - - return $returnValue === 0; + \exec('where ' . $command . ' 2>&1', $output, $returnValue); + if ((new OsHelper())->isWindows() === false) { + \exec('which ' . $command . ' 2>&1', $output, $returnValue); } - throw new GitHeadNotAvailable('No Git HEAD present to create an archive from.'); + return $returnValue === 0; } /** * Compare archive against unexpected artifacts. * * @param array $unexpectedArtifacts The unexpected artifacts. - * @throws \Stolt\LeanPackage\Exceptions\NoLicenseFilePresent + * @throws NoLicenseFilePresent * @return array */ public function compareArchive(array $unexpectedArtifacts): array @@ -195,29 +194,12 @@ public function compareArchive(array $unexpectedArtifacts): array return $foundUnexpectedArtifacts; } - /** - * Remove temporary Git archive. - * - * @return boolean - */ - public function removeArchive(): bool - { - if (\file_exists($this->getFilename())) { - return \unlink($this->getFilename()); - } - - return false; - } - /** * Delegator for temporary archive creation and comparison against * a set of unexpected artifacts. * * @param array $unexpectedArtifacts The unexpected artifacts of the archive. - * - * @throws \Stolt\LeanPackage\Exceptions\GitNotAvailable - * @throws \Stolt\LeanPackage\Exceptions\GitHeadNotAvailable - * + * @throws GitHeadNotAvailable|NoLicenseFilePresent|GitNotAvailable * @return array */ public function getUnexpectedArchiveArtifacts(array $unexpectedArtifacts): array @@ -228,4 +210,18 @@ public function getUnexpectedArchiveArtifacts(array $unexpectedArtifacts): array return $this->foundUnexpectedArtifacts; } + + /** + * Remove temporary Git archive. + * + * @return boolean + */ + public function removeArchive(): bool + { + if (\file_exists($this->getFilename())) { + return \unlink($this->getFilename()); + } + + return false; + } } diff --git a/src/Archive/Validator.php b/src/Archive/Validator.php index 2cdf11b..cc56976 100755 --- a/src/Archive/Validator.php +++ b/src/Archive/Validator.php @@ -4,11 +4,14 @@ use Stolt\LeanPackage\Archive; use Stolt\LeanPackage\Exceptions\GitArchiveNotValidatedYet; +use Stolt\LeanPackage\Exceptions\GitHeadNotAvailable; +use Stolt\LeanPackage\Exceptions\GitNotAvailable; +use Stolt\LeanPackage\Exceptions\NoLicenseFilePresent; class Validator { /** - * @var \Stolt\LeanPackage\Archive + * @var Archive */ private Archive $archive; @@ -20,7 +23,7 @@ class Validator /** * Initialise. * - * @param \Stolt\LeanPackage\Archive $archive The archive to validate. + * @param Archive $archive The archive to validate. */ public function __construct(Archive $archive) { @@ -30,7 +33,7 @@ public function __construct(Archive $archive) /** * Set if license file presence should be validated. * - * @return \Stolt\LeanPackage\Archive\Validator + * @return Validator */ public function shouldHaveLicenseFile(): Validator { @@ -42,7 +45,7 @@ public function shouldHaveLicenseFile(): Validator /** * Accessor for injected archive instance. * - * @return \Stolt\LeanPackage\Archive + * @return Archive */ public function getArchive(): Archive { @@ -54,10 +57,10 @@ public function getArchive(): Archive * * @param array $unexpectedArtifacts Artifacts not expected in archive. * - * @throws \Stolt\LeanPackage\Exceptions\GitHeadNotAvailable - * @throws \Stolt\LeanPackage\Exceptions\GitNotAvailable - * @throws \Stolt\LeanPackage\Exceptions\GitHeadNotAvailable - * @throws \Stolt\LeanPackage\Exceptions\GitNotAvailable + * @throws GitNotAvailable + * @throws GitHeadNotAvailable + * @throws GitNotAvailable|NoLicenseFilePresent + * @throws GitHeadNotAvailable * @return boolean */ public function validate(array $unexpectedArtifacts): bool @@ -77,7 +80,7 @@ public function validate(array $unexpectedArtifacts): bool /** * Accessor for found unexpected archive artifacts. * - * @throws \Stolt\LeanPackage\Exceptions\GitArchiveNotValidatedYet + * @throws GitArchiveNotValidatedYet * * @return array */