Skip to content

Commit

Permalink
extract cache-file-not-found-or-stale (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
inmanturbo authored Mar 12, 2024
1 parent 34f2350 commit 516607e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Sushi.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,7 @@ public static function bootSushi()
static::setSqliteConnection($cachePath);
},
'cache-file-not-found-or-stale' => function () use ($cachePath, $dataPath, $instance) {
file_put_contents($cachePath, '');

static::setSqliteConnection($cachePath);

$instance->migrate();

touch($cachePath, filemtime($dataPath));
static::cacheFileNotFoundOrStale($cachePath, $dataPath, $instance);
},
'no-caching-capabilities' => function () use ($instance) {
static::setSqliteConnection(':memory:');
Expand Down Expand Up @@ -101,6 +95,17 @@ public static function bootSushi()
}
}

protected static function cacheFileNotFoundOrStale($cachePath, $dataPath, $instance)
{
file_put_contents($cachePath, '');

static::setSqliteConnection($cachePath);

$instance->migrate();

touch($cachePath, filemtime($dataPath));
}

protected function newRelatedInstance($class)
{
return tap(new $class, function ($instance) {
Expand Down

0 comments on commit 516607e

Please sign in to comment.