44namespace DivineOmega \SSHConnection ;
55
66
7+ use InvalidArgumentException ;
8+ use RuntimeException ;
9+
710class SSHConnection
811{
912 private $ hostname ;
@@ -49,15 +52,15 @@ public function withKeyPair(string $publicKeyPath, string $privateKeyPath): self
4952 private function sanityCheck ()
5053 {
5154 if (!$ this ->hostname ) {
52- throw new \ InvalidArgumentException ('Hostname not specified. ' );
55+ throw new InvalidArgumentException ('Hostname not specified. ' );
5356 }
5457
5558 if (!$ this ->username ) {
56- throw new \ InvalidArgumentException ('Username not specified. ' );
59+ throw new InvalidArgumentException ('Username not specified. ' );
5760 }
5861
5962 if (!$ this ->password && (!$ this ->publicKeyPath || !$ this ->privateKeyPath )) {
60- throw new \ InvalidArgumentException ('No password or public-private key pair specified. ' );
63+ throw new InvalidArgumentException ('No password or public-private key pair specified. ' );
6164 }
6265 }
6366
@@ -70,14 +73,14 @@ public function connect(): self
7073 if ($ this ->publicKeyPath || $ this ->privateKeyPath ) {
7174 $ authenticated = ssh2_auth_pubkey_file ($ this ->resource , $ this ->username , $ this ->publicKeyPath , $ this ->privateKeyPath );
7275 if (!$ authenticated ) {
73- throw new \ RuntimeException ('Error authenticating with public-private key pair. ' );
76+ throw new RuntimeException ('Error authenticating with public-private key pair. ' );
7477 }
7578 }
7679
7780 if ($ this ->password ) {
7881 $ authenticated = ssh2_auth_password ($ this ->resource , $ this ->username , $ this ->password );
7982 if (!$ authenticated ) {
80- throw new \ RuntimeException ('Error authenticating with password. ' );
83+ throw new RuntimeException ('Error authenticating with password. ' );
8184 }
8285 }
8386
@@ -89,7 +92,7 @@ public function connect(): self
8992 public function disconnect ()
9093 {
9194 if (!$ this ->connected ) {
92- throw new \ RuntimeException ('Unable to disconnect. Not yet connected. ' );
95+ throw new RuntimeException ('Unable to disconnect. Not yet connected. ' );
9396 }
9497
9598 ssh2_disconnect ($ this ->resource );
@@ -102,11 +105,11 @@ public function run($commands)
102105 }
103106
104107 if (!is_array ($ commands )) {
105- throw new \ InvalidArgumentException ('Command(s) passed should be a string or an array of string. ' );
108+ throw new InvalidArgumentException ('Command(s) passed should be a string or an array of string. ' );
106109 }
107110
108111 if (!$ this ->connected ) {
109- throw new \ RuntimeException ('Unable to run commands when not connected. ' );
112+ throw new RuntimeException ('Unable to run commands when not connected. ' );
110113 }
111114
112115 $ results = [];
0 commit comments