Skip to content

Commit

Permalink
[improve]getContent/hasContent のリファクタ
Browse files Browse the repository at this point in the history
  • Loading branch information
ngyuki committed May 24, 2018
1 parent 9732967 commit 03ce41b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Migrate/Migrator.php
Expand Up @@ -184,7 +184,7 @@ public function markVersion($version)

if ($status->isApplied()) {
$this->logger->log("version already migrated: $version");
} elseif ($status->hasContent() == false) {
} elseif ($status->isMissing()) {
$this->logger->log("mark version: $version is missing");
} else {
$this->adapter->save($version, $status->getContent());
Expand All @@ -199,8 +199,8 @@ public function markAllVersions()
foreach ($statuses as $version => $status) {
if ($status->isApplied()) {
// skip
} elseif ($status->hasContent() == false) {
$this->logger->log("mark version: $version is missing");
} elseif ($status->isMissing()) {
// skip
} else {
$this->adapter->save($version, $status->getContent());
$this->logger->log("mark version: $version");
Expand Down
10 changes: 8 additions & 2 deletions src/Migrate/Status.php
@@ -1,6 +1,8 @@
<?php
namespace ngyuki\DbMigrate\Migrate;

use Guzzle\Common\Exception\RuntimeException;

class Status
{
/**
Expand Down Expand Up @@ -61,10 +63,14 @@ public function getContent()
{
if ($this->source === null) {
if ($this->script !== null) {
$this->source = file_get_contents($this->script);
$source = file_get_contents($this->script);
if ($source === false) {
throw new RuntimeException("Unable read \"$this->script\"");
}
$this->source = $source;
};
}
if ($this->source !== false && $this->source !== null) {
if ($this->source !== null) {
return $this->source;
} else {
return $this->content;
Expand Down

0 comments on commit 03ce41b

Please sign in to comment.