Passed
Branch dev (a860f8)
by Alan
02:15
created

OutputSentException::onFileLine()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace FigTree\Exceptions;
4
5
use Throwable;
6
use LogicException;
7
use FigTree\Exceptions\Contracts\{
8
	SevereExceptionInterface,
9
	LocatableExceptionInterface,
10
};
11
use FigTree\Exceptions\Concerns\HasSeverity;
12
13
/**
14
 * Exception thrown when output has already been sent when attempting to emit an HTTP header.
15
 */
16
class OutputSentException extends LogicException implements SevereExceptionInterface, LocatableExceptionInterface
17
{
18
	use HasSeverity;
19
20
	/**
21
	 * Exception thrown when output has already been sent when attempting to emit an HTTP header.
22
	 *
23
	 * @param int $code The Exception code.
24
	 * @param \Throwable $previous The previous throwable used for the exception chaining.
25
	 */
26
	public function __construct(int $code = 0, Throwable $previous = null)
27
	{
28
		$message = 'Output already sent.';
29
30
		parent::__construct($message, $code, $previous);
31
	}
32
33
	/**
34
	 * If required, set the file and line where the Exception was thrown.
35
	 *
36
	 * @param string $file
37
	 * @param int $line
38
	 *
39
	 * @return $this
40
	 */
41
	public function onFileLine(string $file, int $line): LocatableExceptionInterface
42
	{
43
		if (file_exists($file)) {
44
			$this->file = $file;
45
			$this->line = max(0, $line);
46
		}
47
48
		return $this;
49
	}
50
}
51