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

conedevelopment / root / 15084089635

17 May 2025 10:00AM UTC coverage: 77.93% (+0.04%) from 77.891%
15084089635

push

github

web-flow
Modernize back-end.yml (#240)

3291 of 4223 relevant lines covered (77.93%)

36.04 hits per line

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

86.36
/src/Fields/URL.php
1
<?php
2

3
namespace Cone\Root\Fields;
4

5
use Closure;
6
use Cone\Root\Root;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Http\Request;
9

10
class URL extends Text
11
{
12
    /**
13
     * The text resolver callback.
14
     */
15
    protected Closure $textResolver;
16

17
    /**
18
     * Create a new field instance.
19
     */
20
    public function __construct(string $label, Closure|string|null $modelAttribute = null)
2✔
21
    {
22
        parent::__construct($label, $modelAttribute);
2✔
23

24
        $this->type('url');
2✔
25

26
        $this->textResolver = fn (): string => 'URL';
2✔
27
    }
28

29
    /**
30
     * Set the text resolver callback.
31
     */
32
    public function text(Closure|string $value): static
×
33
    {
34
        $this->textResolver = is_string($value) ? fn (): string => $value : $value;
×
35

36
        return $this;
×
37
    }
38

39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function resolveFormat(Request $request, Model $model): ?string
1✔
43
    {
44
        if (is_null($this->formatResolver)) {
1✔
45
            $this->formatResolver = fn (Request $request, Model $model, mixed $value): ?string => is_null($value) ? $value : sprintf(
1✔
46
                '<a href="%1$s" title="%1$s"%2$s>%3$s</a>',
1✔
47
                $value,
1✔
48
                $this->isExternal($value) ? ' data-turbo="false" target="_blank"' : '',
1✔
49
                call_user_func_array($this->textResolver, [$model])
1✔
50
            );
1✔
51
        }
52

53
        return parent::resolveFormat($request, $model);
1✔
54
    }
55

56
    /**
57
     * Determine if the given URL is external.
58
     */
59
    public function isExternal(string $value): bool
1✔
60
    {
61
        $root = Root::instance();
1✔
62

63
        [$domain, $path] = [$root->getDomain(), $root->getPath()];
1✔
64

65
        $url = parse_url($value);
1✔
66

67
        return $domain !== ($url['host'] ?? null)
1✔
68
            && ! str_starts_with(ltrim($url['path'] ?? '', '/'), ltrim($path, '/'));
1✔
69
    }
70
}
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