Skip to content

Commit

Permalink
Merge pull request #90 from getsentry/prepare-release-2.0
Browse files Browse the repository at this point in the history
Prepare release 2.0
  • Loading branch information
Jean85 authored Dec 12, 2017
2 parents 3947a83 + 3aaa5af commit 3e94025
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 239 deletions.
22 changes: 8 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ sudo: false
dist: trusty

php:
- 5.6
- 7.0
- 7.1
- 7.2

Expand All @@ -13,33 +11,29 @@ cache:
- $HOME/.composer/cache/files

before_install:
- phpenv config-rm xdebug.ini
- composer self-update
- composer global require hirak/prestissimo

install: travis_wait travis_retry composer update --no-interaction --prefer-dist --prefer-stable $COMPOSER_OPTIONS
install:
- travis_wait travis_retry composer update --no-interaction --prefer-dist --prefer-stable $COMPOSER_OPTIONS

script:
- vendor/bin/phpunit -v

jobs:
include:
- stage: test
php: 5.6
env: COMPOSER_OPTIONS="--prefer-lowest"
- stage: Test
php: 7.0
env: COMPOSER_OPTIONS="--prefer-lowest"
- stage: codestyle and SCA
php: 7.1
env: COMPOSER_OPTIONS="--prefer-lowest"
- stage: Code style and static analysis
script:
- phpenv config-rm xdebug.ini
- composer require --dev phpstan/phpstan symfony/expression-language --no-interaction --prefer-dist --prefer-stable
- vendor/bin/phpstan analyse src --level 7
- composer phpstan
env: PHPSTAN=true
- script: vendor/bin/php-cs-fixer fix --verbose --diff --dry-run
- script:
- composer cs-check
env: CS-FIXER=true
- stage: coverage
php: 7.1
script:
- phpdbg -qrr vendor/bin/phpunit --coverage-clover clover.xml
after_success:
Expand Down
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## 1.0.0 - [Unreleased]
## 2.0.0 - [Unreleased]
### Added
- Add support for Symfony 4.x
### Changed
- The `SentryBundle::VERSION` constant has been replaced with the `SentryBundle::getVersion(): string` method, to get a more accurate result
- Due to a deprecation in `symfony/console`, we require it at at least version 3.3, and we added a method to `SentryExceptionListenerInterface`:
```php
public function onConsoleException(ConsoleErrorEvent $event);
```
### Removed
- Drop support for Symfony 2.x
- Drop support for PHP 5 and 7.0

## 1.0.0 - 2017-11-07
### Added
- Add official support to PHP 7.2 (#71)
### Changed
Expand Down
35 changes: 23 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@
"sort-packages": true
},
"require": {
"php": "^5.6|^7.0",
"php": "^7.1",
"jean85/pretty-package-versions": "^1.0",
"sentry/sentry": "^1.8",
"symfony/config": "^2.7|^3.0",
"symfony/console": "^2.7|^3.0",
"symfony/dependency-injection": "^2.7|^3.0",
"symfony/event-dispatcher": "^2.7|^3.0",
"symfony/http-kernel": "^2.7|^3.0",
"symfony/security-core": "^2.7|^3.0",
"symfony/yaml": "^2.7|^3.0"
"symfony/config": "^3.0||^4.0",
"symfony/console": "^3.3||^4.0",
"symfony/dependency-injection": "^3.0||^4.0",
"symfony/event-dispatcher": "^3.0||^4.0",
"symfony/http-kernel": "^3.0||^4.0",
"symfony/security-core": "^3.0||^4.0",
"symfony/yaml": "^3.0||^4.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.5",
"phpunit/phpunit": "^5.7|^6.0",
"scrutinizer/ocular": "^1.4"
"friendsofphp/php-cs-fixer": "^2.8",
"phpstan/phpstan": "^0.9.1",
"phpstan/phpstan-phpunit": "^0.9.1",
"phpunit/phpunit": "^6.5",
"scrutinizer/ocular": "^1.4",
"symfony/expression-language": "^3.0||^4.0"
},
"autoload": {
"psr-4" : {
Expand All @@ -44,9 +48,16 @@
"Sentry\\SentryBundle\\Test\\": "test"
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse src test --level 7 -c phpstan.neon",
"cs-check": "vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
"cs-fix": "vendor/bin/php-cs-fixer fix --verbose --diff"
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"master": "2.0.x-dev",
"releases/0.8.x": "0.8.x-dev",
"releases/1.x": "1.0.x-dev"
}
}
}
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
- '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::/'
- '/Calling method \w+ on possibly null value of type Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface|null/'
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
12 changes: 4 additions & 8 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Sentry\SentryBundle\EventListener\ExceptionListener;
use Sentry\SentryBundle\EventListener\SentryExceptionListenerInterface;
use Sentry\SentryBundle\SentrySymfonyClient;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
Expand All @@ -25,6 +26,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->root('sentry');

// Basic Sentry configuration
Expand Down Expand Up @@ -138,10 +140,7 @@ public function getConfigTreeBuilder()
return $treeBuilder;
}

/**
* @return \Closure
*/
private function getExceptionListenerInvalidationClosure()
private function getExceptionListenerInvalidationClosure(): callable
{
return function ($value) {
$implements = class_implements($value);
Expand All @@ -153,10 +152,7 @@ private function getExceptionListenerInvalidationClosure()
};
}

/**
* @return \Closure
*/
private function getTrimClosure()
private function getTrimClosure(): callable
{
return function ($str) {
$value = trim($str);
Expand Down
13 changes: 8 additions & 5 deletions src/ErrorTypesParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
*/
class ErrorTypesParser
{
private $expression = null;
/** @var string */
private $expression;

/**
* Initialize ErrorParser
*
* @param string $expression Error Types e.g. E_ALL & ~E_DEPRECATED & ~E_NOTICE
*/
public function __construct($expression)
public function __construct(string $expression)
{
$this->expression = $expression;
}
Expand All @@ -23,8 +24,9 @@ public function __construct($expression)
* Parse and compute the error types expression
*
* @return int the parsed expression
* @throws \InvalidArgumentException
*/
public function parse()
public function parse(): int
{
// convert constants to ints
$this->expression = $this->convertErrorConstants($this->expression);
Expand All @@ -43,7 +45,7 @@ public function parse()
* @param string $expression e.g. E_ALL & ~E_DEPRECATED & ~E_NOTICE
* @return string converted expression e.g. 32767 & ~8192 & ~8
*/
private function convertErrorConstants($expression)
private function convertErrorConstants(string $expression): string
{
$output = preg_replace_callback('/(E_[a-zA-Z_]+)/', function ($errorConstant) {
if (defined($errorConstant[1])) {
Expand All @@ -61,8 +63,9 @@ private function convertErrorConstants($expression)
*
* @param string $expression prepared expression e.g. 32767&~8192&~8
* @return int computed expression e.g. 24567
* @throws \InvalidArgumentException
*/
private function compute($expression)
private function compute(string $expression): int
{
// catch anything which could be a security issue
if (0 !== preg_match("/[^\d.+*%^|&~<>\/()-]/", $this->expression)) {
Expand Down
3 changes: 2 additions & 1 deletion src/Event/SentryUserContextEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

class SentryUserContextEvent extends Event
{
/** @var TokenInterface */
private $authenticationToken;

public function __construct(TokenInterface $authenticationToken)
{
$this->authenticationToken = $authenticationToken;
}

public function getAuthenticationToken()
public function getAuthenticationToken(): TokenInterface
{
return $this->authenticationToken;
}
Expand Down
37 changes: 29 additions & 8 deletions src/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Sentry\SentryBundle\Event\SentryUserContextEvent;
use Sentry\SentryBundle\SentrySymfonyEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Event\ConsoleEvent;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
Expand Down Expand Up @@ -71,7 +73,7 @@ public function setClient(\Raven_Client $client)
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(GetResponseEvent $event): void
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
Expand All @@ -94,7 +96,7 @@ public function onKernelRequest(GetResponseEvent $event)
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
public function onKernelException(GetResponseForExceptionEvent $event): void
{
$exception = $event->getException();

Expand All @@ -114,18 +116,37 @@ public function onKernelException(GetResponseForExceptionEvent $event)
*
* @return void
*/
public function onConsoleCommand(ConsoleCommandEvent $event)
public function onConsoleCommand(ConsoleCommandEvent $event): void
{
// only triggers loading of client, does not need to do anything.
}

public function onConsoleError(ConsoleErrorEvent $event): void
{
$this->handleConsoleError($event);
}

public function onConsoleException(ConsoleExceptionEvent $event): void
{
$this->handleConsoleError($event);
}

/**
* @param ConsoleExceptionEvent $event
* @param ConsoleExceptionEvent|ConsoleErrorEvent $event
*/
public function onConsoleException(ConsoleExceptionEvent $event)
private function handleConsoleError(ConsoleEvent $event): void
{
$command = $event->getCommand();
$exception = $event->getException();
switch (true) {
case $event instanceof ConsoleErrorEvent:
$exception = $event->getError();
break;
case $event instanceof ConsoleExceptionEvent:
$exception = $event->getException();
break;
default:
throw new \InvalidArgumentException('Event not recognized: ' . \get_class($event));
}

if ($this->shouldExceptionCaptureBeSkipped($exception)) {
return;
Expand All @@ -142,7 +163,7 @@ public function onConsoleException(ConsoleExceptionEvent $event)
$this->client->captureException($exception, $data);
}

protected function shouldExceptionCaptureBeSkipped(\Exception $exception)
protected function shouldExceptionCaptureBeSkipped(\Throwable $exception): bool
{
foreach ($this->skipCapture as $className) {
if ($exception instanceof $className) {
Expand Down Expand Up @@ -171,7 +192,7 @@ private function setUserValue($user)
}

if (is_object($user) && method_exists($user, '__toString')) {
$this->client->set_user_data($user->__toString());
$this->client->set_user_data((string)$user);
}
}
}
16 changes: 13 additions & 3 deletions src/EventListener/SentryExceptionListenerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sentry\SentryBundle\EventListener;

use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
Expand All @@ -17,21 +18,30 @@ interface SentryExceptionListenerInterface
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event);
public function onKernelRequest(GetResponseEvent $event): void;

/**
* When an exception occurs as part of a web request, this method will be
* triggered for capturing the error.
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event);
public function onKernelException(GetResponseForExceptionEvent $event): void;

/**
* When an exception occurs on the command line, this method will be
* triggered for capturing the error.
*
* @param ConsoleErrorEvent $event
*/
public function onConsoleError(ConsoleErrorEvent $event): void;

/**
* When an exception occurs on the command line, this method will be
* triggered for capturing the error.
*
* @param ConsoleExceptionEvent $event
* @deprecated This method exists for BC with Symfony 3.x
*/
public function onConsoleException(ConsoleExceptionEvent $event);
public function onConsoleException(ConsoleExceptionEvent $event): void;
}
Loading

0 comments on commit 3e94025

Please sign in to comment.