Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.

Commit 9b406c6

Browse files
authored
Merge pull request #3 from DALTCORE/analysis-qxW953
Apply fixes from StyleCI
2 parents b310eca + e1d0335 commit 9b406c6

File tree

5 files changed

+66
-65
lines changed

5 files changed

+66
-65
lines changed

src/Console/Commands/Deploy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function handle()
5757
// Write to config
5858
SSH::instance()
5959
->into($this->option('stage'))
60-
->putString(SSH::home($this->option('stage')) . '/ldh.json', json_encode($this->ldh));
60+
->putString(SSH::home($this->option('stage')).'/ldh.json', json_encode($this->ldh));
6161

6262
// Done
6363
SSH::performLanding($this->option('stage'));

src/Console/Commands/Rollback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function handle()
6262
// Write to config
6363
SSH::instance()
6464
->into($this->option('stage'))
65-
->putString(SSH::home($this->option('stage')) . '/ldh.json', json_encode($this->ldh));
65+
->putString(SSH::home($this->option('stage')).'/ldh.json', json_encode($this->ldh));
6666

6767
SSH::performLanding($this->option('stage'));
6868
}

src/Helpers/Deployer.php

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static function freshInit(Connection $connection, $stage)
1414
{
1515
// Init fresh remote repo
1616
$connection->define('init', [
17-
'cd ' . config('laravel-deploy-helper.stages.' . $stage . '.remote.root'),
17+
'cd '.config('laravel-deploy-helper.stages.'.$stage.'.remote.root'),
1818
'mkdir releases',
1919
'mkdir patches',
2020
'mkdir shared',
@@ -35,11 +35,11 @@ public static function doDeploy($stage, $branch, $ldh)
3535
{
3636
// Some stuff that does not change in runtime
3737
$releaseName = time();
38-
$home = config('laravel-deploy-helper.stages.' . $stage . '.remote.root');
39-
$shared = config('laravel-deploy-helper.stages.' . $stage . '.shared');
40-
$commands = config('laravel-deploy-helper.stages.' . $stage . '.commands');
41-
$versions = config('laravel-deploy-helper.stages.' . $stage . '.config.dependencies');
42-
$keep = config('laravel-deploy-helper.stages.' . $stage . '.config.keep');
38+
$home = config('laravel-deploy-helper.stages.'.$stage.'.remote.root');
39+
$shared = config('laravel-deploy-helper.stages.'.$stage.'.shared');
40+
$commands = config('laravel-deploy-helper.stages.'.$stage.'.commands');
41+
$versions = config('laravel-deploy-helper.stages.'.$stage.'.config.dependencies');
42+
$keep = config('laravel-deploy-helper.stages.'.$stage.'.config.keep');
4343

4444
// Check what releases are old and can be removed
4545
ksort($ldh);
@@ -52,67 +52,67 @@ public static function doDeploy($stage, $branch, $ldh)
5252

5353
// Check versions
5454
// Operators: http://php.net/manual/en/function.version-compare.php
55-
verbose('[' . $stage . '] Checking dependencies. Migth take a minute.');
55+
verbose('['.$stage.'] Checking dependencies. Migth take a minute.');
5656
foreach ($versions as $app => $version) {
5757
SSH::checkAppVersion($connection, $app, $version);
5858
}
5959

6060
// Define the deploy
61-
verbose('[' . $stage . '] Creating new release directory and pulling from remote');
61+
verbose('['.$stage.'] Creating new release directory and pulling from remote');
6262
SSH::execute($stage, [
63-
'mkdir ' . $home . '/releases/' . $releaseName,
64-
'cd ' . $home . '/releases/' . $releaseName,
65-
'git clone -b ' . $branch . ' ' . config('laravel-deploy-helper.stages.' . $stage . '.git.http') . ' .',
63+
'mkdir '.$home.'/releases/'.$releaseName,
64+
'cd '.$home.'/releases/'.$releaseName,
65+
'git clone -b '.$branch.' '.config('laravel-deploy-helper.stages.'.$stage.'.git.http').' .',
6666
]);
6767

6868
// Pre-flight for shared stuff
6969
$items['directories'] = [];
7070
foreach ($shared['directories'] as $share) {
71-
verbose('[' . $stage . '] About to share direcroty "' . $home . '/current/' . $share . '"');
72-
$items['directories'][] = '[ -e ' . $home . '/current/' . $share . ' ] && cp -R -p ' . $home . '/current/'
73-
. $share . ' ' . $home . '/shared/' . $share;
74-
$items['directories'][] = '[ -e ' . $home . '/shared/' . $share . ' ] && cp -R -p ' . $home . '/shared/' .
75-
$share . ' ' . $home . '/releases/' . $releaseName;
71+
verbose('['.$stage.'] About to share direcroty "'.$home.'/current/'.$share.'"');
72+
$items['directories'][] = '[ -e '.$home.'/current/'.$share.' ] && cp -R -p '.$home.'/current/'
73+
.$share.' '.$home.'/shared/'.$share;
74+
$items['directories'][] = '[ -e '.$home.'/shared/'.$share.' ] && cp -R -p '.$home.'/shared/'.
75+
$share.' '.$home.'/releases/'.$releaseName;
7676
}
7777
// Pre-flight for shared stuff
7878
$items['files'] = [];
7979
foreach ($shared['files'] as $share) {
80-
verbose('[' . $stage . '] About to share file "' . $home . '/current/' . $share . '"');
81-
$items['files'][] = '[ -e ' . $home . '/current/' . $share . ' ] && cp -p ' . $home . '/current/' . $share
82-
. ' ' . $home . '/shared/' . $share;
83-
$items['files'][] = '[ -e ' . $home . '/shared/' . $share . ' ] && cp -p ' . $home . '/shared/' . $share .
84-
' ' . $home . '/releases/' . $releaseName . '/' . $share;
80+
verbose('['.$stage.'] About to share file "'.$home.'/current/'.$share.'"');
81+
$items['files'][] = '[ -e '.$home.'/current/'.$share.' ] && cp -p '.$home.'/current/'.$share
82+
.' '.$home.'/shared/'.$share;
83+
$items['files'][] = '[ -e '.$home.'/shared/'.$share.' ] && cp -p '.$home.'/shared/'.$share.
84+
' '.$home.'/releases/'.$releaseName.'/'.$share;
8585
}
8686

8787
// Define shared files
88-
verbose('[' . $stage . '] Syncing shared files');
88+
verbose('['.$stage.'] Syncing shared files');
8989
SSH::execute($stage, $items['files']);
9090

9191
// Define shared directories
92-
verbose('[' . $stage . '] Syncing shared directories');
92+
verbose('['.$stage.'] Syncing shared directories');
9393
SSH::execute($stage, $items['directories']);
9494

9595
$items = [];
9696
foreach ($commands as $command) {
97-
$items[] = 'cd ' . $home . '/releases/' . $releaseName . ' && ' . $command;
97+
$items[] = 'cd '.$home.'/releases/'.$releaseName.' && '.$command;
9898
}
9999
// Define commands
100-
verbose('[' . $stage . '] Executing custom commands');
100+
verbose('['.$stage.'] Executing custom commands');
101101
SSH::execute($stage, $items);
102102

103103
// Define post deploy actions
104-
verbose('[' . $stage . '] Linking new release to /current directory and removing temp');
104+
verbose('['.$stage.'] Linking new release to /current directory and removing temp');
105105
SSH::execute($stage, [
106-
'ln -sfn ' . $home . '/releases/' . $releaseName . ' ' . $home . '/current',
107-
'rm -rf ' . $home . '/shared/*',
106+
'ln -sfn '.$home.'/releases/'.$releaseName.' '.$home.'/current',
107+
'rm -rf '.$home.'/shared/*',
108108
]);
109109

110110
// Remove old deploys
111111
$items = [];
112112
foreach ($toRemove as $dir => $val) {
113-
$items[] = 'echo "Removing release ' . $dir . '" && rm -rf ' . $home . '/releases/' . $dir;
113+
$items[] = 'echo "Removing release '.$dir.'" && rm -rf '.$home.'/releases/'.$dir;
114114
}
115-
verbose('[' . $stage . '] Cleaning up old releases');
115+
verbose('['.$stage.'] Cleaning up old releases');
116116
SSH::execute($stage, $items);
117117

118118
$ldh[$releaseName] = true;
@@ -125,15 +125,15 @@ public static function doDeploy($stage, $branch, $ldh)
125125
*/
126126
public static function doRollback(Connection $connection, $stage, $ldh, $dirs)
127127
{
128-
$home = config('laravel-deploy-helper.stages.' . $stage . '.remote.root');
128+
$home = config('laravel-deploy-helper.stages.'.$stage.'.remote.root');
129129

130130
// Define post deploy actions
131131
$connection->define('preformRollback', [
132-
'ln -sfn ' . $home . '/releases/' . $dirs[1] . ' ' . $home . '/current',
133-
'rm -rf ' . $home . '/releases/' . $dirs[0],
132+
'ln -sfn '.$home.'/releases/'.$dirs[1].' '.$home.'/current',
133+
'rm -rf '.$home.'/releases/'.$dirs[0],
134134
]);
135135

136-
verbose("\t" . 'Hold my beer, We\'re rolling back');
136+
verbose("\t".'Hold my beer, We\'re rolling back');
137137
$connection->task('preformRollback');
138138

139139
unset($dirs[0]);
@@ -153,26 +153,26 @@ public static function doRollback(Connection $connection, $stage, $ldh, $dirs)
153153
*/
154154
public static function doPatch($stage, $branch)
155155
{
156-
$home = config('laravel-deploy-helper.stages.' . $stage . '.remote.root');
156+
$home = config('laravel-deploy-helper.stages.'.$stage.'.remote.root');
157157

158158
// setup ssh connection to remote
159159
$connection = SSH::instance()->into($stage);
160160

161161
$connection->define('preformPatch', [
162-
Command::builder('cd', [$home . '/current']),
162+
Command::builder('cd', [$home.'/current']),
163163
Command::builder('ls', ['-haml']),
164164

165165
Command::builder('git', ['config', 'user.email', 'git+LDH@localhost.ext']),
166166
Command::builder('git', ['config', 'user.name', 'LDH']),
167167

168168
Command::builder('git', ['fetch']),
169169
Command::builder('git',
170-
['format-patch', '-1', 'origin/' . $branch, 'FETCH_HEAD', '-o', $home . '/patches']),
171-
'git apply --reject --whitespace=fix ' . $home . '/patches/*',
172-
Command::builder('rm', ['-rf', $home . '/patches'])
170+
['format-patch', '-1', 'origin/'.$branch, 'FETCH_HEAD', '-o', $home.'/patches']),
171+
'git apply --reject --whitespace=fix '.$home.'/patches/*',
172+
Command::builder('rm', ['-rf', $home.'/patches']),
173173
]);
174174

175-
verbose("\t" . 'Hold on tight, trying to patch!');
175+
verbose("\t".'Hold on tight, trying to patch!');
176176
$connection->task('preformPatch');
177177
}
178178
}

src/Helpers/SSH.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function instance()
2222
*/
2323
public static function home($stage)
2424
{
25-
return config('laravel-deploy-helper.stages.' . $stage . '.remote.root');
25+
return config('laravel-deploy-helper.stages.'.$stage.'.remote.root');
2626
}
2727

2828
public static function checkAppVersion(Connection $connection, $app, $requestedVersion)
@@ -68,7 +68,7 @@ public static function checkAppVersion(Connection $connection, $app, $requestedV
6868
if ($requestedVersion === true) {
6969
$connection->run(Command::builder($app, []), function ($response) use ($app) {
7070
if (stripos($response, 'command not found') !== false) {
71-
throw new \Exception('ERROR: ' . $app . ' is not installed on the server.');
71+
throw new \Exception('ERROR: '.$app.' is not installed on the server.');
7272
}
7373
});
7474
verbose("\t => Checking $app is available");
@@ -81,7 +81,7 @@ public static function checkAppVersion(Connection $connection, $app, $requestedV
8181
*/
8282
$connection->run(Command::builder($app, []), function ($response) use ($app) {
8383
if (stripos($response, 'command not found') !== false) {
84-
throw new \Exception('ERROR: ' . $app . ' is not installed on the server.');
84+
throw new \Exception('ERROR: '.$app.' is not installed on the server.');
8585
}
8686
});
8787

@@ -104,14 +104,15 @@ public static function execute($stage, $commands)
104104
}
105105

106106
/**
107-
* Pre flight checks before the deploy happens
107+
* Pre flight checks before the deploy happens.
108108
*
109109
* @param $instance
110110
* @param $stage
111111
* @param $branch
112112
*
113-
* @return bool|mixed
114113
* @throws \Exception
114+
*
115+
* @return bool|mixed
115116
*/
116117
public static function preFlight($instance, $stage, $branch = false)
117118
{
@@ -121,9 +122,9 @@ public static function preFlight($instance, $stage, $branch = false)
121122
if ($stage === null) {
122123
throw new \Exception('The argument "--stage=" is required!', 128);
123124
} else {
124-
if (!is_array(config('laravel-deploy-helper.stages.' . $stage))) {
125-
throw new \Exception('The stage "' . $stage
126-
. '" does not exist!', 128);
125+
if (!is_array(config('laravel-deploy-helper.stages.'.$stage))) {
126+
throw new \Exception('The stage "'.$stage
127+
.'" does not exist!', 128);
127128
}
128129
}
129130

@@ -133,14 +134,14 @@ public static function preFlight($instance, $stage, $branch = false)
133134
}
134135

135136
if (in_array($branch, Git::getBranches()) == false) {
136-
throw new \Exception('The branch "' . $branch
137-
. '" does not exists locally? Please `git pull`!', 128);
137+
throw new \Exception('The branch "'.$branch
138+
.'" does not exists locally? Please `git pull`!', 128);
138139
}
139140
}
140141

141142
// Connecting to remote server
142-
verbose('[' . $stage . '] Trying to login into remote SSH');
143-
$ssh = SSH::instance()->into($stage);
143+
verbose('['.$stage.'] Trying to login into remote SSH');
144+
$ssh = self::instance()->into($stage);
144145

145146
// Check for lockfile
146147
if (Locker::lock($ssh, $stage) === false) {
@@ -149,22 +150,22 @@ public static function preFlight($instance, $stage, $branch = false)
149150
}
150151

151152
// Trying to read file
152-
verbose('[' . $stage . '] Reading config file from remote server');
153-
$config = $ssh->exists(SSH::home($stage) . '/ldh.json');
153+
verbose('['.$stage.'] Reading config file from remote server');
154+
$config = $ssh->exists(self::home($stage).'/ldh.json');
154155

155156
// Check if config exists
156157
if ($config == false) {
157-
error('[' . $stage . '] ldh.json does not exists.');
158+
error('['.$stage.'] ldh.json does not exists.');
158159
if ($instance->confirm('Do you want to initialize LDH here?')) {
159160
Deployer::freshInit($ssh, $stage);
160161
} else {
161162
return false;
162163
}
163164
} else {
164-
verbose('[' . $stage . '] Found config. Checking directories.');
165-
$config = $ssh->getString(SSH::home($stage) . '/ldh.json');
165+
verbose('['.$stage.'] Found config. Checking directories.');
166+
$config = $ssh->getString(self::home($stage).'/ldh.json');
166167
if ($config == false) {
167-
error('[' . $stage . '] Config file is empty... Something is wrong.');
168+
error('['.$stage.'] Config file is empty... Something is wrong.');
168169

169170
return false;
170171
}
@@ -174,14 +175,14 @@ public static function preFlight($instance, $stage, $branch = false)
174175
}
175176

176177
/**
177-
* End of command
178+
* End of command.
178179
*
179180
* @param $stage
180181
*/
181182
public static function performLanding($stage)
182183
{
183-
$ssh = SSH::instance()->into($stage);
184+
$ssh = self::instance()->into($stage);
184185
Locker::unlock($ssh, $stage);
185-
verbose('[' . $stage . '] Changes are successfull!');
186+
verbose('['.$stage.'] Changes are successfull!');
186187
}
187188
}

src/Helpers/helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function verbose($message)
1515
{
1616
$console = new ConsoleOutput();
1717
$console->getFormatter()->setStyle('info', new OutputFormatterStyle('blue', null));
18-
$console->writeln('<info>' . $message . '</info>');
18+
$console->writeln('<info>'.$message.'</info>');
1919
}
2020
}
2121

@@ -31,7 +31,7 @@ function error($message)
3131
{
3232
$console = new ConsoleOutput();
3333
$console->getFormatter()->setStyle('error', new OutputFormatterStyle('white', 'red'));
34-
$console->writeln('<error>' . $message . '</error>');
34+
$console->writeln('<error>'.$message.'</error>');
3535
}
3636
}
3737

0 commit comments

Comments
 (0)