Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cast the replaced value as string #95

Merged
merged 3 commits into from
Aug 9, 2023
Merged
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
5 changes: 1 addition & 4 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ public function handleEvent($event, $name = null)
* @param Event $event
* @param string $method
*
* @return mixed
*
* @throws Exception
*/
private function getEventValue($event, $method)
Expand Down Expand Up @@ -187,7 +185,7 @@ private function replaceConfigPlaceholder($event, $eventName, $string)
if ((preg_match_all('/<([^>]*)>/', $string, $matches) > 0) and ($this->propertyAccessor !== null)) {
$tokens = $matches[1];
foreach ($tokens as $token) {
$value = $this->propertyAccessor->getValue($event, $token);
$value = (string) $this->propertyAccessor->getValue($event, $token);
$string = str_replace('<'.$token.'>', $value, $string);
}
}
Expand All @@ -198,7 +196,6 @@ private function replaceConfigPlaceholder($event, $eventName, $string)
/**
* Merge config tags with tags manually sent with the event
*
* @param mixed $event
* @param array $config
*
* @return array of tags
Expand Down
5 changes: 0 additions & 5 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('m6_statsd');
Expand Down Expand Up @@ -100,8 +97,6 @@ private function addClientsSection($rootNode)

/**
* addDefaultEventSection
*
* @param mixed $rootNode
*/
private function addDefaultEventSection($rootNode)
{
Expand Down
3 changes: 0 additions & 3 deletions src/DependencyInjection/M6WebStatsdExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
*/
class M6WebStatsdExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
Expand Down
3 changes: 0 additions & 3 deletions src/Event/ConsoleCommandEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
*/
class ConsoleCommandEvent extends ConsoleEvent
{
/**
* {@inheritDoc}
*/
protected static function support(BaseConsoleEvent $e)
{
return $e instanceof BaseEvent;
Expand Down
3 changes: 0 additions & 3 deletions src/Event/ConsoleErrorEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
*/
class ConsoleErrorEvent extends ConsoleEvent
{
/**
* {@inheritDoc}
*/
protected static function support(BaseConsoleEvent $e)
{
return $e instanceof BaseEvent;
Expand Down
2 changes: 0 additions & 2 deletions src/Event/ConsoleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ final public function __construct(BaseConsoleEvent $originalEvent, $startTime =
*
* @param string $name
* @param array $parameters
*
* @return mixed
*/
public function __call($name, $parameters)
{
Expand Down
3 changes: 0 additions & 3 deletions src/Event/ConsoleTerminateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
*/
class ConsoleTerminateEvent extends ConsoleEvent
{
/**
* {@inheritDoc}
*/
protected static function support(BaseConsoleEvent $e)
{
return $e instanceof BaseEvent;
Expand Down
14 changes: 10 additions & 4 deletions src/Listener/ConsoleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@
*/
class ConsoleListener
{
/** @var EventDispatcherInterface */
protected $eventDispatcher = null;
/** @var ?EventDispatcherInterface */
protected $eventDispatcher;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should update line 67 to check with isset

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I trusted blindly the cs-fixer. Thank you.


/**
* Time when command started
*
* @var float
* @var ?float
*/
protected $startTime = null;
protected $startTime;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If for some reason onException or onTerminate are called before onCommand we will get an exception (L.76) because startTime will not have been set. We should check if startTime is set before dispatching.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am struggling with the cs-fixer. I initialized these vars inside the constructor


public function __construct()
{
$this->startTime = null;
$this->eventDispatcher = null;
}

/**
* Define event dispatch
Expand Down
2 changes: 0 additions & 2 deletions src/Statsd/MonitorableEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ interface MonitorableEventInterface
{
/**
* the measured value
*
* @return mixed
*/
public function getValue();

Expand Down
4 changes: 0 additions & 4 deletions src/Statsd/StatsdEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class StatsdEvent extends GenericEvent implements MonitorableEventInterface
{
/**
* getTiming
*
* @return mixed
*/
public function getTiming()
{
Expand All @@ -23,8 +21,6 @@ public function getTiming()

/**
* getValue
*
* @return mixed
*/
public function getValue()
{
Expand Down
3 changes: 0 additions & 3 deletions src/Validator/Constraints/NodeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
class NodeValidator extends ConstraintValidator
{
/**
* {@inheritDoc}
*/
public function validate($value, Constraint $constraint)
{
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
Expand Down