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

@@ 273-298 (lines=26) @@
270
     * @return void
271
     * @throws \Exception Is thrown, if the directory can not be removed
272
     */
273
    protected function removeDir($src)
274
    {
275
276
        // open the directory
277
        $dir = opendir($src);
278
279
        // remove files/folders recursively
280
        while (false !== ($file = readdir($dir))) {
281
            if (($file != '.') && ($file != '..')) {
282
                $full = $src . '/' . $file;
283
                if (is_dir($full)) {
284
                    $this->removeDir($full);
285
                } else {
286
                    if (!unlink($full)) {
287
                        throw new \Exception(sprintf('Can\'t remove file %s', $full));
288
                    }
289
                }
290
            }
291
        }
292
293
        // close handle and remove directory itself
294
        closedir($dir);
295
        if (!rmdir($src)) {
296
            throw new \Exception(sprintf('Can\'t remove directory %s', $src));
297
        }
298
    }
299
300
    /**
301
     * Return's the configured swift mailer instance.