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

DocumentRepository::load()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 11
nc 4
nop 1
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\Document;
10
11
use Doctrine\Common\Collections\ArrayCollection;
12
13
/**
14
 * @author John Kleijn <[email protected]>
15
 */
16
class DocumentRepository extends ArrayCollection
17
{
18
    /**
19
     * @var string
20
     */
21
    private $basePath;
22
23
    /**
24
     * Initializes a new Repository.
25
     *
26
     * @param string $basePath
27
     */
28
    public function __construct($basePath = null)
29
    {
30
        $this->basePath = $basePath;
31
        parent::__construct([]);
32
    }
33
34
    /**
35
     * @param string $documentPath
36
     *
37
     * @return SwaggerDocument
38
     */
39
    public function get($documentPath)
40
    {
41
        if ($this->basePath) {
42
            $documentPath = "$this->basePath/$documentPath";
43
        }
44
        if (!$documentPath) {
45
            throw new \InvalidArgumentException("No document path provided");
46
        }
47
        $document = parent::get($documentPath);
48
49
        if (!$document) {
50
            $document = new SwaggerDocument($documentPath);
51
            $this->set($documentPath, $document);
52
        }
53
54
        return $document;
55
    }
56
}
57