Code Duplication    Length = 26-26 lines in 2 locations

src/Adapter/PhpFilesystemAdapter.php 1 location

@@ 178-203 (lines=26) @@
175
     * @return void
176
     * @throws \Exception Is thrown, if the directory can not be removed
177
     */
178
    public function removeDir($src, $recursive = false)
179
    {
180
181
        // open the directory
182
        $dir = opendir($src);
183
184
        // remove files/folders recursively
185
        while (false !== ($file = readdir($dir))) {
186
            if (($file != '.') && ($file != '..')) {
187
                $full = $src . '/' . $file;
188
                if (is_dir($full)) {
189
                    $recursive ?? $this->removeDir($full, $recursive);
190
                } else {
191
                    if (!unlink($full)) {
192
                        throw new \Exception(sprintf('Can\'t remove file %s', $full));
193
                    }
194
                }
195
            }
196
        }
197
198
        // close handle and remove directory itself
199
        closedir($dir);
200
        if (!rmdir($src)) {
201
            throw new \Exception(sprintf('Can\'t remove directory %s', $src));
202
        }
203
    }
204
}
205

src/Plugins/AbstractPlugin.php 1 location

@@ 295-320 (lines=26) @@
292
     * @return void
293
     * @throws \Exception Is thrown, if the directory can not be removed
294
     */
295
    protected function removeDir($src)
296
    {
297
298
        // open the directory
299
        $dir = opendir($src);
300
301
        // remove files/folders recursively
302
        while (false !== ($file = readdir($dir))) {
303
            if (($file != '.') && ($file != '..')) {
304
                $full = $src . '/' . $file;
305
                if (is_dir($full)) {
306
                    $this->removeDir($full);
307
                } else {
308
                    if (!unlink($full)) {
309
                        throw new \Exception(sprintf('Can\'t remove file %s', $full));
310
                    }
311
                }
312
            }
313
        }
314
315
        // close handle and remove directory itself
316
        closedir($dir);
317
        if (!rmdir($src)) {
318
            throw new \Exception(sprintf('Can\'t remove directory %s', $src));
319
        }
320
    }
321
322
    /**
323
     * Return's the configured swift mailer instance.