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

Add Symfony 3.4 compatibility, without deprecation notices #47

Merged
merged 1 commit into from
Dec 8, 2017
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ php:
env:
- SYMFONY_VERSION="2.8.*"
- SYMFONY_VERSION="3.1.*"
- SYMFONY_VERSION="3.4.*"
- COMPOSER_FLAGS="--prefer-lowest"

matrix:
Expand All @@ -20,4 +21,4 @@ before_install:

install: composer update --prefer-dist $COMPOSER_FLAGS

script: bin/atoum
script: bin/atoum
33 changes: 18 additions & 15 deletions src/AmqpBundle/Amqp/DataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DataCollector extends SymfonyDataCollector
public function __construct($name)
{
$this->name = $name;
$this->data['commands'] = array();
$this->reset();
}

/**
Expand All @@ -44,7 +44,7 @@ public function collect(Request $request, Response $response, \Exception $except
}

/**
* Listen for aws command event.
* Listen for command event.
*
* @param object $event The event object
*/
Expand All @@ -62,7 +62,7 @@ public function onCommand($event)
*
* @return array The command list and number of times called
*/
public function getCommands()
public function getCommands(): array
{
return $this->data['commands'];
}
Expand All @@ -72,33 +72,36 @@ public function getCommands()
*
* @return string data collector name
*/
public function getName()
public function getName(): string
{
return $this->name;
}

/**
* Temps total d'exec des commandes.
* Return total command execution time.
*
* @return float
*/
public function getTotalExecutionTime()
public function getTotalExecutionTime(): float
{
$ret = 0;
foreach ($this->data['commands'] as $command) {
$ret += $command['executiontime'];
}

return $ret;
return (float) array_sum(array_column($this->data['commands'], 'executiontime'));
}

/**
* Temps moyen d'exec.
* Get average execution time.
*
* @return float
*/
public function getAvgExecutionTime()
public function getAvgExecutionTime(): float
{
return $this->getTotalExecutionTime() ? ($this->getTotalExecutionTime() / \count($this->data['commands'])) : (float) 0;
}

/**
* {@inheritdoc}
*/
public function reset()
{
return ($this->getTotalExecutionTime()) ? ($this->getTotalExecutionTime() / count($this->data['commands'])) : 0;
$this->data = [['commands' => []];
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need to call parent::reset() to ensure proper $this-data reset? 🤔

parent::reset();
$this->data['commands'] = [];

I didn't find where is defined data and who is in charge of its default initialization 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, most other data collectors I ran into so far do just reset to empty array, as do most of the official ones from symfony itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good 😃
Let's go for v3.0.1 🎉

}
}