InlineReferenceSerializer   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 2

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 15 3
1
<?php
2
3
namespace League\JsonReference\ReferenceSerializer;
4
5
use League\JsonReference\Reference;
6
use League\JsonReference\ReferenceSerializationException;
7
use League\JsonReference\ReferenceSerializerInterface;
8
9
/**
10
 * A reference serializer that attempts to inline the referenced schema.
11
 */
12
final class InlineReferenceSerializer implements ReferenceSerializerInterface
13
{
14 8
    public function serialize(Reference $reference)
15
    {
16 8
        $stack  = [];
17 8
        $schema = $stack[] = $reference->resolve();
18
19 8
        while ($schema instanceof Reference) {
20 2
            $resolved = $schema->resolve();
21 2
            if (in_array($resolved, $stack)) {
22 2
                throw ReferenceSerializationException::circular($schema->getRef());
23
            }
24
            $schema = $resolved;
25
        }
26
27 6
        return $schema;
28
    }
29
}
30