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

[BUG]: Wrong return type hint for Phalcon\Mvc\Model::average #15013

Closed
sergeyklay opened this issue May 5, 2020 · 1 comment · Fixed by #15014
Closed

[BUG]: Wrong return type hint for Phalcon\Mvc\Model::average #15013

sergeyklay opened this issue May 5, 2020 · 1 comment · Fixed by #15014
Assignees
Labels
bug A bug report status: low Low

Comments

@sergeyklay
Copy link
Contributor

Current return type hint of the Phalcon\Mvc\Model::average implies that method must return a float value. But this method MAY return am Phalcon\Mvc\Model\ResultsetInterface instance for for when the GROUP condition is used:

public static function average(var parameters = null) -> float
{
return self::_groupResult("AVG", "average", parameters);
}

For example:

use Phalcon\Di;
use Phalcon\Di\FactoryDefault;
use Phalcon\Db\Adapter\PdoFactory;
use Phalcon\Mvc\Model;

$options = ['dbname' => '/tmp/test.sqlite'];

Di::reset();

$container = new FactoryDefault();
Di::setDefault($container);

$container->setShared(
    'db',
    (new PdoFactory())->newInstance('sqlite', $options)
);

class Invoices extends Model {
    public $inv_id;
    public $inv_cst_id;
    public $inv_status_flag;
    public $inv_title;
    public $inv_total;
    public $inv_created_at;

    public function initialize()
    {
        $this->setSource('co_invoices');
    }
}

// All is OK
var_dump(Invoices::average(['column' => 'inv_id'])); 

// Fatal Error
var_dump(Invoices::average(         
    [
        'column' => 'inv_id',
        'group' => 'inv_cst_id'
    ]
));

This leads to a fatal error:

PHP Fatal error:
Return value of Phalcon\Mvc\Model::average()
must be of the type float, object returned
@sergeyklay
Copy link
Contributor Author

Fixed in 4.0.x branch

@niden niden moved this to Released in Phalcon v5 Aug 25, 2022
@niden niden added this to Phalcon v5 Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: low Low
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant