Skip to content

Commit 13699c3

Browse files
committed
Use bound Closure instead of "$self = $this" ... fn use ($self)
1 parent 04ae6b2 commit 13699c3

1 file changed

Lines changed: 24 additions & 27 deletions

File tree

src/ExtensionInstaller.php

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,20 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
6060

6161
$this->rcubeVersionCheck($package);
6262

63-
$self = $this;
64-
$postInstall = function() use ($self, $package) {
65-
$config_file = $self->rcubeConfigFile();
66-
$package_name = $self->getPackageName($package);
67-
$package_dir = $self->getVendorDir() . DIRECTORY_SEPARATOR . $package_name;
63+
$postInstall = function() use ($package) {
64+
$config_file = $this->rcubeConfigFile();
65+
$package_name = $this->getPackageName($package);
66+
$package_dir = $this->getVendorDir() . DIRECTORY_SEPARATOR . $package_name;
6867
$extra = $package->getExtra();
6968

7069
if (is_writeable($config_file) && php_sapi_name() == 'cli' && $this->confirmInstall($package_name)) {
71-
$self->rcubeAlterConfig($package_name);
70+
$this->rcubeAlterConfig($package_name);
7271
}
7372

7473
// copy config.inc.php.dist -> config.inc.php
7574
if (is_file($package_dir . DIRECTORY_SEPARATOR . 'config.inc.php.dist')) {
7675
$config_exists = false;
77-
$alt_config_file = $self->rcubeConfigFile($package_name . '.inc.php');
76+
$alt_config_file = $this->rcubeConfigFile($package_name . '.inc.php');
7877

7978
if (is_file($package_dir . DIRECTORY_SEPARATOR . 'config.inc.php')) {
8079
$config_exists = true;
@@ -84,15 +83,15 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
8483
}
8584

8685
if (!$config_exists && is_writeable($package_dir)) {
87-
$self->io->write("<info>Creating package config file</info>");
86+
$this->io->write("<info>Creating package config file</info>");
8887
copy($package_dir . DIRECTORY_SEPARATOR . 'config.inc.php.dist', $package_dir . DIRECTORY_SEPARATOR . 'config.inc.php');
8988
}
9089
}
9190

9291
// initialize database schema
9392
if (!empty($extra['roundcube']['sql-dir'])) {
9493
if ($sqldir = realpath($package_dir . DIRECTORY_SEPARATOR . $extra['roundcube']['sql-dir'])) {
95-
$self->io->write("<info>Running database initialization script for $package_name</info>");
94+
$this->io->write("<info>Running database initialization script for $package_name</info>");
9695

9796
$roundcube_version = self::versionNormalize(RCMAIL_VERSION);
9897
if (self::versionCompare($roundcube_version, '1.2.0', '>=')) {
@@ -106,7 +105,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
106105

107106
// run post-install script
108107
if (!empty($extra['roundcube']['post-install-script'])) {
109-
$self->rcubeRunScript($extra['roundcube']['post-install-script'], $package);
108+
$this->rcubeRunScript($extra['roundcube']['post-install-script'], $package);
110109
}
111110
};
112111

@@ -134,29 +133,28 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
134133

135134
$this->rcubeVersionCheck($target);
136135

137-
$self = $this;
138136
$extra = $target->getExtra();
139137
$fs = new Filesystem();
140138

141139
// backup persistent files e.g. config.inc.php
142-
$package_name = $self->getPackageName($initial);
143-
$package_dir = $self->getVendorDir() . DIRECTORY_SEPARATOR . $package_name;
140+
$package_name = $this->getPackageName($initial);
141+
$package_dir = $this->getVendorDir() . DIRECTORY_SEPARATOR . $package_name;
144142
$temp_dir = $package_dir . '-' . sprintf('%010d%010d', mt_rand(), mt_rand());
145143

146144
// make a backup of existing files (for restoring persistent files)
147145
$fs->copy($package_dir, $temp_dir);
148146

149-
$postUpdate = function() use ($self, $target, $extra, $fs, $temp_dir) {
150-
$package_name = $self->getPackageName($target);
151-
$package_dir = $self->getVendorDir() . DIRECTORY_SEPARATOR . $package_name;
147+
$postUpdate = function() use ($target, $extra, $fs, $temp_dir) {
148+
$package_name = $this->getPackageName($target);
149+
$package_dir = $this->getVendorDir() . DIRECTORY_SEPARATOR . $package_name;
152150

153151
// restore persistent files
154152
$persistent_files = !empty($extra['roundcube']['persistent-files']) ? $extra['roundcube']['persistent-files'] : ['config.inc.php'];
155153
foreach ($persistent_files as $file) {
156154
$path = $temp_dir . DIRECTORY_SEPARATOR . $file;
157155
if (is_readable($path)) {
158156
if ($fs->copy($path, $package_dir . DIRECTORY_SEPARATOR . $file)) {
159-
$self->io->write("<info>Restored $package_name/$file</info>");
157+
$this->io->write("<info>Restored $package_name/$file</info>");
160158
}
161159
else {
162160
throw new \Exception("Restoring " . $file . " failed.");
@@ -169,7 +167,7 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
169167
// update database schema
170168
if (!empty($extra['roundcube']['sql-dir'])) {
171169
if ($sqldir = realpath($package_dir . DIRECTORY_SEPARATOR . $extra['roundcube']['sql-dir'])) {
172-
$self->io->write("<info>Updating database schema for $package_name</info>");
170+
$this->io->write("<info>Updating database schema for $package_name</info>");
173171

174172
$roundcube_version = self::versionNormalize(RCMAIL_VERSION);
175173
if (self::versionCompare($roundcube_version, '1.2.0', '>=')) {
@@ -183,7 +181,7 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
183181

184182
// run post-update script
185183
if (!empty($extra['roundcube']['post-update-script'])) {
186-
$self->rcubeRunScript($extra['roundcube']['post-update-script'], $target);
184+
$this->rcubeRunScript($extra['roundcube']['post-update-script'], $target);
187185
}
188186
};
189187

@@ -209,27 +207,26 @@ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $
209207
}
210208
require_once INSTALL_PATH . 'program/include/iniset.php';
211209

212-
$self = $this;
213-
$config = $self->composer->getConfig()->get('roundcube');
210+
$config = $this->composer->getConfig()->get('roundcube');
214211

215-
$postUninstall = function() use ($self, $package, $config) {
212+
$postUninstall = function() use ($package, $config) {
216213
// post-uninstall: deactivate package
217-
$package_name = $self->getPackageName($package);
218-
$package_dir = $self->getVendorDir() . DIRECTORY_SEPARATOR . $package_name;
214+
$package_name = $this->getPackageName($package);
215+
$package_dir = $this->getVendorDir() . DIRECTORY_SEPARATOR . $package_name;
219216

220-
$self->rcubeAlterConfig($package_name, false);
217+
$this->rcubeAlterConfig($package_name, false);
221218

222219
// run post-uninstall script
223220
$extra = $package->getExtra();
224221
if (!empty($extra['roundcube']['post-uninstall-script'])) {
225-
$self->rcubeRunScript($extra['roundcube']['post-uninstall-script'], $package);
222+
$this->rcubeRunScript($extra['roundcube']['post-uninstall-script'], $package);
226223
}
227224

228225
// remove package folder
229226
if (!empty($config['uninstall-remove-folder'])) {
230227
$fs = new Filesystem();
231228
$fs->remove($package_dir);
232-
$self->io->write("<info>Removed $package_name files</info>");
229+
$this->io->write("<info>Removed $package_name files</info>");
233230
}
234231
};
235232

0 commit comments

Comments
 (0)