Skip to content

Commit a9a712d

Browse files
authored
Merge pull request #53 from BoatraceOpenAPI/refactor/rename-class-name
refactor: rename class from ProgramStorage to ProgramSaver
2 parents df9c0d9 + 7978523 commit a9a712d

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

scraper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require __DIR__ . '/vendor/autoload.php';
66

77
use BOA\Programs\ProgramScraper;
8-
use BOA\Programs\ProgramStorage;
8+
use BOA\Programs\ProgramSaver;
99
use BOA\Programs\ScraperAdapter;
1010
use BVP\Scraper\Scraper;
1111
use Carbon\CarbonImmutable as Carbon;
@@ -34,6 +34,6 @@
3434
// 出走表データを JSON ファイルとして保存
3535
// 日付付きの JSON ファイルとして保存(例: docs/{version}/YYYY/YYYYMMDD.json)
3636
// 最新データとして today.json にも保存
37-
$storage = new ProgramStorage();
38-
$storage->save($programs, "docs/{$version}/" . $date->format('Y') . '/' . $date->format('Ymd') . '.json');
39-
$storage->save($programs, "docs/{$version}/today.json");
37+
$saver = new ProgramSaver();
38+
$saver->save($programs, "docs/{$version}/" . $date->format('Y') . '/' . $date->format('Ymd') . '.json');
39+
$saver->save($programs, "docs/{$version}/today.json");
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @author shimomo
1111
*/
12-
final class ProgramStorage
12+
final class ProgramSaver
1313
{
1414
/**
1515
* @psalm-param ScrapedStadiumRaces $programs
@@ -29,7 +29,7 @@ public function save(array $programs, string $path): void
2929
}
3030

3131
$dir = dirname($path);
32-
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
32+
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
3333
throw new \RuntimeException("Failed to create directory: {$dir}");
3434
}
3535

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace BOA\Programs\Tests;
66

7-
use BOA\Programs\ProgramStorage;
7+
use BOA\Programs\ProgramSaver;
88
use PHPUnit\Framework\TestCase;
99

1010
/**
1111
* @author shimomo
1212
*/
13-
final class ProgramStorageTest extends TestCase
13+
final class ProgramSaverTest extends TestCase
1414
{
1515
/**
1616
* @psalm-var non-empty-string
@@ -27,8 +27,10 @@ final class ProgramStorageTest extends TestCase
2727
protected function setUp(): void
2828
{
2929
parent::setUp();
30-
$this->tempDir = sys_get_temp_dir() . '/program_storage_test_' . uniqid();
31-
mkdir($this->tempDir, 0777, true);
30+
$this->tempDir = sys_get_temp_dir() . '/program_saver_test_' . bin2hex(random_bytes(8));
31+
if (!mkdir($this->tempDir, 0755, true) && !is_dir($this->tempDir)) {
32+
$this->fail('Failed to create temp dir: ' . $this->tempDir);
33+
}
3234
}
3335

3436
/**
@@ -59,7 +61,7 @@ protected function tearDown(): void
5961
*/
6062
public function testSave(): void
6163
{
62-
$storage = new ProgramStorage();
64+
$saver = new ProgramSaver();
6365
$path = $this->tempDir . '/programs.json';
6466

6567
$programs = [
@@ -102,7 +104,7 @@ public function testSave(): void
102104
],
103105
];
104106

105-
$storage->save($programs, $path);
107+
$saver->save($programs, $path);
106108

107109
$this->assertFileExists($path);
108110

0 commit comments

Comments
 (0)