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

codeigniter4 / CodeIgniter4 / 12739860967

13 Jan 2025 03:03AM UTC coverage: 84.454%. Remained the same
12739860967

push

github

web-flow
chore: add more trailing commas in more places (#9395)

* Apply to parameters

* Apply to array destructuring

* Apply to match

* Apply for arguments

337 of 397 new or added lines in 117 files covered. (84.89%)

1 existing line in 1 file now uncovered.

20464 of 24231 relevant lines covered (84.45%)

189.67 hits per line

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

79.17
/system/HTTP/Exceptions/RedirectException.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\HTTP\Exceptions;
15

16
use CodeIgniter\Exceptions\HTTPExceptionInterface;
17
use CodeIgniter\HTTP\ResponsableInterface;
18
use CodeIgniter\HTTP\ResponseInterface;
19
use Exception;
20
use InvalidArgumentException;
21
use LogicException;
22
use Throwable;
23

24
/**
25
 * RedirectException
26
 */
27
class RedirectException extends Exception implements ResponsableInterface, HTTPExceptionInterface
28
{
29
    /**
30
     * HTTP status code for redirects
31
     *
32
     * @var int
33
     */
34
    protected $code = 302;
35

36
    protected ?ResponseInterface $response = null;
37

38
    /**
39
     * @param ResponseInterface|string $message Response object or a string containing a relative URI.
40
     * @param int                      $code    HTTP status code to redirect if $message is a string.
41
     */
42
    public function __construct($message = '', int $code = 0, ?Throwable $previous = null)
43
    {
44
        if (! is_string($message) && ! $message instanceof ResponseInterface) {
23✔
45
            throw new InvalidArgumentException(
×
46
                'RedirectException::__construct() first argument must be a string or ResponseInterface',
×
47
                0,
×
NEW
48
                $this,
×
49
            );
×
50
        }
51

52
        if ($message instanceof ResponseInterface) {
23✔
53
            $this->response = $message;
9✔
54
            $message        = '';
9✔
55

56
            if ($this->response->getHeaderLine('Location') === '' && $this->response->getHeaderLine('Refresh') === '') {
9✔
57
                throw new LogicException(
1✔
58
                    'The Response object passed to RedirectException does not contain a redirect address.',
1✔
59
                );
1✔
60
            }
61

62
            if ($this->response->getStatusCode() < 301 || $this->response->getStatusCode() > 308) {
8✔
63
                $this->response->setStatusCode($this->code);
1✔
64
            }
65
        }
66

67
        parent::__construct($message, $code, $previous);
22✔
68
    }
69

70
    public function getResponse(): ResponseInterface
71
    {
72
        if (! $this->response instanceof ResponseInterface) {
14✔
73
            $this->response = service('response')
7✔
74
                ->redirect(base_url($this->getMessage()), 'auto', $this->getCode());
7✔
75
        }
76

77
        service('logger')->info(
14✔
78
            'REDIRECTED ROUTE at '
14✔
79
             . ($this->response->getHeaderLine('Location') ?: substr($this->response->getHeaderLine('Refresh'), 6)),
14✔
80
        );
14✔
81

82
        return $this->response;
14✔
83
    }
84
}
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