Skip to content

Commit 2ea7b12

Browse files
committed
feat: save to custom path
1 parent 8847ff8 commit 2ea7b12

File tree

5 files changed

+16
-146
lines changed

5 files changed

+16
-146
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/.idea
22
/.phpunit.cache
33
/build
4+
/list
45
/vendor
56
.DS_Store
67
composer.lock

2024-12-06.json

Lines changed: 0 additions & 135 deletions
This file was deleted.

src/Retrieve.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,28 @@ public function json(?string $tseId = null, bool $pretty = true): string
105105
/**
106106
* @return array<string, string>
107107
*/
108-
public function save(): array
108+
public function save(string $path = '.'): array
109109
{
110110
$files = [];
111111

112-
$filename = date('Y-m-d');
112+
$prefix = date('Y-m-d');
113113

114-
$files['json'] = $this->saveJson($filename);
115-
// $files['xml'] = $this->saveXml($filename);
116-
// $files['csv'] = $this->saveCsv($filename);
114+
$files['json'] = $this->saveJson($path.DIRECTORY_SEPARATOR.$prefix);
117115

118116
return $files;
119117
}
120118

121-
private function saveJson(string $filename): string
119+
private function saveJson(string $path): string
122120
{
123121
$content = $this->json();
124-
$filenameWithExtension = $filename.'.json';
125-
$result = file_put_contents($filenameWithExtension, $content);
122+
$pathWithExtension = $path.'.json';
123+
$result = file_put_contents($pathWithExtension, $content);
126124

127125
if ($result === false) {
128126
return '';
129127
}
130128

131-
$path = realpath($filenameWithExtension);
129+
$path = realpath($pathWithExtension);
132130

133131
if ($path === false) {
134132
return '';

src/RetrieveCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
1616

1717
$retrieve = new Retrieve;
1818
$retrieve->run();
19-
$result = $retrieve->save();
19+
$result = $retrieve->save('list');
2020

2121
if (empty($result) || empty($result[array_key_first($result)])) {
2222
$output->writeln('Failed to retrieve TSE list from BSI');
2323

2424
return Command::FAILURE;
2525
}
2626

27-
$output->writeln('Retrieved listed saved to: '.$result[array_key_first($result)]);
27+
$path = $result[array_key_first($result)];
28+
29+
$output->writeln('Retrieved listed saved to: '.$path);
30+
31+
unlink($path);
2832

2933
return Command::SUCCESS;
3034
}

tests/RetrieveTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
expect($content)
5050
->toBeJson()
5151
->not->toBeEmpty();
52+
53+
unlink($path);
5254
}
5355
});
5456

0 commit comments

Comments
 (0)