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

conedevelopment / root / 13086943877

01 Feb 2025 08:35AM UTC coverage: 79.285% (+1.2%) from 78.037%
13086943877

push

github

web-flow
Merge pull request #234 from xHeaven/patch-1

Codebase health checkup

195 of 239 new or added lines in 45 files covered. (81.59%)

2 existing lines in 2 files now uncovered.

2572 of 3244 relevant lines covered (79.28%)

35.8 hits per line

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

96.15
/src/Fields/Fields.php
1
<?php
2

3
namespace Cone\Root\Fields;
4

5
use Cone\Root\Traits\RegistersRoutes;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Http\Request;
8
use Illuminate\Routing\Router;
9
use Illuminate\Support\Arr;
10
use Illuminate\Support\Collection;
11

12
class Fields extends Collection
13
{
14
    /**
15
     * Register the given fields.
16
     */
17
    public function register(array|Field $fields): static
18
    {
19
        foreach (Arr::wrap($fields) as $field) {
198✔
20
            $this->push($field);
198✔
21
        }
22

23
        return $this;
198✔
24
    }
25

26
    /**
27
     * Persist the request value on the model.
28
     */
29
    public function persist(Request $request, Model $model): void
30
    {
31
        $this->each(static function (Field $field) use ($request, $model): void {
7✔
32
            $field->persist(
7✔
33
                $request, $model, $field->getValueForHydrate($request)
7✔
34
            );
7✔
35
        });
7✔
36
    }
37

38
    /**
39
     * Filter the fields that are available for the current request and model.
40
     */
41
    public function authorized(Request $request, ?Model $model = null): static
42
    {
43
        return $this->filter->authorized($request, $model)->values();
19✔
44
    }
45

46
    /**
47
     * Filter the fields that are visible in the given context.
48
     */
49
    public function visible(string|array $context): static
50
    {
51
        return $this->filter->visible($context)->values();
16✔
52
    }
53

54
    /**
55
     * Filter the searchable fields.
56
     */
57
    public function searchable(): static
58
    {
59
        return $this->filter->isSearchable();
6✔
60
    }
61

62
    /**
63
     * Filter the sortable fields.
64
     */
65
    public function sortable(): static
66
    {
67
        return $this->filter->isSortable();
6✔
68
    }
69

70
    /**
71
     * Filter the relation fields.
72
     */
73
    public function relation(): static
74
    {
NEW
75
        return $this->filter(static fn (Field $field): bool => $field instanceof Relation);
×
76
    }
77

78
    /**
79
     * Filter the translatable fields.
80
     */
81
    public function translatable(): static
82
    {
83
        return $this->filter(static fn (Field $field): bool => $field->isTranslatable());
198✔
84
    }
85

86
    /**
87
     * Filter the subresource fields.
88
     */
89
    public function subResource(bool $value = true): static
90
    {
91
        return $this->filter(static fn (Field $field): bool => $value
11✔
92
            ? $field instanceof Relation && $field->isSubResource()
1✔
93
            : ! $field instanceof Relation || ! $field->isSubResource());
11✔
94
    }
95

96
    /**
97
     * Map the fields to validate.
98
     */
99
    public function mapToValidate(Request $request, Model $model): array
100
    {
101
        return $this->reduce(static fn (array $rules, Field $field): array => array_merge_recursive($rules, $field->toValidate($request, $model)), []);
11✔
102
    }
103

104
    /**
105
     * Map the fields to displayable data.
106
     */
107
    public function mapToDisplay(Request $request, Model $model): array
108
    {
109
        return $this->map->toDisplay($request, $model)->filter()->values()->all();
5✔
110
    }
111

112
    /**
113
     * Map the fields to form inputs.
114
     */
115
    public function mapToInputs(Request $request, Model $model): array
116
    {
117
        return $this->map->toInput($request, $model)->filter()->values()->all();
8✔
118
    }
119

120
    /**
121
     * Register the field routes.
122
     */
123
    public function registerRoutes(Request $request, Router $router): void
124
    {
125
        $router->prefix('fields')->group(function (Router $router) use ($request): void {
198✔
126
            $this->each(static function (Field $field) use ($request, $router): void {
198✔
127
                if (in_array(RegistersRoutes::class, class_uses_recursive($field))) {
198✔
128
                    /** @var \Cone\Root\Tests\phpstan\FieldWithRoute $field */
129
                    $field->registerRoutes($request, $router);
198✔
130
                }
131
            });
198✔
132
        });
198✔
133
    }
134
}
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