Skip to content

Commit bc8b89c

Browse files
committed
Refactor for code consistency and modern PHP compatibility
1 parent 21e0951 commit bc8b89c

23 files changed

Lines changed: 96 additions & 121 deletions

contrib/cloudflare.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@
6666
throw new \RuntimeException("Error making curl request (result: $res)");
6767
}
6868

69-
if (PHP_MAJOR_VERSION < 8) {
70-
curl_close($ch);
71-
}
72-
7369
return $res;
7470
};
7571

contrib/cpanel.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ function getCpanel()
158158
}
159159

160160

161-
if (!is_array($config) ||
162-
!isset($config['host']) ||
163-
!isset($config['port']) ||
164-
!isset($config['username']) ||
165-
!isset($config['token']) ||
166-
!isset($config['user'])) {
161+
if (!is_array($config)
162+
|| !isset($config['host'])
163+
|| !isset($config['port'])
164+
|| !isset($config['username'])
165+
|| !isset($config['token'])
166+
|| !isset($config['user'])) {
167167
throw new \RuntimeException("<comment>Please configure CPanel config:</comment> <info>set('cpanel', array('host' => 'xxx.xxx.xxx.xxx:', 'port' => 2087 , 'username' => 'root', 'token' => 'asdfasdf', 'cpaneluser' => 'guy'));</info>");
168168
}
169169

contrib/directadmin.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ function getDirectAdminConfig()
3232
{
3333
$config = get('directadmin', []);
3434

35-
if (!is_array($config) ||
36-
!isset($config['host']) ||
37-
!isset($config['username']) ||
38-
!isset($config['password'])) {
35+
if (!is_array($config)
36+
|| !isset($config['host'])
37+
|| !isset($config['username'])
38+
|| !isset($config['password'])) {
3939
throw new \RuntimeException("Please set the following DirectAdmin config:" . PHP_EOL . "set('directadmin', ['host' => '127.0.0.1', 'port' => 2222, 'username' => 'admin', 'password' => 'password']);");
4040
}
4141

@@ -76,10 +76,9 @@ function DirectAdmin(string $action, array $data = [])
7676
task('directadmin:createdb', function () {
7777
$config = getDirectAdminConfig();
7878

79-
if (!is_array($config) ||
80-
!isset($config['db_name']) ||
81-
!isset($config['db_user']) ||
82-
!isset($config['db_password'])) {
79+
if (!isset($config['db_name'])
80+
|| !isset($config['db_user'])
81+
|| !isset($config['db_password'])) {
8382
throw new \RuntimeException("Please add the following DirectAdmin config:" . PHP_EOL . "add('directadmin', ['db_name' => 'test', 'db_user' => 'test', 'db_password' => '123456']);");
8483
}
8584

@@ -96,8 +95,7 @@ function DirectAdmin(string $action, array $data = [])
9695
task('directadmin:deletedb', function () {
9796
$config = getDirectAdminConfig();
9897

99-
if (!is_array($config) ||
100-
!isset($config['db_user'])) {
98+
if (!isset($config['db_user'])) {
10199
throw new \RuntimeException("Please add the following DirectAdmin config:" . PHP_EOL . "add('directadmin', ['db_user' => 'test_database']);");
102100
}
103101

@@ -111,8 +109,7 @@ function DirectAdmin(string $action, array $data = [])
111109
task('directadmin:createdomain', function () {
112110
$config = getDirectAdminConfig();
113111

114-
if (!is_array($config) ||
115-
!isset($config['domain_name'])) {
112+
if (!isset($config['domain_name'])) {
116113
throw new \RuntimeException("Please add the following DirectAdmin config:" . PHP_EOL . "add('directadmin', ['domain_name' => 'test.example.com']);");
117114
}
118115

@@ -129,8 +126,7 @@ function DirectAdmin(string $action, array $data = [])
129126
task('directadmin:deletedomain', function () {
130127
$config = getDirectAdminConfig();
131128

132-
if (!is_array($config) ||
133-
!isset($config['domain_name'])) {
129+
if (!isset($config['domain_name'])) {
134130
throw new \RuntimeException("Please add the following DirectAdmin config:" . PHP_EOL . "add('directadmin', ['domain_name' => 'test.example.com']);");
135131
}
136132

@@ -145,8 +141,7 @@ function DirectAdmin(string $action, array $data = [])
145141
task('directadmin:symlink-private-html', function () {
146142
$config = getDirectAdminConfig();
147143

148-
if (!is_array($config) ||
149-
!isset($config['domain_name'])) {
144+
if (!isset($config['domain_name'])) {
150145
throw new \RuntimeException("Please add the following DirectAdmin config:" . PHP_EOL . "add('directadmin', ['domain_name' => 'test.example.com']);");
151146
}
152147

@@ -161,9 +156,8 @@ function DirectAdmin(string $action, array $data = [])
161156
task('directadmin:php-version', function () {
162157
$config = getDirectAdminConfig();
163158

164-
if (!is_array($config) ||
165-
!isset($config['domain_name']) ||
166-
!isset($config['domain_php_version'])) {
159+
if (!isset($config['domain_name'])
160+
|| !isset($config['domain_php_version'])) {
167161
throw new \RuntimeException("Please add the following DirectAdmin config:" . PHP_EOL . "add('directadmin', ['domain_name' => 'test.example.com', 'domain_php_version' => 1]);");
168162
}
169163

contrib/grafana.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
];
4646

4747
$config = array_merge($defaultConfig, (array) get('grafana'));
48-
if (!is_array($config) || !isset($config['url']) || !isset($config['token'])) {
48+
if (!isset($config['url']) || !isset($config['token'])) {
4949
throw new \RuntimeException("Please configure Grafana: set('grafana', ['url' => 'https://localhost/api/annotations', token' => 'eyJrIjo...']);");
5050
}
5151

contrib/rabbit.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,12 @@
8989

9090
$config = array_merge($defaultConfig, $config);
9191

92-
if (!is_array($config) ||
93-
!isset($config['channel']) ||
94-
!isset($config['host']) ||
95-
!isset($config['port']) ||
96-
!isset($config['username']) ||
97-
!isset($config['password']) ||
98-
!isset($config['vhost'])) {
92+
if (!isset($config['channel'])
93+
|| !isset($config['host'])
94+
|| !isset($config['port'])
95+
|| !isset($config['username'])
96+
|| !isset($config['password'])
97+
|| !isset($config['vhost'])) {
9998
throw new \RuntimeException("<comment>Please configure rabbit config:</comment> <info>set('rabbit', array('channel' => 'channel', 'host' => 'host', 'port' => 'port', 'username' => 'username', 'password' => 'password'));</info>");
10099
}
101100

contrib/sentry.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ static function (&$value) use ($config) {
144144

145145
writeln(
146146
sprintf(
147-
'<info>Sentry:</info> Release of version <comment>%s</comment> ' .
148-
'for projects: <comment>%s</comment> created successfully.',
147+
'<info>Sentry:</info> Release of version <comment>%s</comment> '
148+
. 'for projects: <comment>%s</comment> created successfully.',
149149
$response['version'],
150150
implode(', ', array_column($response['projects'], 'slug')),
151151
),
@@ -175,8 +175,8 @@ static function (&$value) use ($config) {
175175

176176
writeln(
177177
sprintf(
178-
'<info>Sentry:</info> Deployment <comment>%s</comment> ' .
179-
'for environment <comment>%s</comment> created successfully',
178+
'<info>Sentry:</info> Deployment <comment>%s</comment> '
179+
. 'for environment <comment>%s</comment> created successfully',
180180
$response['id'],
181181
$response['environment'],
182182
),

contrib/supervisord-monitor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ function supervisordCheckConfig()
100100
}
101101
}
102102

103-
if (!get('supervisord_uri') ||
104-
!get('supervisord_basic_auth_user') ||
105-
!get('supervisord_basic_auth_password') ||
106-
!get('supervisord_process_name')) {
103+
if (!get('supervisord_uri')
104+
|| !get('supervisord_basic_auth_user')
105+
|| !get('supervisord_basic_auth_password')
106+
|| !get('supervisord_process_name')) {
107107
throw new \RuntimeException("<comment>Please configure Supervisord config:</comment> <info>set('supervisord', array('uri' => 'yourdomain.xyz/supervisor', 'basic_auth_user' => 'abc' , 'basic_auth_password' => 'xyz', 'process_name' => 'process01,process02'));</info> or <info>set('supervisord_uri', 'yourdomain.xyz/supervisor'); set('supervisord_basic_auth_user', 'abc'); etc</info>");
108108
}
109109
}

recipe/deploy/lock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
if ($locked === '+locked') {
1212
$lockedUser = run("cat {{deploy_path}}/.dep/deploy.lock");
1313
throw new GracefulShutdownException(
14-
"Deploy locked by $lockedUser.\n" .
15-
"Execute \"deploy:unlock\" task to unlock.",
14+
"Deploy locked by $lockedUser.\n"
15+
. "Execute \"deploy:unlock\" task to unlock.",
1616
);
1717
}
1818
});

recipe/deploy/release.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
}
113113

114114
// Save release_name.
115-
if (is_numeric($releaseName) && is_integer(intval($releaseName))) {
115+
if (is_numeric($releaseName)) {
116116
run("echo $releaseName > .dep/latest_release");
117117
}
118118

recipe/deploy/writable.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
if (empty($httpUser)) {
1414
throw new \RuntimeException(
15-
"Can't detect http user name.\n" .
16-
"Please setup `http_user` config parameter.",
15+
"Can't detect http user name.\n"
16+
. "Please setup `http_user` config parameter.",
1717
);
1818
}
1919

@@ -29,8 +29,8 @@
2929

3030
if (empty($httpGroup)) {
3131
throw new \RuntimeException(
32-
"Can't detect http user name.\n" .
33-
"Please setup `http_group` config parameter.",
32+
"Can't detect http user name.\n"
33+
. "Please setup `http_group` config parameter.",
3434
);
3535
}
3636

@@ -149,12 +149,12 @@
149149
} elseif ($mode === 'sticky') {
150150
// Changes the group of the files, sets sticky bit to the directories
151151
// and add the writable bit for all files
152-
run("for dir in $dirs;" .
153-
'do ' .
154-
'chgrp -L -R {{http_group}} ${dir}; ' .
155-
'find ${dir} -type d -exec chmod g+rwxs \{\} \;;' .
156-
'find ${dir} -type f -exec chmod g+rw \{\} \;;' .
157-
'done');
152+
run("for dir in $dirs;"
153+
. 'do '
154+
. 'chgrp -L -R {{http_group}} ${dir}; '
155+
. 'find ${dir} -type d -exec chmod g+rwxs \{\} \;;'
156+
. 'find ${dir} -type f -exec chmod g+rw \{\} \;;'
157+
. 'done');
158158
} elseif ($mode === 'skip') {
159159
// Does nothing, saves time if no changes are required for some environments
160160
return;

0 commit comments

Comments
 (0)