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

Problem with 0 executed statements #534

Open
koupisbean opened this issue Apr 30, 2023 · 1 comment
Open

Problem with 0 executed statements #534

koupisbean opened this issue Apr 30, 2023 · 1 comment

Comments

@koupisbean
Copy link

Hello, I have discovered probably a problem.

Im using Laravel DebuBar and when I want to register TraceablePDO class to track all PDO queries and run 0 queries, it gives error with return type.

Register (in Laravel ServiceProvider):

$pdo = new TraceablePDO(DB::getPdo());
app('debugbar')->addCollector(new PDOCollector($pdo));

DB::setPdo($pdo);

Error:

DebugBar\DataCollector\PDO\TraceablePDO::getAccumulatedStatementsDuration(): Return value must be of type float, null returned

After preventing from returning null, it works as it should.

Fix (in DebugBar\DataCollector\PDO\TraceablePDO):

    /**
     * Returns the accumulated execution time of statements
     *
     * @return float
     */
    public function getAccumulatedStatementsDuration() : float
    {
        return array_reduce($this->executedStatements, function ($v, $s) { return $v + $s->getDuration(); }) ?? 0;
    }

    /**
     * Returns the peak memory usage while performing statements
     *
     * @return int
     */
    public function getMemoryUsage() : int
    {
        return array_reduce($this->executedStatements, function ($v, $s) { return $v + $s->getMemoryUsage(); }) ?? 0;
    }

    /**
     * Returns the peak memory usage while performing statements
     *
     * @return int
     */
    public function getPeakMemoryUsage() : int
    {
        return array_reduce($this->executedStatements, function ($v, $s) { $m = $s->getEndMemory(); return $m > $v ? $m : $v; }) ?? 0;
    }
@angeljqv
Copy link
Contributor

Closed by #523

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants