Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

/vendor
.env
.env.backup
.env.prod
.env.testing
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing .env.prod and .env.backup from .gitignore makes it easier to accidentally commit environment-specific secrets/config files. If the intent is only formatting, consider keeping these entries ignored (or documenting why they should be tracked).

Suggested change
.env.testing
.env.testing
.env.prod
.env.backup

Copilot uses AI. Check for mistakes.
.phpactor.json
.phpunit.result.cache
Expand Down
8 changes: 4 additions & 4 deletions src/app/Console/Commands/AlgoliaImportWorldHeritages.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public function handle(): int

WorldHeritage::query()
->with([
'images' => function ($query) {
'images' => static function ($query): void {
$query->where('is_primary', true)->select(['world_heritage_site_id', 'url']);
},
'countries' => function ($query) {
'countries' => static function ($query): void {
$query->select(['countries.state_party_code', 'countries.name_en', 'countries.name_jp']);
},
])
Expand All @@ -69,12 +69,12 @@ public function handle(): int
'world_heritage_sites.year_inscribed',
'world_heritage_sites.is_endangered',
])
->chunkById($chunk, function ($rows) use ($client, $indexName, $dryRun, &$processed) {
->chunkById($chunk, function ($rows) use ($client, $indexName, $dryRun, &$processed): void {
$objects = [];

foreach ($rows as $row) {
$countries = $row->countries
->filter(fn ($country) => $country->state_party_code !== null)
->filter(static fn ($country) => $country->state_party_code !== null)
->values();

$statePartyCodes = $countries
Expand Down
8 changes: 4 additions & 4 deletions src/app/Console/Commands/DumpUnescoWorldHeritageJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private function resolveCountries(): array
return [];
}
$lines = preg_split('/\R/u', (string) Storage::disk('local')->get($file)) ?: [];
$items = array_map(fn ($v) => trim((string) $v), $lines);
$items = array_map(static fn ($v) => trim((string) $v), $lines);
return array_values(array_filter(array_unique($items)));
}

Expand Down Expand Up @@ -440,9 +440,9 @@ private function slugifyCountry(string $country): string

private function normalizeRow(array $row): array
{
$toBool = fn ($v) => is_bool($v) ? $v : (strtolower(trim((string) $v)) === 'true');
$toFloat = fn ($v) => $v === null || $v === '' ? null : (float) $v;
$toInt = fn ($v) => $v === null || $v === '' ? null : (int) $v;
$toBool = static fn ($v) => is_bool($v) ? $v : (strtolower(trim((string) $v)) === 'true');
$toFloat = static fn ($v) => $v === null || $v === '' ? null : (float) $v;
$toInt = static fn ($v) => $v === null || $v === '' ? null : (int) $v;

$images = [];
if (isset($row['images_urls']) && is_string($row['images_urls'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function handle(): int
$sid = (string) $id;
$url = "{$baseUrl}/{$sid}";

$this->line("[$i/" . (count($targets) - 1) . "] {$url}");
$this->line("[{$i}/" . (count($targets) - 1) . "] {$url}");

$html = $this->fetchHtml($url, $timeout);
if ($html === null) {
Expand Down Expand Up @@ -250,7 +250,7 @@ private function loadExistingRows(string $out): array
return [];
}

return array_values(array_filter($json, fn ($v) => is_array($v)));
return array_values(array_filter($json, static fn ($v) => is_array($v)));
}

private function containsJapanese(string $s): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function handle(): int
$existingIds = WorldHeritage::query()
->whereIn('id', $ids)
->pluck('id')
->map(fn ($id) => (int) $id)
->map(static fn ($id) => (int) $id)
->all();

$existingIdSet = array_fill_keys($existingIds, true);
Expand Down Expand Up @@ -120,7 +120,7 @@ public function handle(): int
try {
$chunkIdList = array_column($upsertRows, 'id');
$cases = implode(' ', array_map(
fn ($row) => "WHEN {$row['id']} THEN ?",
static fn ($row) => "WHEN {$row['id']} THEN ?",
$upsertRows
));
$bindings = array_column($upsertRows, 'name_jp');
Expand Down Expand Up @@ -217,7 +217,7 @@ private function handleMissingIds(array $missing): void
$dir = dirname($fullOut);

if (!is_dir($dir)) {
@mkdir($dir, 0777, true);
@mkdir($dir, 0o777, true);
}

$content = implode(PHP_EOL, $missing) . PHP_EOL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ private function collectJsonFiles(string $fullPath): array
);

foreach ($rii as $file) {
if ($file->isFile() && str_ends_with($file->getFilename(), '.json')) {
$files[] = $file->getPathname();
}
if (!($file->isFile() && str_ends_with($file->getFilename(), '.json'))) { continue; }

$files[] = $file->getPathname();
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The foreach loop was rewritten into a one-line if { continue; } and the $files[] = ... line lost indentation, reducing readability and likely failing formatting checks. Please reformat this block so the assignment is properly indented under the loop.

Suggested change
$files[] = $file->getPathname();
$files[] = $file->getPathname();

Copilot uses AI. Check for mistakes.
}

sort($files);
Expand Down
4 changes: 2 additions & 2 deletions src/app/Console/Commands/SplitWorldHeritageJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function handle(): int
}

$outDir = $this->resolvePathToDir($out);
if (!is_dir($outDir) && (!@mkdir($outDir, 0777, true) && !is_dir($outDir))) {
if (!is_dir($outDir) && (!@mkdir($outDir, 0o777, true) && !is_dir($outDir))) {
$this->error("Failed to create output dir: {$outDir}");
return self::FAILURE;
}
Expand Down Expand Up @@ -756,7 +756,7 @@ private function mergeSiteRowPreferExisting(array $existing, array $incoming): a
}
}

$fill = function (string $key, mixed $value) use (&$existing): void {
$fill = static function (string $key, mixed $value) use (&$existing): void {
if ((!array_key_exists($key, $existing) || $existing[$key] === null || $existing[$key] === '') && ($value !== null && $value !== '')) {
$existing[$key] = $value;
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/Console/Commands/WorldHeritageBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function handle(): int
'--out' => $dumpOut, // e.g. unesco/world-heritage-sites.json
'--pretty' => $pretty ? true : null,
'--dry-run' => (bool) $this->option('dump-dry-run') ? true : null,
], fn ($v) => $v !== null));
], static fn ($v) => $v !== null));
}

// 1) Split raw UNESCO JSON -> normalized JSON files
Expand All @@ -88,7 +88,7 @@ public function handle(): int
'--exceptions-out' => self::NORM_DIR . '/exceptions-missing-iso-codes.json',
'--clean' => true,
'--pretty' => $pretty ? true : null,
], fn ($v) => $v !== null));
], static fn ($v) => $v !== null));

// 2) Import countries (FK parent)
$this->callOrFail('world-heritage:import-countries-split', [
Expand Down Expand Up @@ -137,14 +137,14 @@ public function handle(): int

'--missing-out' => trim((string) $this->option('jp-missing-out')) !== '' ? (string) $this->option('jp-missing-out') : null,
'--missing-limit' => (int) $this->option('jp-missing-limit'),
], fn ($v) => $v !== null));
], static fn ($v) => $v !== null));
}

// 8) Algolia import (optional)
if ((bool) $this->option('algolia')) {
$this->callOrFail('algolia:import-world-heritages', array_filter([
'--truncate' => (bool) $this->option('algolia-truncate') ? true : null,
], fn ($v) => $v !== null));
], static fn ($v) => $v !== null));
}

$this->info('Done: DB rebuilt + UNESCO data imported (dump -> split -> import)');
Expand Down
12 changes: 0 additions & 12 deletions src/app/Enums/Region.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ public function search(
'hitsPerPage' => $perPage,
'filters' => $hasAnyFilter ? implode(' AND ', $filters) : null,
],
fn ($v) => $v !== null,
static fn ($v) => $v !== null,
),
);

$hits = $response['hits'] ?? [];

$ids = array_values(array_filter(array_map(function (array $h) {
$ids = array_values(array_filter(array_map(static function (array $h) {
return isset($h['id'])
? (int) $h['id']
: (isset($h['objectID']) ? (int) $h['objectID'] : null);
Expand Down
4 changes: 1 addition & 3 deletions src/app/Packages/Domains/Infra/CountryResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ private function dictionary(): array
// not to conflict cache even if the environment/connection is different
$key = self::CACHE_KEY.':'.(string) config('database.default');

// Cache::remember:
// - キャッシュがあればそれを返す
// - なければクロージャを実行して値を作り、保存して返す
// Cache::remember() is atomic, so it prevents cache stampede when there are multiple concurrent requests and the cache is expired.
return Cache::store('file')->remember(
$key,
now()->addHours(self::TTL_HOURS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

class ExceptionalStudyRegions
{
/**
* UNESCO site_id based overrides.
*
* @var array<int, StudyRegion>
*/
public const SITE_ID_TO_REGION = [
148 => StudyRegion::ASIA,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function setUp(): void
parent::setUp();
$this->refresh();

$this->app->bind(WorldHeritageSearchPort::class, function () {
$this->app->bind(WorldHeritageSearchPort::class, static function () {
return new class implements WorldHeritageSearchPort {
public function search($query, int $currentPage, int $perPage): HeritageSearchResult {
return new HeritageSearchResult(ids: [], total: 0, currentPage: 1, perPage: $perPage, lastPage: 0);
Expand Down Expand Up @@ -86,8 +86,8 @@ public function test_count_each_region(): void
'name' => 'Simien National Park',
'study_region' => StudyRegion::AFRICA->value,
'category' => 'Natural',
'latitude' => 13.1833333333,
'longitude' => 38.0666666667,
'latitude' => 13.183_333_333_3,
'longitude' => 38.066_666_666_7,
]),
// id:25 Djoudj National Bird Sanctuary (Senegal, AFR)
$this->baseRecord([
Expand All @@ -96,17 +96,17 @@ public function test_count_each_region(): void
'name' => 'Djoudj National Bird Sanctuary',
'study_region' => StudyRegion::AFRICA->value,
'category' => 'Natural',
'latitude' => 16.414602,
'longitude' => -16.237906,
'latitude' => 16.414_602,
'longitude' => -16.237_906,
]),
// id:26 Island of Gorée (Senegal, AFR)
$this->baseRecord([
'id' => 26,
'official_name'=> 'Island of Gorée',
'name' => 'Island of Gorée',
'study_region' => StudyRegion::AFRICA->value,
'latitude' => 14.66722,
'longitude' => -17.40083,
'latitude' => 14.667_22,
'longitude' => -17.400_83,
]),

// Europe × 3
Expand All @@ -116,17 +116,17 @@ public function test_count_each_region(): void
'official_name'=> 'Aachen Cathedral',
'name' => 'Aachen Cathedral',
'study_region' => StudyRegion::EUROPE->value,
'latitude' => 50.7747468537,
'longitude' => 6.083919968,
'latitude' => 50.774_746_853_7,
'longitude' => 6.083_919_968,
]),
// id:29 Historic Centre of Kraków (Poland, EUR)
$this->baseRecord([
'id' => 29,
'official_name'=> 'Historic Centre of Kraków',
'name' => 'Historic Centre of Kraków',
'study_region' => StudyRegion::EUROPE->value,
'latitude' => 50.0613888889,
'longitude' => 19.9372222222,
'latitude' => 50.061_388_888_9,
'longitude' => 19.937_222_222_2,
]),
// id:30 Historic Centre of Warsaw (Poland, EUR)
$this->baseRecord([
Expand All @@ -145,7 +145,7 @@ public function test_count_each_region(): void
'official_name'=> "L'Anse aux Meadows National Historic Site",
'name' => "L'Anse aux Meadows",
'study_region' => StudyRegion::NORTH_AMERICA->value,
'latitude' => 51.5847222222,
'latitude' => 51.584_722_222_2,
'longitude' => -55.55,
]),
// id:27 Mesa Verde National Park (USA, EUR/North America)
Expand All @@ -154,8 +154,8 @@ public function test_count_each_region(): void
'official_name'=> 'Mesa Verde National Park',
'name' => 'Mesa Verde National Park',
'study_region' => StudyRegion::NORTH_AMERICA->value,
'latitude' => 37.26166667,
'longitude' => -108.4855556,
'latitude' => 37.261_666_67,
'longitude' => -108.485_555_6,
]),

// South America × 2
Expand All @@ -166,8 +166,8 @@ public function test_count_each_region(): void
'name' => 'Galápagos Islands',
'study_region' => StudyRegion::SOUTH_AMERICA->value,
'category' => 'Natural',
'latitude' => -0.68986,
'longitude' => -90.501319,
'latitude' => -0.689_86,
'longitude' => -90.501_319,
]),
// id:2 City of Quito (Ecuador, LAC)
$this->baseRecord([
Expand All @@ -176,7 +176,7 @@ public function test_count_each_region(): void
'name' => 'City of Quito',
'study_region' => StudyRegion::SOUTH_AMERICA->value,
'latitude' => -0.22,
'longitude' => -78.5120833333,
'longitude' => -78.512_083_333_3,
]),

// Oceania × 1 (JSONにないため仮データ)
Expand Down Expand Up @@ -206,8 +206,8 @@ public function test_count_each_region(): void
'official_name'=> 'Ancient City of Damascus',
'name' => 'Ancient City of Damascus',
'study_region' => StudyRegion::UNKNOWN->value,
'latitude' => 33.5108333333,
'longitude' => 36.3097222222,
'latitude' => 33.510_833_333_3,
'longitude' => 36.309_722_222_2,
]),
// id:8 Ichkeul National Park (Tunisia, ARB)
$this->baseRecord([
Expand All @@ -216,8 +216,8 @@ public function test_count_each_region(): void
'name' => 'Ichkeul National Park',
'study_region' => StudyRegion::UNKNOWN->value,
'category' => 'Natural',
'latitude' => 37.16361,
'longitude' => 9.67472,
'latitude' => 37.163_61,
'longitude' => 9.674_72,
]),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function setUp(): void
$seeder = new DatabaseSeeder();
$seeder->run();

$this->app->bind(WorldHeritageSearchPort::class, function () {
$this->app->bind(WorldHeritageSearchPort::class, static function () {
return new class implements WorldHeritageSearchPort {
public function search($query, int $currentPage, int $perPage): HeritageSearchResult {
return new HeritageSearchResult(ids: [], total: 0, currentPage: 1, perPage: $perPage, lastPage: 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function setUp(): void
parent::setUp();
$this->refresh();

$this->app->bind(WorldHeritageSearchPort::class, function () {
$this->app->bind(WorldHeritageSearchPort::class, static function () {
return new class implements WorldHeritageSearchPort {
public function search($query, int $currentPage, int $perPage): HeritageSearchResult {
return new HeritageSearchResult(ids: [], total: 0, currentPage: 1, perPage: $perPage, lastPage: 0);
Expand Down Expand Up @@ -66,8 +66,8 @@ private function arrayData(): array
'criteria' => ['ix'],
'state_party' => null,
'year_inscribed' => 2007,
'area_hectares' => 99947.81,
'buffer_zone_hectares' => 296275.8,
'area_hectares' => 99_947.81,
'buffer_zone_hectares' => 296_275.8,
'is_endangered' => false,
'latitude' => 0.0,
'longitude' => 0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function test_searchHeritages_orchestrates_ports_and_returns_pagination_d
->keyBy('id');

$ordered = collect($hitIds)
->map(fn ($id) => $modelsById->get($id))
->map(static fn ($id) => $modelsById->get($id))
->filter();

$readQueryService = Mockery::mock(WorldHeritageReadQueryServiceInterface::class);
Expand All @@ -140,7 +140,7 @@ public function test_searchHeritages_orchestrates_ports_and_returns_pagination_d
$this->assertSame(1, $dto->getLastPage());

$heritageIds = collect($dto->getCollection()->getHeritages())
->map(fn ($h) => $h->getId())
->map(static fn ($h) => $h->getId())
->all();

$this->assertCount(2, $heritageIds);
Expand Down
Loading
Loading