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

NeoIsRecursive / inertia-tempest / 27938424188

22 Jun 2026 08:05AM UTC coverage: 92.754% (-6.1%) from 98.81%
27938424188

Pull #23

github

web-flow
Merge ae1c83b3e into 90d76d658
Pull Request #23: feat: inertia 3

221 of 245 new or added lines in 21 files covered. (90.2%)

8 existing lines in 1 file now uncovered.

320 of 345 relevant lines covered (92.75%)

18.92 hits per line

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

81.58
/src/Props/ScrollProp.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace NeoIsRecursive\Inertia\Props;
6

7
use Closure;
8
use NeoIsRecursive\Inertia\Concerns\IsCallableProp;
9
use NeoIsRecursive\Inertia\Concerns\IsMergeableProp;
10
use NeoIsRecursive\Inertia\Contracts\CallableProp;
11
use NeoIsRecursive\Inertia\Contracts\MergeableProp;
12
use NeoIsRecursive\Inertia\Contracts\ProvidesScrollMetadata;
13
use Override;
14
use Tempest\Support\Paginator\PaginatedData;
15

16
final class ScrollProp implements CallableProp, MergeableProp
17
{
18
    use IsMergeableProp;
19
    use IsCallableProp;
20

21
    public mixed $resolved = null;
22
    public bool $shouldMerge = true;
23

24
    public function __construct(
25
        public readonly mixed $value,
26
        public string $pageName,
27
        public string $wrapper = 'data',
28
        /** @var ProvidesScrollMetadata|Closure(mixed):ProvidesScrollMetadata|null */
29
        public ProvidesScrollMetadata|Closure|null $metadata = null,
30
    ) {}
1✔
31

32
    public function mergeKey(string|int $key): string|int
33
    {
34
        if (!is_string($key) || $this->wrapper === '') {
1✔
NEW
35
            return $key;
×
36
        }
37

38
        return sprintf('%s.%s', $key, $this->wrapper);
1✔
39
    }
40

41
    protected function resolveValue(): mixed
42
    {
43
        if ($this->resolved !== null) {
1✔
44
            return $this->resolved;
1✔
45
        }
46

47
        $this->resolved = $this->resolveCallablePropValue($this->value);
1✔
48

49
        return $this->resolved;
1✔
50
    }
51

52
    /**
53
     * Resolve the scroll metadata provider.
54
     *
55
     * @throws \LogicException
56
     */
57
    protected function resolveMetadataProvider(): ProvidesScrollMetadata
58
    {
59
        if ($this->metadata instanceof ProvidesScrollMetadata) {
1✔
NEW
60
            return $this->metadata;
×
61
        }
62

63
        $value = $this->resolveValue();
1✔
64

65
        if ($this->metadata === null) {
1✔
66
            $pageName = $this->pageName;
1✔
67

68
            if ($value instanceof PaginatedData) {
1✔
69
                return new class($pageName, $value) implements ProvidesScrollMetadata {
1✔
70
                    public function __construct(
71
                        private string $pageName,
72
                        private PaginatedData $value,
73
                    ) {}
1✔
74

75
                    public function getPageName(): string
76
                    {
77
                        return $this->pageName;
1✔
78
                    }
79

80
                    public function getPreviousPage(): int|string|null
81
                    {
82
                        return $this->value->previousPage;
1✔
83
                    }
84

85
                    public function getNextPage(): int|string|null
86
                    {
87
                        return $this->value->nextPage;
1✔
88
                    }
89

90
                    public function getCurrentPage(): int|string|null
91
                    {
92
                        return $this->value->currentPage;
1✔
93
                    }
94
                };
1✔
95
            }
96
        }
97

NEW
98
        $metadata = $this->metadata;
×
99

NEW
100
        if (!$metadata instanceof Closure) {
×
NEW
101
            throw new \LogicException('Scroll metadata resolver must be a closure or metadata provider.');
×
102
        }
103

104
        /** @var Closure(mixed):ProvidesScrollMetadata $metadata */
NEW
105
        return $metadata($value);
×
106
    }
107

108
    /**
109
     * Get the pagination meta information.
110
     *
111
     * @return array{pageName: string, previousPage: int|string|null, nextPage: int|string|null, currentPage: int|string|null}
112
     */
113
    public function metadata(): array
114
    {
115
        $metadataProvider = $this->resolveMetadataProvider();
1✔
116

117
        return [
1✔
118
            'pageName' => $metadataProvider->getPageName(),
1✔
119
            'previousPage' => $metadataProvider->getPreviousPage(),
1✔
120
            'nextPage' => $metadataProvider->getNextPage(),
1✔
121
            'currentPage' => $metadataProvider->getCurrentPage(),
1✔
122
        ];
1✔
123
    }
124

125
    #[Override]
126
    public function __invoke(): mixed
127
    {
128
        $value = $this->resolveValue();
1✔
129

130
        if ($value instanceof PaginatedData) {
1✔
131
            return [
1✔
132
                $this->wrapper => $value->data,
1✔
133
            ];
1✔
134
        }
135

NEW
136
        return $value;
×
137
    }
138
}
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

© 2026 Coveralls, Inc