Skip to content

Commit 76b7677

Browse files
author
Diego Hernandes
committed
Merge branch 'release/1.0.3'
2 parents a39ac64 + 3c949ea commit 76b7677

File tree

11 files changed

+86
-65
lines changed

11 files changed

+86
-65
lines changed

LICENSE.TXT

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2016 - Diego Hernandes
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

src/Console/Commands/AddCommand.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,21 @@ class AddCommand extends BaseCommand
2525
protected function fire()
2626
{
2727
// Greetings.
28-
$this->info("Registering a new Server Configuration!");
28+
$this->info('Registering a new Server Configuration!');
2929

3030
// Read initial connection data.
31-
$serverData['alias'] = $this->ask("Server connection alias (server1):", "server1");
32-
$serverData['user'] = $this->ask("Server username (none):");
33-
$serverData['host'] = $this->ask("Server hostname or IP Address (192.168.0.1):", "192.168.0.1");
34-
$serverData['port'] = $this->ask("Server Port (22):", 22);
35-
$serverData['authenticationMethod'] = $this->ask("Authentication Method:[system|key|password] (system):", 'system');
31+
$serverData['alias'] = $this->ask('Server connection alias (server1):', 'server1');
32+
$serverData['user'] = $this->ask('Server username (none):');
33+
$serverData['host'] = $this->ask('Server hostname or IP Address (192.168.0.1):', '192.168.0.1');
34+
$serverData['port'] = $this->ask('Server Port (22):', 22);
35+
$serverData['authenticationMethod'] = $this->ask('Authentication Method:[system|key|password] (system):', 'system');
3636

37-
3837
if ($serverData['authenticationMethod'] == 'key') {
3938
// Ask for private key if key was selected as authentication method.
40-
$serverData['privateKey'] = $this->ask("Private Key (~/.ssh/id_rsa):", $_SERVER['HOME'].'/.ssh/id_rsa');
39+
$serverData['privateKey'] = $this->ask('Private Key (~/.ssh/id_rsa):', $_SERVER['HOME'].'/.ssh/id_rsa');
4140
} elseif ($serverData['authenticationMethod'] == 'password') {
4241
// Ask for password if password as selected as authentication method.
43-
$serverData['password'] = $this->ask("Password:");
42+
$serverData['password'] = $this->ask('Password:');
4443
} else {
4544
// don't store anything when system is selected.
4645
}
@@ -50,7 +49,7 @@ protected function fire()
5049

5150
// If the server was indeed created, congratulate the user.
5251
if ($this->manager->serverExists($serverData['alias'])) {
53-
$this->comment("Server registered successfully!");
52+
$this->comment('Server registered successfully!');
5453
}
5554
}
56-
}
55+
}

src/Console/Commands/BaseCommand.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract class BaseCommand extends Command
3131
* @var array Command arguments (if any).
3232
*/
3333
protected $arguments = [];
34-
34+
3535
/**
3636
* @var Manager Servers manager instance.
3737
*/
@@ -55,10 +55,8 @@ abstract class BaseCommand extends Command
5555
/**
5656
* Main Command method, calls the fire command on it's child commands.
5757
*
58-
* @param InputInterface $input Application provided input handler.
58+
* @param InputInterface $input Application provided input handler.
5959
* @param OutputInterface $output Application provided output handler.
60-
*
61-
* @return void
6260
*/
6361
protected function execute(InputInterface $input, OutputInterface $output)
6462
{
@@ -77,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7775
}
7876

7977
/**
80-
* Initialize the command for the console Application
78+
* Initialize the command for the console Application.
8179
*/
8280
protected function configure()
8381
{
@@ -103,7 +101,7 @@ abstract protected function fire();
103101
* Some options are defined by convention, like formatting.
104102
*
105103
* @param string $question The question being asked.
106-
* @param null $default Default value in case the user does not provide an answer.
104+
* @param null $default Default value in case the user does not provide an answer.
107105
*
108106
* @return string The user input or the default value.
109107
*/
@@ -123,12 +121,13 @@ protected function ask($question, $default = null)
123121
* Any other input will return false.
124122
*
125123
* @param string $question The question to be confirmed.
124+
*
126125
* @return bool Confirmed or Not.
127126
*/
128127
protected function askConfirmation($question)
129128
{
130129
// Creates a new confirmation instance using convention formatting.
131-
$confirmQuestion = new ConfirmationQuestion($this->format("$question (Y/n)", 'question'), false) ;
130+
$confirmQuestion = new ConfirmationQuestion($this->format("$question (Y/n)", 'question'), false);
132131

133132
// Do ask the question and return the input.
134133
return $this->questionHelper->ask($this->input, $this->output, $confirmQuestion);
@@ -139,6 +138,7 @@ protected function askConfirmation($question)
139138
*
140139
* @param string $text The string to be formatted.
141140
* @param string $type Desired coloring type.
141+
*
142142
* @return string The formatted string.
143143
*/
144144
protected function format($text, $type = 'info')
@@ -149,7 +149,7 @@ protected function format($text, $type = 'info')
149149
/**
150150
* Write a string into the console output.
151151
*
152-
* @param string $text The string to be displayed.
152+
* @param string $text The string to be displayed.
153153
* @param string $format The coloring format.
154154
*/
155155
protected function writeln($text, $format = 'info')
@@ -213,10 +213,11 @@ protected function error($text)
213213
* Gets the provided value to a given command argument.
214214
*
215215
* @param string $name Argument's name
216+
*
216217
* @return mixed The user provided value.
217218
*/
218219
protected function argument($name)
219220
{
220221
return $this->input->getArgument($name);
221222
}
222-
}
223+
}

src/Console/Commands/ConnectCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ConnectCommand extends BaseCommand
2121
*/
2222
protected $arguments = [
2323
// Connection alias.
24-
['alias', InputArgument::REQUIRED, 'Connection Alias']
24+
['alias', InputArgument::REQUIRED, 'Connection Alias'],
2525
];
2626

2727
/**
@@ -40,4 +40,4 @@ protected function fire()
4040
// for usage while authenticating
4141
$this->writelnPlain($server->connectionString());
4242
}
43-
}
43+
}

src/Console/Commands/DeleteCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DeleteCommand extends BaseCommand
2626
*/
2727
protected $arguments = [
2828
// Connection alias.
29-
['alias', InputArgument::REQUIRED, 'The connection to be removed.']
29+
['alias', InputArgument::REQUIRED, 'The connection to be removed.'],
3030
];
3131

3232
protected function fire()
@@ -37,7 +37,7 @@ protected function fire()
3737
$this->manager->getServer($alias);
3838

3939
// Greetings.
40-
$this->info("Server connection removal.");
40+
$this->info('Server connection removal.');
4141

4242
// Ask for confirmation.
4343
$confirmed = $this->askConfirmation("Are you sure about deleting the connection {$alias}:");
@@ -47,7 +47,7 @@ protected function fire()
4747
// Delete the connection.
4848
$this->manager->deleteServer($alias);
4949
// And congratulate.
50-
$this->info("Server connection deleted successfully!");
50+
$this->info('Server connection deleted successfully!');
5151
}
5252
}
53-
}
53+
}

src/Console/Commands/ServersCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function fire()
3232

3333
// If there is no servers registered.
3434
if (!count($servers)) {
35-
throw new NotFoundException("No servers available.");
35+
throw new NotFoundException('No servers available.');
3636
// Otherwise.
3737
} else {
3838
// Render the servers table.
@@ -55,7 +55,7 @@ protected function serversTable(array $servers)
5555

5656
// Loop on available connections to build the rows.
5757
$rows = [];
58-
foreach($servers as $server) {
58+
foreach ($servers as $server) {
5959
$rows[] = [$server->alias, $server->host, $server->user, $server->port, $server->authenticationMethod];
6060
}
6161

@@ -65,4 +65,4 @@ protected function serversTable(array $servers)
6565
// Render the table.
6666
$table->render();
6767
}
68-
}
68+
}

src/Servers/Exceptions/NotFoundException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
use Symfony\Component\Console\Exception\RuntimeException;
77

88
/**
9-
* Class NotFoundException
9+
* Class NotFoundException.
1010
*
1111
* Exception when a given resource is not found or there are no resources into a
1212
* given collection.
1313
*/
1414
class NotFoundException extends RuntimeException implements ExceptionInterface
1515
{
1616
//
17-
}
17+
}

src/Servers/Manager.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct()
2929
{
3030
// created a new Manager instance.
3131
$this->storageManager = new StorageManager();
32-
32+
3333
// Load servers from storage.
3434
$this->loadServers();
3535
}
@@ -41,9 +41,9 @@ protected function loadServers()
4141
{
4242
// Get the servers configuration array from the servers.yml file.
4343
$servers = $this->storageManager->getConfiguration('servers');
44-
44+
4545
// Register each server configuration as a Server instance.
46-
foreach($servers as $serverData) {
46+
foreach ($servers as $serverData) {
4747
$this->registerServer($serverData);
4848
}
4949
}
@@ -57,7 +57,7 @@ public function registerServer(array $data)
5757
{
5858
// Generate a new server connection instance.
5959
$server = new Server($data);
60-
60+
6161
// Register the server connection into the servers list.
6262
$this->servers[$server->alias] = $server;
6363
}
@@ -72,7 +72,7 @@ public function createServer(array $data)
7272
{
7373
// Register a new server connection instance.
7474
$this->registerServer($data);
75-
75+
7676
// Write the configuration server with the updated information
7777
$this->writeServers();
7878
}
@@ -86,10 +86,10 @@ public function deleteServer($alias)
8686
{
8787
// Find the server.
8888
$server = $this->getServer($alias);
89-
89+
9090
// Forget the server from the server connection instances list
9191
unset($this->servers[$server->alias]);
92-
92+
9393
// Write the updated configuration file
9494
$this->writeServers();
9595
}
@@ -101,7 +101,7 @@ protected function writeServers()
101101
{
102102
$servers = [];
103103
// Parse all current instances into the array representation.
104-
foreach($this->servers as $server) {
104+
foreach ($this->servers as $server) {
105105
$servers[] = $server->toArray();
106106
}
107107

@@ -113,15 +113,17 @@ protected function writeServers()
113113
* Get a server instance.
114114
*
115115
* @param string $alias Server connection alias.
116+
*
116117
* @return Server The Server connection instance.
118+
*
117119
* @throws NotFoundException When the desired alias is not registered.
118120
*/
119121
public function getServer($alias)
120122
{
121123
if ($this->serverExists($alias)) {
122124
return $this->servers[$alias];
123125
} else {
124-
throw new NotFoundException("Server not found.");
126+
throw new NotFoundException('Server not found.');
125127
}
126128
}
127129

@@ -139,10 +141,11 @@ public function getServers()
139141
* Is a given connection alias registered?
140142
*
141143
* @param string $alias The given server connection instance alias.
144+
*
142145
* @return bool Registered or not.
143146
*/
144147
public function serverExists($alias)
145148
{
146149
return array_key_exists($alias, $this->servers);
147150
}
148-
}
151+
}

src/Servers/Server.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Server
6060
public function __construct(array $config)
6161
{
6262
// For each config key
63-
foreach($config as $key => $value) {
63+
foreach ($config as $key => $value) {
6464
// Set into it's own attribute.
6565
$this->$key = $value;
6666
}
@@ -69,8 +69,8 @@ public function __construct(array $config)
6969
/**
7070
* Magic __set method.
7171
*
72-
* @param string $key Attribute name.
73-
* @param mixed $value Attribute value
72+
* @param string $key Attribute name.
73+
* @param mixed $value Attribute value
7474
*/
7575
public function __set($key, $value)
7676
{
@@ -80,7 +80,9 @@ public function __set($key, $value)
8080

8181
/**
8282
* Magic __get method.
83+
*
8384
* @param string $key desired attribute.
85+
*
8486
* @return mixed
8587
*/
8688
public function __get($key)
@@ -93,7 +95,7 @@ public function __get($key)
9395
*/
9496
protected function portParameter()
9597
{
96-
return $this->port ? "-p{$this->port}" : "";
98+
return $this->port ? "-p{$this->port}" : '';
9799
}
98100

99101
/**
@@ -125,7 +127,7 @@ protected function keyParameter()
125127
return "-i{$this->privateKey}";
126128
}
127129

128-
return "";
130+
return '';
129131
}
130132

131133
/**
@@ -152,7 +154,7 @@ public function toArray()
152154
if ($this->alias) {
153155
$configArray['alias'] = $this->alias;
154156
}
155-
157+
156158
if ($this->host) {
157159
$configArray['host'] = $this->host;
158160
}
@@ -176,7 +178,7 @@ public function toArray()
176178
if ($this->privateKey) {
177179
$configArray['privateKey'] = $this->privateKey;
178180
}
179-
181+
180182
return $configArray;
181183
}
182-
}
184+
}

0 commit comments

Comments
 (0)