Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ cs:
cs-dry-run:
vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --diff --dry-run

test: cs-dry-run
vendor/bin/phpunit
cs-fix:
vendor/bin/php-cs-fixer fix --config=.php_cs

phpstan:
vendor/bin/phpstan analyse src tests -c phpstan.neon -l 7

test: cs-fix phpstan
vendor/bin/phpunit --verbose

setup-git:
git config branch.autosetuprebase always
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@
"bin/sentry"
],
"autoload": {
"files": ["src/Sdk.php"],
"psr-4" : {
"Sentry\\" : "src/"
}
},
"autoload-dev": {
"files": ["src/Sdk.php"],
"psr-4": {
"Sentry\\Tests\\": "tests/"
}
Expand Down
5 changes: 3 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sentry\Context\RuntimeContext;
use Sentry\Context\ServerOsContext;
use Sentry\Context\TagsContext;
use Sentry\Context\UserContext;
use Sentry\Middleware\MiddlewareStack;
use Sentry\Transport\TransportInterface;
use Zend\Diactoros\ServerRequestFactory;
Expand Down Expand Up @@ -99,7 +100,7 @@ class Client implements ClientInterface
private $tagsContext;

/**
* @var Context The user context
* @var UserContext The user context
*/
private $userContext;

Expand Down Expand Up @@ -139,7 +140,7 @@ public function __construct(Configuration $config, TransportInterface $transport
$this->config = $config;
$this->transport = $transport;
$this->tagsContext = new TagsContext();
$this->userContext = new Context();
$this->userContext = new UserContext();
$this->extraContext = new Context();
$this->runtimeContext = new RuntimeContext();
$this->serverOsContext = new ServerOsContext();
Expand Down
4 changes: 2 additions & 2 deletions src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function __construct(array $options = [])
/**
* {@inheritdoc}
*/
public static function create(array $options = [])
public static function create(array $options = []): self
{
return new static($options);
}
Expand Down Expand Up @@ -240,7 +240,7 @@ public function getMiddlewares()
/**
* {@inheritdoc}
*/
public function getClient()
public function getClient(): Client
{
$this->messageFactory = $this->messageFactory ?? MessageFactoryDiscovery::find();
$this->uriFactory = $this->uriFactory ?? UriFactoryDiscovery::find();
Expand Down
4 changes: 2 additions & 2 deletions src/ClientBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getMiddlewares();
/**
* Gets the instance of the client built using the configured options.
*
* @return ClientInterface
* @return Client
*/
public function getClient();
public function getClient(): Client;
}
99 changes: 99 additions & 0 deletions src/Context/OptionsResolverContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Sentry\Context;

use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
use Symfony\Component\OptionsResolver\OptionsResolver;

abstract class OptionsResolverContext extends Context
{
/**
* @var OptionsResolver The options resolver
*/
protected $resolver;

/**
* {@inheritdoc}
*
* @throws UndefinedOptionsException If any of the options are not supported
* by the context
* @throws InvalidOptionsException If any of the options don't fulfill the
* specified validation rules
*/
public function __construct(array $data = [])
{
$this->resolver = new OptionsResolver();

$this->configureOptions($this->resolver);

parent::__construct($this->resolver->resolve($data));
}

/**
* {@inheritdoc}
*
* @throws UndefinedOptionsException If any of the options are not supported
* by the context
* @throws InvalidOptionsException If any of the options don't fulfill the
* specified validation rules
*/
public function merge(array $data, $recursive = false)
{
$data = $this->resolver->resolve($data);

parent::merge($data, $recursive);
}

/**
* {@inheritdoc}
*
* @throws UndefinedOptionsException If any of the options are not supported
* by the context
* @throws InvalidOptionsException If any of the options don't fulfill the
* specified validation rules
*/
public function setData(array $data)
{
$data = $this->resolver->resolve($data);

parent::setData($data);
}

/**
* {@inheritdoc}
*
* @throws UndefinedOptionsException If any of the options are not supported
* by the context
* @throws InvalidOptionsException If any of the options don't fulfill the
* specified validation rules
*/
public function replaceData(array $data)
{
$data = $this->resolver->resolve($data);

parent::replaceData($data);
}

/**
* {@inheritdoc}
*
* @throws UndefinedOptionsException If any of the options are not supported
* by the context
* @throws InvalidOptionsException If any of the options don't fulfill the
* specified validation rules
*/
public function offsetSet($offset, $value)
{
$data = $this->resolver->resolve([$offset => $value]);

parent::offsetSet($offset, $data[$offset]);
}

/**
* Configures the options of the context.
*
* @param OptionsResolver $resolver The resolver for the options
*/
abstract protected function configureOptions(OptionsResolver $resolver);
}
101 changes: 3 additions & 98 deletions src/Context/RuntimeContext.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
<?php

/*
* This file is part of Raven.
*
* (c) Sentry Team
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sentry\Context;

use Sentry\Util\PHPVersion;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
Expand All @@ -22,90 +11,8 @@
*
* @author Stefano Arlandini <[email protected]>
*/
class RuntimeContext extends Context
final class RuntimeContext extends OptionsResolverContext
{
/**
* @var OptionsResolver The options resolver
*/
private $resolver;

/**
* {@inheritdoc}
*
* @throws UndefinedOptionsException If any of the options are not supported
* by the context
* @throws InvalidOptionsException If any of the options don't fulfill the
* specified validation rules
*/
public function __construct(array $data = [])
{
$this->resolver = new OptionsResolver();

$this->configureOptions($this->resolver);

parent::__construct($this->resolver->resolve($data));
}

/**
* {@inheritdoc}
*
* @throws UndefinedOptionsException If any of the options are not supported
* by the context
* @throws InvalidOptionsException If any of the options don't fulfill the
* specified validation rules
*/
public function merge(array $data, $recursive = false)
{
$data = $this->resolver->resolve($data);

parent::merge($data, $recursive);
}

/**
* {@inheritdoc}
*
* @throws UndefinedOptionsException If any of the options are not supported
* by the context
* @throws InvalidOptionsException If any of the options don't fulfill the
* specified validation rules
*/
public function setData(array $data)
{
$data = $this->resolver->resolve($data);

parent::setData($data);
}

/**
* {@inheritdoc}
*
* @throws UndefinedOptionsException If any of the options are not supported
* by the context
* @throws InvalidOptionsException If any of the options don't fulfill the
* specified validation rules
*/
public function replaceData(array $data)
{
$data = $this->resolver->resolve($data);

parent::replaceData($data);
}

/**
* {@inheritdoc}
*
* @throws UndefinedOptionsException If any of the options are not supported
* by the context
* @throws InvalidOptionsException If any of the options don't fulfill the
* specified validation rules
*/
public function offsetSet($offset, $value)
{
$data = $this->resolver->resolve([$offset => $value]);

parent::offsetSet($offset, $data[$offset]);
}

/**
* Gets the name of the runtime.
*
Expand Down Expand Up @@ -147,11 +54,9 @@ public function setVersion($version)
}

/**
* Configures the options of the context.
*
* @param OptionsResolver $resolver The resolver for the options
* {@inheritdoc}
*/
private function configureOptions(OptionsResolver $resolver)
protected function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'name' => 'php',
Expand Down
Loading