From 492fc32ca3d007f021abbee6af6f96dc76d81774 Mon Sep 17 00:00:00 2001 From: Sarah Mount Date: Tue, 19 Sep 2023 15:25:39 +0100 Subject: [PATCH] Dependency types are not hard-coded literals Previously we hard-coded the list of dependency types wherever we needed to use them. In order to manage language packs within Whippet, we now need to add to the list of dependency types. So, rather than have them scattered over the code, we now have them in one place. Once we have dropped PHP 7.4 support, we should really use an enumeration here. Fixes #70 --- spec/dependencies/dependency_types.spec.php | 9 +++++++++ src/Dependencies/DependencyTypes.php | 16 ++++++++++++++++ src/Dependencies/Describer.php | 3 +-- src/Dependencies/Installer.php | 2 +- src/Dependencies/Updater.php | 6 +++--- src/Dependencies/Validator.php | 2 +- 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 spec/dependencies/dependency_types.spec.php create mode 100644 src/Dependencies/DependencyTypes.php diff --git a/spec/dependencies/dependency_types.spec.php b/spec/dependencies/dependency_types.spec.php new file mode 100644 index 0000000..1aae91d --- /dev/null +++ b/spec/dependencies/dependency_types.spec.php @@ -0,0 +1,9 @@ +toBe(['themes', 'plugins']); + }); + }); +}); diff --git a/src/Dependencies/DependencyTypes.php b/src/Dependencies/DependencyTypes.php new file mode 100644 index 0000000..e3de5af --- /dev/null +++ b/src/Dependencies/DependencyTypes.php @@ -0,0 +1,16 @@ +isErr()) { return $resultLoad; } - $dependencyTypes = ['themes', 'plugins']; $git = new \Dxw\Whippet\Git\Git($this->dir); $results = []; - foreach ($dependencyTypes as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { foreach ($this->lockFile->getDependencies($type) as $dep) { $result = $git::tag_for_commit($dep['src'], $dep['revision']); if ($result->isErr()) { diff --git a/src/Dependencies/Installer.php b/src/Dependencies/Installer.php index f837db2..e76475c 100644 --- a/src/Dependencies/Installer.php +++ b/src/Dependencies/Installer.php @@ -28,7 +28,7 @@ public function installAll() $dependencies = []; - foreach (['themes', 'plugins'] as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { $dependencies[$type] = $this->lockFile->getDependencies($type); } diff --git a/src/Dependencies/Updater.php b/src/Dependencies/Updater.php index 37cba7e..d7977dc 100644 --- a/src/Dependencies/Updater.php +++ b/src/Dependencies/Updater.php @@ -57,7 +57,7 @@ public function updateAll() $allDependencies = []; - foreach (['themes', 'plugins'] as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { $allDependencies[$type] = $this->jsonFile->getDependencies($type); } @@ -133,7 +133,7 @@ private function updateHash() private function createGitIgnore() { - foreach (['themes', 'plugins'] as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { foreach ($this->jsonFile->getDependencies($type) as $dep) { $this->addDependencyToIgnoresArray($type, $dep['name']); } @@ -151,7 +151,7 @@ private function loadGitignore() } // Iterate through locked dependencies and remove from gitignore - foreach (['themes', 'plugins'] as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { foreach ($this->lockFile->getDependencies($type) as $dep) { $line = $this->getGitignoreDependencyLine($type, $dep['name']); $index = array_search($line, $this->ignores); diff --git a/src/Dependencies/Validator.php b/src/Dependencies/Validator.php index 17ab56d..209638e 100644 --- a/src/Dependencies/Validator.php +++ b/src/Dependencies/Validator.php @@ -46,7 +46,7 @@ public function validate(bool $enforceRefs = false) // Check that entries in whippet.json // match entries in whippet.lock - foreach (['themes', 'plugins'] as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { $whippetJsonDependencies = $whippetJson->getDependencies($type); $whippetLockDependencies = $whippetLock->getDependencies($type); if (count($whippetJsonDependencies) !== count($whippetLockDependencies)) {