CollectionGenerator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 79
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A generate() 0 17 2
1
<?php
2
3
/*
4
 * This file is part of the PostmanGeneratorBundle package.
5
 *
6
 * (c) Vincent Chalamon <[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 PostmanGeneratorBundle\Generator;
13
14
use Dunglas\ApiBundle\Api\ResourceCollectionInterface;
15
use Dunglas\ApiBundle\Api\ResourceInterface;
16
use PostmanGeneratorBundle\Model\Collection;
17
use Ramsey\Uuid\Uuid;
18
19
class CollectionGenerator implements GeneratorInterface
20
{
21
    /**
22
     * @var ResourceCollectionInterface
23
     */
24
    private $resourceCollection;
25
26
    /**
27
     * @var RequestGenerator
28
     */
29
    private $requestGenerator;
30
31
    /**
32
     * @var FolderGenerator
33
     */
34
    private $folderGenerator;
35
36
    /**
37
     * @var string
38
     */
39
    private $name;
40
41
    /**
42
     * @var string
43
     */
44
    private $description;
45
46
    /**
47
     * @var bool
48
     */
49
    private $public = false;
50
51
    /**
52
     * @param ResourceCollectionInterface $resourceCollection
53
     * @param RequestGenerator            $requestGenerator
54
     * @param FolderGenerator             $folderGenerator
55
     * @param bool                        $public
56
     * @param string                      $name
57
     * @param string                      $description
58
     */
59 1
    public function __construct(
60
        ResourceCollectionInterface $resourceCollection,
61
        RequestGenerator $requestGenerator,
62
        FolderGenerator $folderGenerator,
63
        $public,
64
        $name = null,
65
        $description = null
66
    ) {
67 1
        $this->resourceCollection = $resourceCollection;
68 1
        $this->requestGenerator = $requestGenerator;
69 1
        $this->folderGenerator = $folderGenerator;
70 1
        $this->public = $public;
71 1
        $this->name = $name;
72 1
        $this->description = $description;
73 1
    }
74
75
    /**
76
     * {@inheritdoc}
77
     *
78
     * @return Collection
79
     */
80 1
    public function generate(ResourceInterface $resource = null)
81
    {
82 1
        $collection = new Collection();
83 1
        $collection->setId((string) Uuid::uuid4());
84 1
        $collection->setName($this->name);
85 1
        $collection->setDescription($this->description);
86 1
        $collection->setPublic($this->public);
87
88 1
        foreach ($this->resourceCollection as $resource) {
89 1
            $folder = $this->folderGenerator->generate($resource);
90 1
            $folder->setRequests($this->requestGenerator->generate($resource));
91
92 1
            $collection->addFolder($folder);
93 1
        }
94
95 1
        return $collection;
96
    }
97
}
98