Test Failed
Pull Request — main (#152)
by Daniel
04:35
created

ResourceMetadataProvider::resourceMetadataExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[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
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\Serializer\ResourceMetadata;
15
16
class ResourceMetadataProvider
17
{
18
    public array $metadatas = [];
19
20
    public function findResourceMetadata(object $object): ResourceMetadata
21
    {
22
        $hash = spl_object_id($object);
23
        if ($this->resourceMetadataExists($object)) {
24
            return $this->metadatas[$hash]['metadata'];
25
        }
26
        $this->metadatas[$hash] = [
27
            'resource' => $object,
28
            'metadata' => new ResourceMetadata()
29
        ];
30
31
        return $this->metadatas[$hash]['metadata'];
32
    }
33
34
    public function resourceMetadataExists(object $object): bool
35
    {
36
        $hash = spl_object_id($object);
37
38
        return isset($this->metadatas[$hash]);
39
    }
40
41
    public function getMetadatas(): array
42
    {
43
        return $this->metadatas;
44
    }
45
}
46