Skip to content

Commit 8d98583

Browse files
code reformat
1 parent c3347bc commit 8d98583

File tree

5 files changed

+109
-93
lines changed

5 files changed

+109
-93
lines changed

src/ZendSentry/Log/Writer/Sentry.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@
2020
*/
2121
class Sentry extends AbstractWriter
2222
{
23+
protected $raven;
2324
/**
2425
* Translates Zend Framework log levels to Raven log levels.
2526
*/
2627
private $logLevels = [
27-
'DEBUG' => Raven::DEBUG,
28-
'INFO' => Raven::INFO,
29-
'NOTICE' => Raven::INFO,
30-
'WARN' => Raven::WARNING,
31-
'ERR' => Raven::ERROR,
32-
'CRIT' => Raven::FATAL,
33-
'ALERT' => Raven::FATAL,
34-
'EMERG' => Raven::FATAL,
28+
'DEBUG' => Raven::DEBUG,
29+
'INFO' => Raven::INFO,
30+
'NOTICE' => Raven::INFO,
31+
'WARN' => Raven::WARNING,
32+
'ERR' => Raven::ERROR,
33+
'CRIT' => Raven::FATAL,
34+
'ALERT' => Raven::FATAL,
35+
'EMERG' => Raven::FATAL,
3536
];
3637

37-
protected $raven;
38-
3938
/**
4039
* Sentry constructor.
4140
*
@@ -52,13 +51,14 @@ public function __construct(Raven $raven, $options = null)
5251
* Write a message to the log
5352
*
5453
* @param array $event log data event
54+
*
5555
* @return string $eventID the event ID
5656
*/
5757
protected function doWrite(array $event): string
5858
{
59-
$extra = [];
59+
$extra = [];
6060
$extra['timestamp'] = $event['timestamp'];
61-
$eventID = $this->raven->captureMessage($event['message'], [], $this->logLevels[$event['priorityName']], false, $event['extra']);
61+
$eventID = $this->raven->captureMessage($event['message'], [], $this->logLevels[$event['priorityName']], false, $event['extra']);
6262

6363
return $eventID;
6464
}

src/ZendSentry/Mvc/View/Console/ExceptionStrategy.php

+22-14
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ class ExceptionStrategy extends AbstractListenerAggregate
2929
{
3030
/**
3131
* Display exceptions?
32+
*
3233
* @var bool
3334
*/
3435
protected $displayExceptions = false;
3536

3637
/**
3738
* Default Exception Message
39+
*
3840
* @var string
3941
*/
4042
protected $defaultExceptionMessage = "Oh no. Something went wrong, but we have been notified.\n";
4143

4244
/**
4345
* A template for message to show in console when an exception has occurred.
46+
*
4447
* @var string|callable
4548
*/
4649
protected $message = <<<EOT
@@ -72,11 +75,12 @@ public function attach(EventManagerInterface $events, $priority = 1)
7275
* Flag: display exceptions in error pages?
7376
*
7477
* @param bool $displayExceptions
78+
*
7579
* @return ExceptionStrategy
7680
*/
7781
public function setDisplayExceptions($displayExceptions): ExceptionStrategy
7882
{
79-
$this->displayExceptions = (bool) $displayExceptions;
83+
$this->displayExceptions = (bool)$displayExceptions;
8084
return $this;
8185
}
8286

@@ -100,17 +104,6 @@ public function getMessage(): string
100104
return $this->message;
101105
}
102106

103-
/**
104-
* Set the default exception message
105-
* @param string $defaultExceptionMessage
106-
* @return self
107-
*/
108-
public function setDefaultExceptionMessage($defaultExceptionMessage): self
109-
{
110-
$this->defaultExceptionMessage = $defaultExceptionMessage;
111-
return $this;
112-
}
113-
114107
/**
115108
* Set template for message that will be shown in Console.
116109
* The message can be a string (template) or a callable (i.e. a closure).
@@ -128,7 +121,8 @@ public function setDefaultExceptionMessage($defaultExceptionMessage): self
128121
* :line - the line where the exception has been thrown
129122
* :stack - full exception stack
130123
*
131-
* @param string|callable $message
124+
* @param string|callable $message
125+
*
132126
* @return ExceptionStrategy
133127
*/
134128
public function setMessage($message): ExceptionStrategy
@@ -137,10 +131,24 @@ public function setMessage($message): ExceptionStrategy
137131
return $this;
138132
}
139133

134+
/**
135+
* Set the default exception message
136+
*
137+
* @param string $defaultExceptionMessage
138+
*
139+
* @return self
140+
*/
141+
public function setDefaultExceptionMessage($defaultExceptionMessage): self
142+
{
143+
$this->defaultExceptionMessage = $defaultExceptionMessage;
144+
return $this;
145+
}
146+
140147
/**
141148
* Create an exception view model, and set the console status code
142149
*
143150
* @param MvcEvent $e
151+
*
144152
* @return void
145153
*/
146154
public function prepareExceptionViewModel(MvcEvent $e)
@@ -175,7 +183,7 @@ public function prepareExceptionViewModel(MvcEvent $e)
175183

176184
if (\is_callable($this->message)) {
177185
$callback = $this->message;
178-
$message = (string) $callback($exception, $this->displayExceptions);
186+
$message = (string)$callback($exception, $this->displayExceptions);
179187
} elseif ($this->displayExceptions && $exception instanceof \Exception) {
180188
/* @var $exception \Exception */
181189
$message = str_replace(

src/ZendSentry/Mvc/View/Http/ExceptionStrategy.php

+44-36
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@ class ExceptionStrategy extends AbstractListenerAggregate
3030
{
3131
/**
3232
* Display exceptions?
33+
*
3334
* @var bool
3435
*/
3536
protected $displayExceptions = false;
3637

3738
/**
3839
* Default Exception Message
40+
*
3941
* @var string
4042
*/
4143
protected $defaultExceptionMessage = 'Oh no. Something went wrong, but we have been notified. If you are testing, tell us your eventID: %s';
4244

4345
/**
4446
* Name of exception template
47+
*
4548
* @var string
4649
*/
4750
protected $exceptionTemplate = 'error';
@@ -59,27 +62,20 @@ public function attach(EventManagerInterface $events, $priority = 1)
5962
* Flag: display exceptions in error pages?
6063
*
6164
* @param bool $displayExceptions
65+
*
6266
* @return ExceptionStrategy
6367
*/
6468
public function setDisplayExceptions($displayExceptions): ExceptionStrategy
6569
{
66-
$this->displayExceptions = (bool) $displayExceptions;
70+
$this->displayExceptions = (bool)$displayExceptions;
6771
return $this;
6872
}
6973

70-
/**
71-
* Should we display exceptions in error pages?
72-
*
73-
* @return bool
74-
*/
75-
public function displayExceptions(): bool
76-
{
77-
return $this->displayExceptions;
78-
}
79-
8074
/**
8175
* Set the default exception message
76+
*
8277
* @param string $defaultExceptionMessage
78+
*
8379
* @return self
8480
*/
8581
public function setDefaultExceptionMessage($defaultExceptionMessage): self
@@ -88,32 +84,11 @@ public function setDefaultExceptionMessage($defaultExceptionMessage): self
8884
return $this;
8985
}
9086

91-
/**
92-
* Set the exception template
93-
*
94-
* @param string $exceptionTemplate
95-
* @return ExceptionStrategy
96-
*/
97-
public function setExceptionTemplate($exceptionTemplate): ExceptionStrategy
98-
{
99-
$this->exceptionTemplate = (string) $exceptionTemplate;
100-
return $this;
101-
}
102-
103-
/**
104-
* Retrieve the exception template
105-
*
106-
* @return string
107-
*/
108-
public function getExceptionTemplate(): string
109-
{
110-
return $this->exceptionTemplate;
111-
}
112-
11387
/**
11488
* Create an exception view model, and set the HTTP status code
11589
*
11690
* @param MvcEvent $e
91+
*
11792
* @return void
11893
*/
11994
public function prepareExceptionViewModel(MvcEvent $e)
@@ -152,9 +127,9 @@ public function prepareExceptionViewModel(MvcEvent $e)
152127

153128
$model = new ViewModel(
154129
[
155-
'message' => sprintf($this->defaultExceptionMessage, $eventID->last()),
156-
'exception' => $e->getParam('exception'),
157-
'display_exceptions' => $this->displayExceptions(),
130+
'message' => sprintf($this->defaultExceptionMessage, $eventID->last()),
131+
'exception' => $e->getParam('exception'),
132+
'display_exceptions' => $this->displayExceptions(),
158133
]
159134
);
160135
$model->setTemplate($this->getExceptionTemplate());
@@ -176,4 +151,37 @@ public function prepareExceptionViewModel(MvcEvent $e)
176151
break;
177152
}
178153
}
154+
155+
/**
156+
* Should we display exceptions in error pages?
157+
*
158+
* @return bool
159+
*/
160+
public function displayExceptions(): bool
161+
{
162+
return $this->displayExceptions;
163+
}
164+
165+
/**
166+
* Retrieve the exception template
167+
*
168+
* @return string
169+
*/
170+
public function getExceptionTemplate(): string
171+
{
172+
return $this->exceptionTemplate;
173+
}
174+
175+
/**
176+
* Set the exception template
177+
*
178+
* @param string $exceptionTemplate
179+
*
180+
* @return ExceptionStrategy
181+
*/
182+
public function setExceptionTemplate($exceptionTemplate): ExceptionStrategy
183+
{
184+
$this->exceptionTemplate = (string)$exceptionTemplate;
185+
return $this;
186+
}
179187
}

src/ZendSentry/ZendSentry.php

+29-29
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,21 @@
2020
*/
2121
class ZendSentry
2222
{
23+
/**
24+
* @var string $nonce
25+
*/
26+
private static $nonce;
2327
/**
2428
* @var RavenClient $ravenClient
2529
*/
2630
private $ravenClient;
27-
2831
/**
2932
* @var RavenErrorHandler $ravenErrorHandler
3033
*/
3134
private $ravenErrorHandler;
3235

3336
/**
34-
* @var string $nonce
35-
*/
36-
private static $nonce;
37-
38-
/**
39-
* @param RavenClient $ravenClient
37+
* @param RavenClient $ravenClient
4038
* @param RavenErrorHandler $ravenErrorHandler
4139
*/
4240
public function __construct(RavenClient $ravenClient, RavenErrorHandler $ravenErrorHandler = null)
@@ -46,8 +44,28 @@ public function __construct(RavenClient $ravenClient, RavenErrorHandler $ravenEr
4644
}
4745

4846
/**
49-
* @param bool $callExistingHandler
50-
* @param int $errorReporting
47+
* @param null|RavenErrorHandler $ravenErrorHandler
48+
*/
49+
private function setOrLoadRavenErrorHandler($ravenErrorHandler)
50+
{
51+
if ($ravenErrorHandler !== null) {
52+
$this->ravenErrorHandler = $ravenErrorHandler;
53+
} else {
54+
$this->ravenErrorHandler = new RavenErrorHandler($this->ravenClient);
55+
}
56+
}
57+
58+
/**
59+
* @param string $nonce
60+
*/
61+
public static function setCSPNonce(string $nonce)
62+
{
63+
self::$nonce = $nonce;
64+
}
65+
66+
/**
67+
* @param bool $callExistingHandler
68+
* @param int $errorReporting
5169
*
5270
* @return ZendSentry
5371
*/
@@ -59,6 +77,7 @@ public function registerErrorHandler($callExistingHandler = true, $errorReportin
5977

6078
/**
6179
* @param bool $callExistingHandler
80+
*
6281
* @return ZendSentry
6382
*/
6483
public function registerExceptionHandler($callExistingHandler = true): ZendSentry
@@ -69,6 +88,7 @@ public function registerExceptionHandler($callExistingHandler = true): ZendSentr
6988

7089
/**
7190
* @param int $reservedMemorySize
91+
*
7292
* @return ZendSentry
7393
*/
7494
public function registerShutdownFunction($reservedMemorySize = 10): ZendSentry
@@ -77,26 +97,6 @@ public function registerShutdownFunction($reservedMemorySize = 10): ZendSentry
7797
return $this;
7898
}
7999

80-
/**
81-
* @param null|RavenErrorHandler $ravenErrorHandler
82-
*/
83-
private function setOrLoadRavenErrorHandler($ravenErrorHandler)
84-
{
85-
if ($ravenErrorHandler !== null) {
86-
$this->ravenErrorHandler = $ravenErrorHandler;
87-
} else {
88-
$this->ravenErrorHandler = new RavenErrorHandler($this->ravenClient);
89-
}
90-
}
91-
92-
/**
93-
* @param string $nonce
94-
*/
95-
public static function setCSPNonce(string $nonce)
96-
{
97-
self::$nonce = $nonce;
98-
}
99-
100100
/**
101101
* @return null|string
102102
*/

0 commit comments

Comments
 (0)