move load method to top
[phorkie.git] / src / phorkie / ForkRemote.php
index d2b077be06b7762219141a3ecaadf0ffe90150bf..7f6129d9a524cefe134e116a2ac6ffd4014b2dbf 100644 (file)
@@ -3,6 +3,11 @@ namespace phorkie;
 
 class ForkRemote
 {
+    /**
+     * Contains error message when parse() failed
+     */
+    public $error;
+
     protected $url;
 
     /**
@@ -17,13 +22,18 @@ class ForkRemote
 
     public function __construct($url)
     {
-        $this->url = $url;
+        $this->url = trim($url);
     }
 
     public function parse()
     {
+        if ($this->url == '') {
+            $this->error = 'Empty fork URL';
+            return false;
+        }
+
         $arUrl  = parse_url($this->url);
-        $scheme = $arUrl['scheme'] ?: '';
+        $scheme = isset($arUrl['scheme']) ? $arUrl['scheme'] : '';
 
         if ($scheme == 'https' && isset($arUrl['host'])
             && $arUrl['host'] == 'gist.github.com'
@@ -85,7 +95,12 @@ class ForkRemote
             }
         }
 
-        return $count > 0;
+        if ($count > 0) {
+            return true;
+        }
+
+        $this->error = 'No git:// clone URL found';
+        return false;
     }
 
     /**