Skip to content

Commit

Permalink
Merge pull request #61 from Dyachenko/update-to-symfony5
Browse files Browse the repository at this point in the history
Update to symfony5
  • Loading branch information
ArturMoczulski authored Feb 15, 2020
2 parents dd39653 + c524404 commit 77624fe
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 108 deletions.
21 changes: 8 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

env:
- SYMFONY_VERSION=3.4.*
- SYMFONY_VERSION=4.0.*
- SYMFONY_VERSION=4.1.*
- SYMFONY_VERSION=5.0.*

sudo: false
dist: trusty
Expand All @@ -20,14 +17,12 @@ cache:

matrix:
exclude:
- php: 5.6
env: SYMFONY_VERSION=4.0.*
- php: 5.6
env: SYMFONY_VERSION=4.1.*
- php: 7.0
env: SYMFONY_VERSION=4.0.*
- php: 7.0
env: SYMFONY_VERSION=4.1.*
- php: 7.1
env: SYMFONY_VERSION=5.0.*
- php: 7.2
env: SYMFONY_VERSION=5.0.*
- php: 7.3
env: SYMFONY_VERSION=5.0.*

before_install:
- composer self-update
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(RollbarExtension::ALIAS);

Expand Down
5 changes: 3 additions & 2 deletions DependencyInjection/RollbarExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class RollbarExtension extends Extension

/**
* {@inheritdoc}
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand All @@ -35,7 +36,7 @@ public function load(array $configs, ContainerBuilder $container)
/**
* {@inheritdoc}
*/
public function getAlias()
public function getAlias(): string
{
return static::ALIAS;
}
Expand Down
31 changes: 14 additions & 17 deletions Factories/RollbarHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,20 @@ public function __construct(ContainerInterface $container)

if (!empty($config['person_fn']) && is_callable($config['person_fn'])) {
$config['person'] = null;
} else {
if (empty($config['person'])) {
$config['person_fn'] = function () use ($container) {
try {
$token = $container->get('security.token_storage')->getToken();

if ($token) {
$user = $token->getUser();
$serializer = $container->get('serializer');
$person = \json_decode($serializer->serialize($user, 'json'), true);
return $person;
}
} catch (\Exception $exception) {
// Ignore
} elseif (empty($config['person'])) {
$config['person_fn'] = static function () use ($container) {
try {
$token = $container->get('security.token_storage')->getToken();

if ($token) {
$user = $token->getUser();
$serializer = $container->get('serializer');
return \json_decode($serializer->serialize($user, 'json'), true);
}
};
}
} catch (\Exception $exception) {
// Ignore
}
};
}

Rollbar::init($config, false, false, false);
Expand All @@ -57,7 +54,7 @@ public function __construct(ContainerInterface $container)
*
* @return RollbarHandler
*/
public function createRollbarHandler()
public function createRollbarHandler(): RollbarHandler
{
return new RollbarHandler(Rollbar::logger(), LogLevel::ERROR);
}
Expand Down
6 changes: 2 additions & 4 deletions Payload/ErrorItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ErrorItem
*/
public function __invoke($code, $message, $file, $line)
{
$record = [
return [
'exception' => [
'class' => $this->mapError($code),
'message' => implode(' ', [
Expand All @@ -65,8 +65,6 @@ public function __invoke($code, $message, $file, $line)
],
],
];

return $record;
}

/**
Expand All @@ -76,7 +74,7 @@ public function __invoke($code, $message, $file, $line)
*
* @return string
*/
protected function mapError($code)
protected function mapError($code): string
{
$code = (int) $code;

Expand Down
18 changes: 9 additions & 9 deletions Payload/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(ContainerInterface $container)
*
* @return array
*/
public function getExceptionPayload($exception)
public function getExceptionPayload($exception): array
{
/**
* Build payload
Expand Down Expand Up @@ -84,7 +84,7 @@ public function getExceptionPayload($exception)
*
* @return array
*/
protected function buildGeneratorError($object, $file, $line)
protected function buildGeneratorError($object, $file, $line): array
{
$item = new ErrorItem();

Expand All @@ -101,7 +101,7 @@ protected function buildGeneratorError($object, $file, $line)
*
* @return array
*/
public function getErrorPayload($code, $message, $file, $line)
public function getErrorPayload($code, $message, $file, $line): array
{
$item = new ErrorItem();

Expand All @@ -110,7 +110,7 @@ public function getErrorPayload($code, $message, $file, $line)
'request' => $this->getRequestInfo(),
'environment' => $this->getKernel()->getEnvironment(),
'framework' => Kernel::VERSION,
'language_version' => phpversion(),
'language_version' => PHP_VERSION,
'server' => $this->getServerInfo(),
];

Expand All @@ -122,7 +122,7 @@ public function getErrorPayload($code, $message, $file, $line)
*
* @return array
*/
protected function getRequestInfo()
protected function getRequestInfo(): array
{
$request = $this->getContainer()->get('request_stack')->getCurrentRequest();
if (empty($request)) {
Expand All @@ -144,9 +144,9 @@ protected function getRequestInfo()
*
* @return array
*/
protected function getServerInfo()
protected function getServerInfo(): array
{
$args = isset($_SERVER['argv']) ? $_SERVER['argv'] : [];
$args = $_SERVER['argv'] ?? [];
$kernel = $this->getKernel();

return [
Expand All @@ -163,7 +163,7 @@ protected function getServerInfo()
*
* @return ContainerInterface
*/
public function getContainer()
public function getContainer(): ContainerInterface
{
return $this->container;
}
Expand All @@ -173,7 +173,7 @@ public function getContainer()
*
* @return Kernel
*/
public function getKernel()
public function getKernel(): Kernel
{
return $this->kernel;
}
Expand Down
4 changes: 1 addition & 3 deletions Payload/TraceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __invoke($throwable)
$frames[] = $frame;
}

$record = [
return [
'exception' => [
'class' => get_class($throwable),
'message' => implode(' ', [
Expand All @@ -59,7 +59,5 @@ public function __invoke($throwable)
],
'frames' => $frames,
];

return $record;
}
}
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

Rollbar full-stack error tracking for Symfony.

Supported Symfony versions: 3+, 4+.

**NOTE 10/08/2018**
The package has been renamed to `rollbar/rollbar-php-symfony-bundle` to reflect support for Symfony 3 and 4. If you have been using the package using the old name (`rollbar/rollbar-php-symfony3-bundle`) make sure to update your `composer.json` to use the new package name.
Supported Symfony versions: 5+.

## Setup Instructions
1. [Sign up for a Rollbar account](https://rollbar.com/signup)
Expand Down
4 changes: 2 additions & 2 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ services:
- '@service_container'

Rollbar\Monolog\Handler\RollbarHandler:
factory: 'Rollbar\Symfony\RollbarBundle\Factories\RollbarHandlerFactory:createRollbarHandler'
factory: ['@Rollbar\Symfony\RollbarBundle\Factories\RollbarHandlerFactory', createRollbarHandler]
tags:
- { name: monolog.logger, channel: rollbar }

Rollbar\Symfony\RollbarBundle\Payload\Generator:
arguments:
- '@service_container'
- '@service_container'
4 changes: 2 additions & 2 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class ConfigurationTest extends KernelTestCase
/**
* Test parameters.
*/
public function testParameters()
public function testParameters(): void
{
static::bootKernel();
$container = isset(static::$container) ? static::$container : static::$kernel->getContainer();
$container = static::$container ?? static::$kernel->getContainer();

$config = $container->getParameter(RollbarExtension::ALIAS . '.config');

Expand Down
10 changes: 5 additions & 5 deletions Tests/DependencyInjection/RollbarExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RollbarExtensionTest extends AbstractExtensionTestCase
*
* @return array
*/
protected function getContainerExtensions()
protected function getContainerExtensions(): array
{
return [
new RollbarExtension(),
Expand All @@ -34,7 +34,7 @@ protected function getContainerExtensions()
* @param string $var
* @param array $expected
*/
public function testConfigEnabledVars($var, $expected)
public function testConfigEnabledVars(string $var, array $expected): void
{
$this->load();

Expand All @@ -50,7 +50,7 @@ public function testConfigEnabledVars($var, $expected)
*
* @return array
*/
public function generatorConfigVars()
public function generatorConfigVars(): array
{
return [
['rollbar.config', ['enabled' => true]],
Expand All @@ -67,7 +67,7 @@ public function generatorConfigVars()
* @param string $var
* @param array $expected
*/
public function testConfigDisabledVars($var, $expected)
public function testConfigDisabledVars(string $var, array $expected): void
{
$this->load(['enabled' => false]);

Expand All @@ -81,7 +81,7 @@ public function testConfigDisabledVars($var, $expected)
/**
* Test alias.
*/
public function testAlias()
public function testAlias(): void
{
$extension = new RollbarExtension();
$this->assertEquals(RollbarExtension::ALIAS, $extension->getAlias());
Expand Down
10 changes: 5 additions & 5 deletions Tests/Fixtures/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ErrorHandler extends AbstractProcessingHandler
*
* @return ErrorHandler
*/
public static function getInstance()
public static function getInstance(): ErrorHandler
{
if (empty(static::$instance)) {
static::$instance = new self(Logger::DEBUG);
Expand All @@ -41,7 +41,7 @@ public static function getInstance()
*
* @param callable $assert
*/
public function setAssert($assert = null)
public function setAssert($assert = null): void
{
$this->assert = $assert;
}
Expand All @@ -53,12 +53,12 @@ public function setAssert($assert = null)
*
* @return void
*/
protected function write(array $record)
protected function write(array $record): void
{
$dummy = function () {
$dummy = static function () {
};

$closure = empty($this->assert) ? $dummy : $this->assert;
call_user_func($closure, $record);
$closure($record);
}
}
Loading

0 comments on commit 77624fe

Please sign in to comment.