Skip to content

Commit

Permalink
Refactor the whole source code to support the Unified API (getsentry#682
Browse files Browse the repository at this point in the history
)
  • Loading branch information
HazAT authored and ste93cry committed Nov 16, 2018
1 parent 3c75bc0 commit fdb12a1
Show file tree
Hide file tree
Showing 87 changed files with 1,438 additions and 4,663 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: test
gc -am .PHONY: test

develop: update-submodules
composer install --dev
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ parameters:
- src
- tests
ignoreErrors:
- '/Constructor of class Sentry\\HttpClient\\Encoding\\Base64EncodingStream has an unused parameter \$(readFilterOptions|writeFilterOptions)/'
- '/Call to an undefined method Sentry\\ClientBuilder::methodThatDoesNotExists\(\)/'
- '/Argument of an invalid type object supplied for foreach, only iterables are supported/'
- '/Binary operation "\*" between array and 2 results in an error\./'
- '/Method Sentry\\ClientBuilder::\w+\(\) should return \$this\(Sentry\\ClientBuilderInterface\) but returns \$this\(Sentry\\ClientBuilder\)\./'
- '/Parameter #1 \$values of class Sentry\\TransactionStack constructor expects array<string>, array<int, stdClass\|string> given\./'
# to be removed with serializer refactoring
- '/Parameter #1 \$data of method Sentry\\Context\\\w*Context::replaceData\(\) expects array, array\|bool\|float\|int\|object\|string\|null given\./'
excludes_analyse:
- tests/resources
includes:
Expand Down
32 changes: 18 additions & 14 deletions src/AbstractErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
abstract class AbstractErrorHandler
{
/**
* @var ClientInterface The Raven client
* @var callable Callback that will be invoked when an error is caught
*/
protected $client;
protected $callback;

/**
* @var \ReflectionProperty A reflection cached instance that points to the
Expand Down Expand Up @@ -80,16 +80,18 @@ abstract class AbstractErrorHandler
/**
* Constructor.
*
* @param ClientInterface $client The Raven client
* @param int $reservedMemorySize The amount of memory to reserve for the fatal error handler
* @param callable $callback The callback that will be invoked in case an error is caught
* @param int $reservedMemorySize The amount of memory to reserve for the fatal error handler
*
* @throws \ReflectionException
*/
protected function __construct(ClientInterface $client, $reservedMemorySize = 10240)
protected function __construct(callable $callback, int $reservedMemorySize = 10240)
{
if (!\is_int($reservedMemorySize) || $reservedMemorySize <= 0) {
throw new \UnexpectedValueException('The value of the $reservedMemorySize argument must be an integer greater than 0.');
}

$this->client = $client;
$this->callback = $callback;
$this->exceptionReflection = new \ReflectionProperty(\Exception::class, 'trace');
$this->exceptionReflection->setAccessible(true);

Expand All @@ -104,7 +106,7 @@ protected function __construct(ClientInterface $client, $reservedMemorySize = 10
if (null === $this->previousErrorHandler) {
restore_error_handler();

// Specifying the error types catched by the error handler with the
// Specifying the error types caught by the error handler with the
// first call to the set_error_handler method would cause the PHP
// bug https://bugs.php.net/63206 if the handler is not the first
// one
Expand Down Expand Up @@ -152,6 +154,8 @@ public function captureAt($levels, $replace = false)
*
* @return bool If the function returns FALSE then the normal error handler continues
*
* @throws \Throwable
*
* @internal
*/
public function handleError($level, $message, $file, $line)
Expand All @@ -169,8 +173,8 @@ public function handleError($level, $message, $file, $line)

try {
$this->handleException($errorAsException);
} catch (\Exception $exception) {
// Do nothing as this error handler should be as trasparent as possible
} catch (\Throwable $exception) {
// Do nothing as this error handler should be as transparent as possible
}

if (null !== $this->previousErrorHandler) {
Expand Down Expand Up @@ -211,7 +215,7 @@ public function handleFatalError(array $error = null)
if (null !== $errorAsException) {
$this->handleException($errorAsException);
}
} catch (\ErrorException $errorAsException) {
} catch (\Throwable $errorAsException) {
// Ignore this re-throw
}
}
Expand All @@ -220,9 +224,9 @@ public function handleFatalError(array $error = null)
* Handles the given exception by capturing it through the Raven client and
* then forwarding it to another handler.
*
* @param \Exception|\Throwable $exception The exception to handle
* @param \Throwable $exception The exception to handle
*
* @throws \Exception|\Throwable
* @throws \Throwable
*
* @internal
*/
Expand Down Expand Up @@ -320,9 +324,9 @@ protected function cleanBacktraceFromErrorHandlerFrames($backtrace, $file, $line
* Handles the given exception. This method can be overridden to customize
* the logging of an exception.
*
* @param \Exception|\Throwable $exception The exception to handle
* @param \Throwable $exception The exception to handle
*
* @throws \Exception|\Throwable
* @throws \Throwable
*/
abstract protected function doHandleException($exception);
}
93 changes: 0 additions & 93 deletions src/BreadcrumbErrorHandler.php

This file was deleted.

35 changes: 35 additions & 0 deletions src/Breadcrumbs/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,41 @@ public static function create($level, $type, $category, $message = null, array $
return new static($level, $type, $category, $message, $metadata);
}

/**
* Maps the severity of the error to one of the levels supported by the
* breadcrumbs.
*
* @param \ErrorException $exception The exception
*
* @return string
*/
public static function levelFromErrorException(\ErrorException $exception): string
{
switch ($exception->getSeverity()) {
case E_DEPRECATED:
case E_USER_DEPRECATED:
case E_WARNING:
case E_USER_WARNING:
case E_RECOVERABLE_ERROR:
return self::LEVEL_WARNING;
case E_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_CORE_WARNING:
case E_COMPILE_ERROR:
case E_COMPILE_WARNING:
return self::LEVEL_CRITICAL;
case E_USER_ERROR:
return self::LEVEL_ERROR;
case E_NOTICE:
case E_USER_NOTICE:
case E_STRICT:
return self::LEVEL_INFO;
default:
return self::LEVEL_ERROR;
}
}

/**
* Gets the breadcrumb type.
*
Expand Down
Loading

0 comments on commit fdb12a1

Please sign in to comment.