Completed
Pull Request — master (#768)
by Antoine
03:02
created

ScriptHandler::installSwaggerUi()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ApiPlatform\Core\Composer;
13
14
use Composer\Script\Event;
15
use Symfony\Component\Filesystem\Filesystem;
16
use Symfony\Component\Finder\Finder;
17
18
class ScriptHandler
19
{
20
    const SWAGGER_UI_DESTINATION = '/src/Bridge/Symfony/Bundle/Resources/public/swagger-ui';
21
    const SWAGGER_UI_SOURCE = '/vendor/swagger-api/swagger-ui/dist';
22
23
    /**
24
     * Copy swagger ui to the correct directory.
25
     *
26
     * @parm Event $event
27
     */
28
    public static function installSwaggerUi(Event $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        $fs = new Filesystem();
31
        $cwd = getcwd();
32
33
        foreach ((new Finder())->in($cwd.self::SWAGGER_UI_SOURCE) as $file) {
34
            $destination = $cwd.self::SWAGGER_UI_DESTINATION.'/'.$file->getRelativePathname();
35
            if ($file->isDir()) {
36
                $fs->mkdir($destination);
37
                continue;
38
            }
39
40
            $fs->copy($file->getRealPath(), $destination, true);
41
        }
42
    }
43
}
44