• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 11924655642

19 Nov 2024 12:37PM UTC coverage: 81.705% (-0.2%) from 81.946%
11924655642

push

github

web-flow
chore(core): framework installer improvements (#752)

1 of 17 new or added lines in 2 files covered. (5.88%)

56 existing lines in 5 files now uncovered.

7869 of 9631 relevant lines covered (81.7%)

51.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/src/Tempest/Core/src/Composer.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Core;
6

7
use function Tempest\path;
8
use function Tempest\Support\arr;
9

10
final class Composer
11
{
12
    /** @var array<ComposerNamespace> */
13
    public array $namespaces;
14

15
    public ?ComposerNamespace $mainNamespace = null;
16

17
    private string $composerPath;
18

19
    private array $composer;
20

21
    public function __construct(
381✔
22
        private string $root,
23
    ) {
24
        $this->composerPath = path($this->root, 'composer.json')->toString();
381✔
25
        $this->composer = $this->loadComposerFile($this->composerPath);
381✔
26
        $this->namespaces = arr($this->composer)
381✔
27
            ->get('autoload.psr-4', default: arr())
381✔
28
            ->map(fn (string $path, string $namespace) => new ComposerNamespace($namespace, $path))
381✔
29
            ->values()
381✔
30
            ->toArray();
381✔
31

32
        foreach ($this->namespaces as $namespace) {
381✔
33
            if (str_starts_with($namespace->path, 'app/') || str_starts_with($namespace->path, 'src/')) {
381✔
34
                $this->mainNamespace = $namespace;
381✔
35

36
                break;
381✔
37
            }
38
        }
39

40
        if (! isset($this->mainNamespace) && count($this->namespaces)) {
381✔
UNCOV
41
            $this->mainNamespace = $this->namespaces[0];
×
42
        }
43
    }
44

45
    public function setMainNamespace(ComposerNamespace $namespace): self
31✔
46
    {
47
        $this->mainNamespace = $namespace;
31✔
48

49
        return $this;
31✔
50
    }
51

UNCOV
52
    public function addNamespace(string $namespace, string $path): self
×
53
    {
UNCOV
54
        $path = str_replace($this->root, '.', $path);
×
55

UNCOV
56
        $this->composer['autoload']['psr-4'][$namespace] = $path;
×
57

UNCOV
58
        return $this;
×
59
    }
60

UNCOV
61
    public function save(): self
×
62
    {
UNCOV
63
        file_put_contents($this->composerPath, json_encode($this->composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
×
64

UNCOV
65
        return $this;
×
66
    }
67

68
    private function loadComposerFile(string $path): array
381✔
69
    {
70
        if (! file_exists($path)) {
381✔
71
            throw new KernelException("Could not locate composer.json.");
1✔
72
        }
73

74
        return json_decode(file_get_contents($path), associative: true);
381✔
75
    }
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc