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

conedevelopment / bazar / 20694116184

04 Jan 2026 02:08PM UTC coverage: 68.615% (+4.5%) from 64.117%
20694116184

push

github

iamgergo
version

1679 of 2447 relevant lines covered (68.61%)

25.06 hits per line

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

13.64
/src/Gateway/Response.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Bazar\Gateway;
6

7
use Closure;
8
use Illuminate\Contracts\Support\Arrayable;
9
use Illuminate\Contracts\Support\Responsable;
10
use Illuminate\Http\JsonResponse;
11
use Illuminate\Http\RedirectResponse;
12
use Symfony\Component\HttpFoundation\Response as BaseResponse;
13

14
class Response implements Arrayable, Responsable
15
{
16
    /**
17
     * The redirect URL.
18
     */
19
    protected string $url = '/';
20

21
    /**
22
     * The response data.
23
     */
24
    protected array $data = [];
25

26
    /**
27
     * The response resolver.
28
     */
29
    protected ?Closure $responseResolver = null;
30

31
    /**
32
     * Create a new response instance.
33
     */
34
    public function __construct(string $url = '/', array $data = [])
3✔
35
    {
36
        $this->url = $url;
3✔
37
        $this->data = $data;
3✔
38
    }
39

40
    /**
41
     * Set the redirect URL.
42
     */
43
    public function url(string $url): static
×
44
    {
45
        $this->url = $url;
×
46

47
        return $this;
×
48
    }
49

50
    /**
51
     * Set the response data.
52
     */
53
    public function data(array $data): static
×
54
    {
55
        $this->data = $data;
×
56

57
        return $this;
×
58
    }
59

60
    /**
61
     * Create a custom response.
62
     */
63
    public function respondWith(Closure $callback): static
×
64
    {
65
        $this->responseResolver = $callback;
×
66

67
        return $this;
×
68
    }
69

70
    /**
71
     * Convert the response to an array.
72
     */
73
    public function toArray(): array
×
74
    {
75
        return array_merge($this->data, [
×
76
            'url' => $this->url,
×
77
        ]);
×
78
    }
79

80
    /**
81
     * Convert the response to an HTTP response.
82
     */
83
    public function toResponse($request): BaseResponse
×
84
    {
85
        if (! is_null($this->responseResolver)) {
×
86
            return call_user_func_array($this->responseResolver, [$this->url, $this->data]);
×
87
        } elseif ($request->wantsJson()) {
×
88
            return new JsonResponse($this->toArray());
×
89
        }
90

91
        return new RedirectResponse($this->url);
×
92
    }
93
}
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