Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
BoundedContextFolder
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getChild
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 getChildren
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\ApieFileSystem\Virtual;
3
4use Apie\ApieFileSystem\Lists\VirtualFileMap;
5use Apie\Common\ActionDefinitionProvider;
6use Apie\Core\BoundedContext\BoundedContext;
7use Apie\Core\BoundedContext\BoundedContextId;
8use Apie\Core\Context\ApieContext;
9use Apie\Core\ContextConstants;
10
11/**
12 * A folder representing a bounded context in the virtual file system.
13 *
14 * @see RootFolder parent instance
15 * @see ResourcesFolder child instances
16 */
17class BoundedContextFolder implements VirtualFolderInterface
18{
19    private readonly ApieContext $apieContext;
20
21    public function __construct(
22        private readonly BoundedContext $boundedContext,
23        private readonly ActionDefinitionProvider $actionDefinitionProvider,
24        ApieContext $apieContext
25    ) {
26        $this->apieContext = $apieContext
27            ->withContext(
28                ContextConstants::BOUNDED_CONTEXT_ID,
29                $this->boundedContext->getId()->toNative()
30            )
31            ->withContext(
32                BoundedContextId::class,
33                $this->boundedContext->getId()
34            );
35    }
36
37    public function getName(): string
38    {
39        return $this->boundedContext->getId()->toNative();
40    }
41
42    public function getChild(string $name): VirtualFileInterface|VirtualFolderInterface|null
43    {
44        if ($name === 'resources') {
45            return new ResourcesFolder(
46                $this->boundedContext,
47                $this->actionDefinitionProvider,
48                $this->apieContext
49            );
50        }
51        return null;
52    }
53
54    public function getChildren(): VirtualFileMap
55    {
56        return new VirtualFileMap([
57            'resources' => new ResourcesFolder(
58                $this->boundedContext,
59                $this->actionDefinitionProvider,
60                $this->apieContext
61            ),
62        ]);
63    }
64}