Skip to content

Commit 8ee43d2

Browse files
committed
Apply laravel preset coding style
As Ray is written with this
1 parent 1fc9a4f commit 8ee43d2

File tree

4 files changed

+89
-64
lines changed

4 files changed

+89
-64
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2
16+
17+
[docker-compose.yml]
18+
indent_size = 4

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
"email": "[email protected]"
1515
}
1616
],
17-
"require": {}
17+
"require-dev": {
18+
"laravel/pint": "^1.21"
19+
}
1820
}

src/ErrorPayload.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace JMSLBAM\RayPHPErrors;
44

55
// use Spatie\Ray\Origin\DefaultOriginFactory;
6-
use Spatie\Ray\Payloads\Payload;
76
use Spatie\Ray\Origin\Origin;
7+
use Spatie\Ray\Payloads\Payload;
88

99
class ErrorPayload extends Payload
1010
{
@@ -27,7 +27,7 @@ public function __construct(string $content, string $label = '')
2727
$this->label = 'error';
2828

2929
// Sorry ;) mis-using the $label to overwrite the file and fileNumber
30-
$fileAndLineNumber = explode( ':', $label );
30+
$fileAndLineNumber = explode(':', $label);
3131

3232
$this->file = $fileAndLineNumber[0];
3333
$this->lineNumber = $fileAndLineNumber[1];
@@ -38,7 +38,7 @@ public function getType(): string
3838
return 'custom';
3939
}
4040

41-
public function getContent(): array
41+
public function getContent(): array
4242
{
4343
return [
4444
'content' => $this->content,
@@ -55,10 +55,10 @@ public function toArray(): array
5555
];
5656
}
5757

58-
protected function getOrigin(): Origin
58+
protected function getOrigin(): Origin
5959
{
6060
/** @var \Spatie\Ray\Origin\OriginFactory $originFactory */
61-
$originFactory = new self::$originFactoryClass();
61+
$originFactory = new self::$originFactoryClass;
6262

6363
$origin = $originFactory->getOrigin();
6464

src/Ray.php

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,86 @@
22

33
namespace JMSLBAM\RayPHPErrors;
44

5-
class Ray {
5+
class Ray
6+
{
7+
/** @var bool */
8+
private $debug;
69

7-
/** @var bool */
8-
private $debug;
10+
public function init($debug = false)
11+
{
912

10-
public function init( $debug = false ) {
13+
$this->debug = $debug;
1114

12-
$this->debug = $debug;
15+
set_exception_handler([$this, 'setExceptionHandler']); // exception
16+
set_error_handler([$this, 'setErrorHandler']); // error
17+
register_shutdown_function([$this, 'registerShutdownFunction']); // fatal error
18+
}
1319

14-
set_exception_handler( [ $this, 'setExceptionHandler'] ); // exception
15-
set_error_handler( [ $this, 'setErrorHandler'] ); // error
16-
register_shutdown_function( [ $this, 'registerShutdownFunction'] ); // fatal error
17-
}
20+
/**
21+
* Set up error handling
22+
*
23+
* @return void
24+
*/
25+
public function setErrorHandler($errorNumber, $message, $file, $lineNumber)
26+
{
1827

19-
/**
20-
* Set up error handling
21-
*
22-
* @return void
23-
*/
24-
public function setErrorHandler( $errorNumber, $message, $file, $lineNumber ) {
28+
$payload = new ErrorPayload($message, $file.':'.$lineNumber);
2529

26-
$payload = new ErrorPayload($message, $file . ':' . $lineNumber );
30+
$this->sendRequest($message, $file, $lineNumber);
2731

28-
$this->sendRequest( $message, $file, $lineNumber );
32+
if ($this->debug) {
33+
dump($message, $file.':'.$lineNumber);
34+
}
2935

30-
if( $this->debug ) {
31-
dump( $message, $file . ':' . $lineNumber );
32-
}
36+
return false;
37+
}
3338

34-
return false;
35-
}
39+
/**
40+
* Catch fatal errors
41+
*
42+
* @return void
43+
*/
44+
public function registerShutdownFunction()
45+
{
3646

37-
/**
38-
* Catch fatal errors
39-
*
40-
* @return void
41-
*/
42-
public function registerShutdownFunction() {
43-
44-
$error = error_get_last();
47+
$error = error_get_last();
4548

46-
if( is_null( $error ) ) {
47-
return;
48-
}
49+
if (is_null($error)) {
50+
return;
51+
}
4952

50-
$this->sendRequest( $error['message'], $error['file'], $error['line'] );
53+
$this->sendRequest($error['message'], $error['file'], $error['line']);
5154

52-
if( $this->debug ) {
53-
dump( $error );
54-
}
55-
}
55+
if ($this->debug) {
56+
dump($error);
57+
}
58+
}
5659

57-
/**
58-
* Catch exceptions
59-
*
60-
* @return void
61-
*/
62-
public function setExceptionHandler( $exception ) {
60+
/**
61+
* Catch exceptions
62+
*
63+
* @return void
64+
*/
65+
public function setExceptionHandler($exception)
66+
{
6367

64-
$this->sendRequest( $exception->getMessage(), $exception->getFile(), $exception->getLine() );
68+
$this->sendRequest($exception->getMessage(), $exception->getFile(), $exception->getLine());
6569

66-
if( $this->debug ) {
67-
dump( $exception );
68-
}
69-
}
70+
if ($this->debug) {
71+
dump($exception);
72+
}
73+
}
7074

71-
private function sendRequest( $message, $file, $lineNumber, $color = 'red' ) {
75+
private function sendRequest($message, $file, $lineNumber, $color = 'red')
76+
{
7277

73-
$payload = new ErrorPayload($message, $file . ':' . $lineNumber );
74-
75-
ray()->sendRequest( $payload )->color( $color );
78+
$payload = new ErrorPayload($message, $file.':'.$lineNumber);
7679

77-
// Sprinkle a little WordPress Query Monitor here so that still shows the errors
78-
if( function_exists('do_action') ) {
79-
do_action( 'qm/error', $message );
80-
}
81-
}
80+
ray()->sendRequest($payload)->color($color);
81+
82+
// Sprinkle a little WordPress Query Monitor here so that still shows the errors
83+
if (function_exists('do_action')) {
84+
do_action('qm/error', $message);
85+
}
86+
}
8287
}

0 commit comments

Comments
 (0)