Skip to content

Commit

Permalink
More typehinting (#617)
Browse files Browse the repository at this point in the history
* Declare strict_types

* Declare void returns

* Add typehints and update docs

* Fix indentation
  • Loading branch information
deviantintegral authored Jul 19, 2024
1 parent 97dc322 commit c293ed7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
18 changes: 11 additions & 7 deletions src/BinaryInstaller.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Lullabot\Drainpipe;

use Composer\Cache;
Expand Down Expand Up @@ -123,7 +125,7 @@ public static function getSubscribedEvents()
*
* @param Event $event the event to handle
*/
public function onPostInstallCmd(Event $event)
public function onPostInstallCmd(Event $event): void
{
$this->installBinaries($event);
}
Expand All @@ -133,7 +135,7 @@ public function onPostInstallCmd(Event $event)
*
* @param event $event The event to handle
*/
public function onPostUpdateCmd(Event $event)
public function onPostUpdateCmd(Event $event): void
{
$this->installBinaries($event);
}
Expand All @@ -143,7 +145,7 @@ public function onPostUpdateCmd(Event $event)
*
* @param event $event The event to handle
*/
public function installBinaries(Event $event)
public function installBinaries(Event $event): void
{
foreach ($this->binaries as $binary => $info) {
$platform = $this->platform;
Expand Down Expand Up @@ -184,9 +186,11 @@ public function installBinaries(Event $event)
* @param string $url
* The URL to download the binary
* @param string $sha
* The hash to validate
* @param string $hashalgo
* The hashing algorithm to use
*
* @see https://www.php.net/manual/en/function.hash-file.php
* @see https://www.php.net/manual/en/function.hash-file.php
*/
protected function installBinary($binary, $version, $url, $sha, $hashalgo = 'sha256'): void
{
Expand Down Expand Up @@ -258,12 +262,12 @@ protected function installBinary($binary, $version, $url, $sha, $hashalgo = 'sha
* Return if a file needs to be downloaded or not.
*
* @param string $cacheDestination The destination path to the downloaded file.
* @param $hashalgo The hash algorithm used to validate the file.
* @param $hash The hash used to validate the file.
* @param string $hashalgo The hash algorithm used to validate the file.
* @param string $hash The hash used to validate the file.
*
* @return bool True if the file needs to be downloaded again, false otherwise.
*/
private function needsDownload(string $cacheDestination, $hashalgo, $hash): bool {
private function needsDownload(string $cacheDestination, string $hashalgo, string $hash): bool {
return !$this->cache->isEnabled() || !file_exists($cacheDestination) || hash_file($hashalgo, $cacheDestination) !== $hash;
}
}
25 changes: 12 additions & 13 deletions src/ScaffoldInstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,18 @@ private function installGitlabCI(string $scaffoldPath): void {
}

if (file_exists('./.ddev/config.yaml')) {
$fs->ensureDirectoryExists('.gitlab/drainpipe');
$fs->copy("$scaffoldPath/gitlab/DDEV.gitlab-ci.yml", ".gitlab/drainpipe/DDEV.gitlab-ci.yml");
$this->io->write("🪠 [Drainpipe] .gitlab/drainpipe/DDEV.gitlab-ci.yml installed");
}
else {
$fs->ensureDirectoryExists('./.drainpipe/gitlab');
$fs->copy("$scaffoldPath/gitlab/Common.gitlab-ci.yml", ".drainpipe/gitlab/Common.gitlab-ci.yml");
$this->io->write("🪠 [Drainpipe] .drainpipe/gitlab/Common.gitlab-ci.yml installed");
}
foreach ($this->extra['drainpipe']['gitlab'] as $gitlab) {
$file = "gitlab/$gitlab.gitlab-ci.yml";
if (file_exists("$scaffoldPath/$file")) {
$fs->ensureDirectoryExists('./.drainpipe/gitlab');
$fs->ensureDirectoryExists('.gitlab/drainpipe');
$fs->copy("$scaffoldPath/gitlab/DDEV.gitlab-ci.yml", ".gitlab/drainpipe/DDEV.gitlab-ci.yml");
$this->io->write("🪠 [Drainpipe] .gitlab/drainpipe/DDEV.gitlab-ci.yml installed");
}
else {
$fs->ensureDirectoryExists('./.drainpipe/gitlab');
$fs->copy("$scaffoldPath/gitlab/Common.gitlab-ci.yml", ".drainpipe/gitlab/Common.gitlab-ci.yml");
$this->io->write("🪠 [Drainpipe] .drainpipe/gitlab/Common.gitlab-ci.yml installed");
}
foreach ($this->extra['drainpipe']['gitlab'] as $gitlab) {
$file = "gitlab/$gitlab.gitlab-ci.yml";
if (file_exists("$scaffoldPath/$file")) {$fs->ensureDirectoryExists('./.drainpipe/gitlab');
$fs->copy("$scaffoldPath/$file", ".drainpipe/$file");
$this->io->write("🪠 [Drainpipe] .drainpipe/$file installed");
}
Expand Down

0 comments on commit c293ed7

Please sign in to comment.