cycle / database

Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders
MIT License
54 stars 23 forks source link

fix type strictness in TokenTrait #123

Closed roxblnfk closed 1 year ago

roxblnfk commented 1 year ago

Fix

TypeError: strtoupper(): Argument #1 ($string) must be of type string, int given
vendor\cycle\database\src\Query\Traits\TokenTrait.php:175

I'm not sure about that fix because it might be related with building for bad query. After the fix I get some think like this: {C7935317-2937-4538-A7CE-B0C5FB8408EE}


Upd:

The bad query produces Cycle ORM Scope:

final class UnexpiredTokenScope implements ScopeInterface
{
    public function apply(QueryBuilder $query): void
    {
        $query->andWhere(['@OR' => [
            [Token::F_EXPIRES_AT, '=', new Parameter(null)],
            [Token::F_EXPIRES_AT, '>', new \DateTimeImmutable()],
        ]]);
    }
}

That query code can be replaced with this one:

        $query->andWhere(function (QueryBuilder $query) {
            $query->where(Token::F_EXPIRES_AT, '=', new Parameter(null))
                ->orWhere(Token::F_EXPIRES_AT, '>', new \DateTimeImmutable());
        });

But we need to research if the origin code was correct. If yes - need to fix QueryBuilder

codecov[bot] commented 1 year ago

Codecov Report

Merging #123 (5683bd3) into 2.x (d5b1be2) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##                2.x     #123   +/-   ##
=========================================
  Coverage     94.68%   94.68%           
  Complexity     1667     1667           
=========================================
  Files            96       96           
  Lines          4496     4497    +1     
=========================================
+ Hits           4257     4258    +1     
  Misses          239      239           
Impacted Files Coverage Δ
src/Query/Traits/TokenTrait.php 93.98% <100.00%> (+0.04%) :arrow_up:
roxblnfk commented 1 year ago

The first Scope implementation is invalid