From e622a8fc94b59459142a19dd61185d73148537ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=A4rtl?= Date: Thu, 16 Feb 2017 12:47:20 +0100 Subject: [PATCH] Issue #2 Check fp only when necessary --- src/Target.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Target.php b/src/Target.php index 179bd4c..fe4447b 100644 --- a/src/Target.php +++ b/src/Target.php @@ -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."); } }