Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
GetSingleResourceFile
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getContents
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getSize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMimeType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\ApieFileSystem\Virtual;
3
4use Apie\Core\Context\ApieContext;
5use Apie\Core\Entities\EntityInterface;
6use Apie\Core\Identifier\IdentifierInterface;
7use Apie\Serializer\Serializer;
8
9class GetSingleResourceFile implements VirtualFileInterface
10{
11    public function __construct(
12        private readonly EntityInterface $resource,
13        private readonly Serializer $serializer,
14        private readonly ApieContext $context,
15    ) {
16    }
17
18    public function getName(): string
19    {
20        /** @var IdentifierInterface<EntityInterface> */
21        $identifier = $this->resource->getId();
22        return $identifier->toNative() . '.json';
23    }
24
25    public function getContents(): string
26    {
27        return json_encode(
28            $this->serializer->normalize($this->resource, $this->context),
29            JSON_PRETTY_PRINT
30        );
31    }
32
33    public function getSize(): int
34    {
35        return strlen($this->getContents());
36    }
37
38    public function getMimeType(): string
39    {
40        return 'application/json';
41    }
42}