Completed
Push — master ( 6ebd1c...df9bae )
by John
10:14
created

ResourceGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 19 2
1
<?php
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Dev\Generator;
10
11
use KleijnWeb\SwaggerBundle\Document\SwaggerDocument;
12
use Sensio\Bundle\GeneratorBundle\Generator\Generator;
13
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
14
15
/**
16
 * @author John Kleijn <[email protected]>
17
 */
18
class ResourceGenerator extends Generator
19
{
20
    /**
21
     * @param BundleInterface $bundle
22
     * @param SwaggerDocument $document
23
     * @param string          $relativeNamespace
24
     */
25
    public function generate(BundleInterface $bundle, SwaggerDocument $document, $relativeNamespace = 'Model\Resources')
26
    {
27
        $dir = $bundle->getPath();
28
29
        $parameters = [
30
            'namespace'          => $bundle->getNamespace(),
31
            'bundle'             => $bundle->getName(),
32
            'resource_namespace' => $relativeNamespace
33
        ];
34
35
        foreach ($document->getResourceSchemas() as $typeName => $spec) {
36
            $resourceFile = "$dir/" . str_replace('\\', '/', $relativeNamespace) . "/$typeName.php";
37
            $this->renderFile(
38
                'resource.php.twig',
39
                $resourceFile,
40
                array_merge($parameters, $spec, ['resource' => $typeName, 'resource_class' => $typeName])
41
            );
42
        }
43
    }
44
}
45