Skip to content

Commit a0bd07c

Browse files
committed
Refactor methods to use getDevToolsFile in AbstractCommand and DocsCommand.
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent 1290d35 commit a0bd07c

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/Command/AbstractCommand.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ protected function getConfigFile(string $filename, bool $force = false): string
155155
return Path::makeAbsolute($filename, $rootPackagePath);
156156
}
157157

158+
return $this->getDevToolsFile($filename);
159+
}
160+
161+
/**
162+
* Resolves the absolute path to a file within the fast-forward/dev-tools package.
163+
*
164+
* This method uses Composer's InstalledVersions to determine the installation path of the
165+
* fast-forward/dev-tools package and returns the absolute path to the given filename within it.
166+
* It is used as a fallback when a configuration file is not found in the project root.
167+
*
168+
* @param string $filename The name of the file to resolve within the dev-tools package.
169+
*
170+
* @return string The absolute path to the file inside the dev-tools package.
171+
*/
172+
protected function getDevToolsFile(string $filename): string
173+
{
158174
$devToolsPackagePath = InstalledVersions::getInstallPath('fast-forward/dev-tools');
159175

160176
return Path::makeAbsolute($filename, $devToolsPackagePath);

src/Command/DocsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private function createPhpDocumentorConfig(string $source, string $target, strin
110110
{
111111
$workingDirectory = $this->getCurrentWorkingDirectory();
112112

113-
$templateFile = $this->getConfigFile('resources/phpdocumentor.xml');
113+
$templateFile = parent::getDevToolsFile('resources/phpdocumentor.xml');
114114

115115
$configDirectory = $this->getAbsolutePath('tmp/cache/phpdoc');
116116
$configFile = $configDirectory . '/phpdocumentor.xml';

src/Command/InstallCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private function createGitHubActionWorkflows(): void
131131
{
132132
$finder = Finder::create()
133133
->files()
134-
->in($this->getConfigFile('resources/github-actions'))
134+
->in(parent::getDevToolsFile('resources/github-actions'))
135135
->name('*.yml');
136136

137137
foreach ($finder as $file) {
@@ -156,8 +156,8 @@ private function createGitHubActionWorkflows(): void
156156
*/
157157
private function copyEditorConfig(): void
158158
{
159-
$source = $this->getConfigFile('.editorconfig');
160-
$target = $this->getConfigFile('.editorconfig', true);
159+
$source = parent::getDevToolsFile('.editorconfig');
160+
$target = parent::getConfigFile('.editorconfig', true);
161161

162162
if ($this->filesystem->exists($target)) {
163163
return;
@@ -180,7 +180,7 @@ private function addRepositoryWikiGitSubmodule(): void
180180
$repositoryUrl = $this->getGitRepositoryUrl();
181181

182182
$wikiRepoUrl = str_replace('.git', '.wiki.git', $repositoryUrl);
183-
$wikiSubmodulePath = $this->getConfigFile('.github/wiki', true);
183+
$wikiSubmodulePath = parent::getConfigFile('.github/wiki', true);
184184

185185
if ($this->filesystem->exists($wikiSubmodulePath)) {
186186
return;

0 commit comments

Comments
 (0)