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

ScriptHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A installSwaggerUi() 0 15 3
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 = 'web/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
    public static function installSwaggerUi()
27
    {
28
        $fs = new Filesystem();
29
        $cwd = getcwd();
30
31
        foreach ((new Finder())->in(implode('/', [$cwd, self::SWAGGER_UI_SOURCE])) as $file) {
32
            $destination = implode('/', [$cwd, self::SWAGGER_UI_DESTINATION, $file->getRelativePathname()]);
33
            if ($file->isDir()) {
34
                $fs->mkdir($destination);
35
                continue;
36
            }
37
38
            $fs->copy($file->getRealPath(), $destination, true);
39
        }
40
    }
41
}
42