• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

letsdrink / ouzo / 6036930958

31 Aug 2023 11:53AM UTC coverage: 82.907% (-3.1%) from 86.01%
6036930958

push

github

web-flow
Add string space const (#318)

4802 of 5792 relevant lines covered (82.91%)

32.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.3
/src/Ouzo/Core/Db/QueryBoundValuesExtractor.php
1
<?php
2
/*
3
 * Copyright (c) Ouzo contributors, https://github.com/letsdrink/ouzo
4
 * This file is made available under the MIT License (view the LICENSE file for more information).
5
 */
6

7
namespace Ouzo\Db;
8

9
use Ouzo\Db\WhereClause\WhereClause;
10
use Ouzo\Restriction\Restriction;
11
use Ouzo\Utilities\Objects;
12

13
class QueryBoundValuesExtractor
14
{
15
    private array $boundValues = [];
16
    private Query $query;
17

18
    public function __construct(Query $query)
19
    {
20
        $this->query = $query;
488✔
21
    }
22

23
    public function extract(): array
24
    {
25
        $this->addBindValues($this->query);
488✔
26
        return $this->boundValues;
488✔
27
    }
28

29
    private function addBindValues(Query $query): void
30
    {
31
        if ($query->table instanceof Query) {
488✔
32
            $this->addBindValues($query->table);
6✔
33
        }
34
        $this->addBindValue(array_values($query->updateAttributes));
488✔
35

36
        $this->addBindValuesFromJoinClauses($query->joinClauses);
488✔
37

38
        foreach ($query->whereClauses as $whereClause) {
488✔
39
            $this->addBindValuesFromWhereClause($whereClause);
374✔
40
        }
41

42
        if ($query->type == QueryType::$UPSERT) {
488✔
43
            $this->addBindValue(array_values($query->updateAttributes));
8✔
44
        }
45

46
        if ($query->limit !== null) {
488✔
47
            $this->addBindValue($query->limit);
3✔
48
        }
49
        if ($query->offset) {
488✔
50
            $this->addBindValue($query->offset);
3✔
51
        }
52
    }
53

54
    /** @param JoinClause[] $joinClauses */
55
    private function addBindValuesFromJoinClauses(array $joinClauses): void
56
    {
57
        foreach ($joinClauses as $joinClause) {
488✔
58
            foreach ($joinClause->onClauses as $onClause) {
84✔
59
                $this->addBindValuesFromWhereClause($onClause);
84✔
60
            }
61
        }
62
    }
63

64
    /** @param WhereClause $whereClause */
65
    private function addBindValuesFromWhereClause(WhereClause $whereClause): void
66
    {
67
        if (!$whereClause->isEmpty()) {
422✔
68
            $this->addBindValue($whereClause->getParameters());
347✔
69
        }
70
    }
71

72
    private function addBindArrayValue(array $array): void
73
    {
74
        foreach ($array as $value) {
488✔
75
            if ($value instanceof Restriction) {
479✔
76
                $this->boundValues = array_merge($this->boundValues, $value->getValues());
44✔
77
            } else {
78
                $this->boundValues[] = $value;
479✔
79
            }
80
        }
81
    }
82

83
    public function addBindValue(mixed $value): void
84
    {
85
        if (is_array($value)) {
488✔
86
            $this->addBindArrayValue($value);
488✔
87
        } else {
88
            $this->boundValues[] = is_bool($value) ? Objects::booleanToString($value) : $value;
3✔
89
        }
90
    }
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc