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

ICanBoogie / ActiveRecord / 6362433236

30 Sep 2023 11:14AM UTC coverage: 85.731% (+5.6%) from 80.178%
6362433236

push

github

olvlvl
Rename StaticModelProvider methods

1436 of 1675 relevant lines covered (85.73%)

29.41 hits per line

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

78.57
/lib/ActiveRecord/Driver/BasicDriver.php
1
<?php
2

3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
namespace ICanBoogie\ActiveRecord\Driver;
13

14
use DateTimeInterface;
15
use ICanBoogie\Accessor\AccessorTrait;
16
use ICanBoogie\ActiveRecord\Connection;
17
use ICanBoogie\ActiveRecord\Driver;
18
use ICanBoogie\ActiveRecord\Schema;
19
use ICanBoogie\DateTime;
20

21
/**
22
 * Basic connection driver.
23
 *
24
 * @property-read Connection $connection
25
 */
26
abstract class BasicDriver implements Driver
27
{
28
    /**
29
     * @uses get_connection
30
     */
31
    use AccessorTrait;
32

33
    /**
34
     * @var callable
35
     */
36
    private $connection_provider;
37

38
    private function get_connection(): Connection
39
    {
40
        return ($this->connection_provider)();
77✔
41
    }
42

43
    /**
44
     * @param callable $connection_provider A callable that provides a database connection.
45
     */
46
    public function __construct(callable $connection_provider)
47
    {
48
        $this->connection_provider = $connection_provider;
78✔
49
    }
50

51
    /**
52
     * @inheritdoc
53
     */
54
    public function quote_string(string $string): string
55
    {
56
        return $this->connection->pdo->quote($string);
×
57
    }
58

59
    /**
60
     * @inheritDoc
61
     */
62
    public function quote_identifier(string $identifier): string
63
    {
64
        return "`$identifier`";
59✔
65
    }
66

67
    /**
68
     * @inheritDoc
69
     */
70
    public function cast_value(mixed $value, string $type = null): mixed
71
    {
72
        if ($value instanceof DateTimeInterface) {
58✔
73
            return DateTime::from($value)->utc->as_db;
38✔
74
        }
75

76
        if ($value === false) {
58✔
77
            return 0;
×
78
        }
79

80
        if ($value === true) {
58✔
81
            return 1;
×
82
        }
83

84
        return $value;
58✔
85
    }
86

87
    public function create_table(string $table_name, Schema $schema): void
88
    {
89
        $this->connection->exec(
77✔
90
            $this->render_create_table($table_name, $schema)
77✔
91
        );
77✔
92
    }
93

94
    /**
95
     * Renders the statement to create the specified table.
96
     *
97
     * @param non-empty-string $table_name
98
     *
99
     * @return non-empty-string
100
     */
101
    abstract protected function render_create_table(string $table_name, Schema $schema): string;
102
}
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

© 2026 Coveralls, Inc