Skip to content

Commit

Permalink
Issue #2 Check fp only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehaertl committed Feb 16, 2017
1 parent c813820 commit e622a8f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ public function init() {
}
$this->fp = @fopen($this->url,'w');
if ($this->fp===false) {
throw new InvalidConfigException("Unable to append to '{$this->url}'");
throw new InvalidConfigException("Unable to open '{$this->url}' for writing.");
}
} else {
if (!is_resource($this->fp)) {
throw new InvalidConfigException("Invalid resource.");
}
$metadata = stream_get_meta_data($this->fp);
if ($metadata['mode']!=='w') {
throw new InvalidConfigException("Resource is not writeable.");
}
}
if (!is_resource($this->fp)) {
throw new InvalidConfigException("Invalid resource.");
}
$metadata = stream_get_meta_data($this->fp);
if ($metadata['mode']!=='w') {
throw new InvalidConfigException("Resource is not writeable.");
}
}

Expand Down

0 comments on commit e622a8f

Please sign in to comment.