Skip to content

Commit a7390f6

Browse files
committed
feat: change dirname e basename method names
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent 7994ab1 commit a7390f6

12 files changed

Lines changed: 35 additions & 32 deletions

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"require": {
4242
"php": "^8.3",
4343
"composer-plugin-api": "^2.0",
44-
"composer/composer": "^2.9",
4544
"container-interop/service-provider": "^0.4.1",
4645
"dg/bypass-finals": "^1.9",
4746
"ergebnis/agent-detector": "^1.1",
@@ -82,6 +81,9 @@
8281
"thecodingmachine/safe": "^3.4",
8382
"twig/twig": "^3.24"
8483
},
84+
"require-dev": {
85+
"composer/composer": "^2.9"
86+
},
8587
"minimum-stability": "stable",
8688
"autoload": {
8789
"psr-4": {

src/Filesystem/Filesystem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function makePathRelative(string $path, ?string $basePath = null): string
197197
*
198198
* @return string the base name of the given path
199199
*/
200-
public function basename(string $path, string $suffix = ''): string
200+
public function getBasename(string $path, string $suffix = ''): string
201201
{
202202
return basename($path, $suffix);
203203
}
@@ -210,7 +210,7 @@ public function basename(string $path, string $suffix = ''): string
210210
*
211211
* @return string the parent path name
212212
*/
213-
public function dirname(string $path, int $levels = 1): string
213+
public function getDirectory(string $path, int $levels = 1): string
214214
{
215215
return \dirname($path, $levels);
216216
}

src/Filesystem/FilesystemInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function makePathRelative(string $path, ?string $basePath = null): string
140140
*
141141
* @return string the base name of the given path
142142
*/
143-
public function basename(string $path, string $suffix = ''): string;
143+
public function getBasename(string $path, string $suffix = ''): string;
144144

145145
/**
146146
* Returns a parent directory's path.
@@ -150,5 +150,5 @@ public function basename(string $path, string $suffix = ''): string;
150150
*
151151
* @return string the parent path name
152152
*/
153-
public function dirname(string $path, int $levels = 1): string;
153+
public function getDirectory(string $path, int $levels = 1): string;
154154
}

src/Process/ColorPreservingProcessEnvironmentConfigurator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private function shouldForceColor(OutputInterface $output): bool
8181
if ($this->outputCapabilityDetector->supportsAnsi($output)) {
8282
return true;
8383
}
84+
8485
if ($this->isTruthyEnvironmentFlag('FORCE_COLOR')) {
8586
return true;
8687
}

src/Sync/PackagedDirectorySynchronizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* Synchronizes one packaged directory of symlinked entries into a consumer repository.
2929
*/
30-
final class PackagedDirectorySynchronizer
30+
final readonly class PackagedDirectorySynchronizer
3131
{
3232
/**
3333
* Initializes the synchronizer with a filesystem and finder factory.
@@ -37,8 +37,8 @@ final class PackagedDirectorySynchronizer
3737
* @param LoggerInterface $logger Logger for recording synchronization actions and decisions
3838
*/
3939
public function __construct(
40-
private readonly FilesystemInterface $filesystem,
41-
private readonly FinderFactoryInterface $finderFactory,
40+
private FilesystemInterface $filesystem,
41+
private FinderFactoryInterface $finderFactory,
4242
private LoggerInterface $logger,
4343
) {}
4444

@@ -132,7 +132,7 @@ private function createNewLink(
132132
SynchronizeResult $result,
133133
): void {
134134
$relativeSourcePath = $this->normalizeRelativeSourcePath(
135-
$this->filesystem->makePathRelative($sourcePath, $this->filesystem->dirname($targetLink)),
135+
$this->filesystem->makePathRelative($sourcePath, $this->filesystem->getDirectory($targetLink)),
136136
$isDirectory,
137137
);
138138

tests/Changelog/Checker/UnreleasedEntryCheckerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function setUp(): void
7171
$this->gitClient = $this->prophesize(GitClientInterface::class);
7272
$this->filesystem = $this->prophesize(FilesystemInterface::class);
7373
$this->parser = $this->prophesize(ChangelogParserInterface::class);
74-
$this->filesystem->dirname(self::FILE)
74+
$this->filesystem->getDirectory(self::FILE)
7575
->willReturn(self::WORKING_DIRECTORY);
7676
$this->checker = new UnreleasedEntryChecker(
7777
$this->filesystem->reveal(),

tests/Changelog/Manager/ChangelogManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function setUp(): void
8585
$this->renderer->reveal(),
8686
$this->gitClient->reveal(),
8787
);
88-
$this->filesystem->dirname(self::FILE)
88+
$this->filesystem->getDirectory(self::FILE)
8989
->willReturn(self::WORKING_DIRECTORY);
9090
}
9191

tests/Console/Command/CodeOwnersCommandTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function executeWillWriteGeneratedCodeOwnersWhenFileIsMissing(): void
155155

156156
$this->filesystem->getAbsolutePath('.github/CODEOWNERS')
157157
->willReturn($targetPath);
158-
$this->filesystem->dirname($targetPath)
158+
$this->filesystem->getDirectory($targetPath)
159159
->willReturn($targetDirectory);
160160
$this->filesystem->exists($targetPath)
161161
->willReturn(false, false);
@@ -193,7 +193,7 @@ public function executeWillSkipExistingCodeOwnersByDefault(): void
193193

194194
$this->filesystem->getAbsolutePath('.github/CODEOWNERS')
195195
->willReturn($targetPath);
196-
$this->filesystem->dirname($targetPath)
196+
$this->filesystem->getDirectory($targetPath)
197197
->willReturn('/project/.github');
198198
$this->filesystem->exists($targetPath)
199199
->willReturn(true);
@@ -227,7 +227,7 @@ public function executeWillFailCheckModeWhenDriftIsDetected(): void
227227
->willReturn(true);
228228
$this->filesystem->getAbsolutePath('.github/CODEOWNERS')
229229
->willReturn($targetPath);
230-
$this->filesystem->dirname($targetPath)
230+
$this->filesystem->getDirectory($targetPath)
231231
->willReturn('/project/.github');
232232
$this->filesystem->exists($targetPath)
233233
->willReturn(true);
@@ -269,7 +269,7 @@ public function executeWillPromptForOwnersWhenInteractiveInferenceFails(): void
269269
->willReturn(true);
270270
$this->filesystem->getAbsolutePath('.github/CODEOWNERS')
271271
->willReturn($targetPath);
272-
$this->filesystem->dirname($targetPath)
272+
$this->filesystem->getDirectory($targetPath)
273273
->willReturn($targetDirectory);
274274
$this->filesystem->exists($targetPath)
275275
->willReturn(false, false);
@@ -318,7 +318,7 @@ public function executeWillReturnSuccessOnDryRunWhenDriftIsDetected(): void
318318
->willReturn(true);
319319
$this->filesystem->getAbsolutePath('.github/CODEOWNERS')
320320
->willReturn($targetPath);
321-
$this->filesystem->dirname($targetPath)
321+
$this->filesystem->getDirectory($targetPath)
322322
->willReturn('/project/.github');
323323
$this->filesystem->exists($targetPath)
324324
->willReturn(true);
@@ -359,7 +359,7 @@ public function executeWillSkipReplacingExistingCodeOwnersWhenConfirmationIsDecl
359359
->willReturn(true);
360360
$this->filesystem->getAbsolutePath('.github/CODEOWNERS')
361361
->willReturn($targetPath);
362-
$this->filesystem->dirname($targetPath)
362+
$this->filesystem->getDirectory($targetPath)
363363
->willReturn('/project/.github');
364364
$this->filesystem->exists($targetPath)
365365
->willReturn(true);

tests/Console/Command/FundingCommandTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ protected function setUp(): void
112112
->willReturn(false);
113113
$this->input->getOption('interactive')
114114
->willReturn(false);
115-
$this->filesystem->dirname('.github/FUNDING.yml')
115+
$this->filesystem->getDirectory('.github/FUNDING.yml')
116116
->willReturn('.github');
117-
$this->filesystem->dirname('composer.json')
117+
$this->filesystem->getDirectory('composer.json')
118118
->willReturn('.');
119-
$this->filesystem->basename('composer.json')
119+
$this->filesystem->getBasename('composer.json')
120120
->willReturn('composer.json');
121121
$this->processBuilder->withArgument(Argument::any())->willReturn($this->processBuilder->reveal());
122122
$this->processBuilder->withArgument(Argument::any(), Argument::any())->willReturn(
@@ -573,9 +573,9 @@ public function executeWillPassWorkingDirectoryAndAlternateManifestToComposerNor
573573
->willReturn(true);
574574
$this->filesystem->readFile('.github/FUNDING.yml')
575575
->willReturn($fundingYaml);
576-
$this->filesystem->dirname($composerFile)
576+
$this->filesystem->getDirectory($composerFile)
577577
->willReturn('build/custom');
578-
$this->filesystem->basename($composerFile)
578+
$this->filesystem->getBasename($composerFile)
579579
->willReturn('composer.alt.json');
580580
$this->processBuilder->withArgument('--working-dir', 'build/custom')
581581
->willReturn($this->processBuilder->reveal())
@@ -676,9 +676,9 @@ public function privateHelpersWillPromptAndNormalizeComposerFileArguments(): voi
676676
$this->io->askQuestion(Argument::type(ConfirmationQuestion::class))
677677
->willReturn(true)
678678
->shouldBeCalledOnce();
679-
$this->filesystem->dirname('composer.alt.json')
679+
$this->filesystem->getDirectory('composer.alt.json')
680680
->willReturn('.');
681-
$this->filesystem->basename('composer.alt.json')
681+
$this->filesystem->getBasename('composer.alt.json')
682682
->willReturn('composer.alt.json');
683683
$this->processBuilder->withArgument('--file', 'composer.alt.json')
684684
->willReturn($this->processBuilder->reveal())

tests/Console/Command/GitHooksCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public function executeWillReportInstallFailureWhenReplacementStillCannotBeWritt
400400
new IOException('Target file could not be opened for writing.', 0, null, '/app/.git/hooks/post-merge')
401401
)
402402
->shouldBeCalledOnce();
403-
$this->filesystem->basename('/app/.git/hooks/post-merge')
403+
$this->filesystem->getBasename('/app/.git/hooks/post-merge')
404404
->willReturn('post-merge')
405405
->shouldBeCalledOnce();
406406
$this->logger->error(

0 commit comments

Comments
 (0)