• 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

0.0
/lib/ActiveRecord/StaticConnectionProvider.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;
13

14
use Closure;
15
use LogicException;
16

17
/**
18
 * Provides a {@link Connection} instance.
19
 */
20
final class StaticConnectionProvider
21
{
22
    /**
23
     * @var (Closure(): ConnectionProvider)|null
24
     */
25
    private static ?Closure $factory = null;
26
    private static ?ConnectionProvider $provider = null;
27

28
    /**
29
     * Defines the {@link ConnectionProvider} factory.
30
     *
31
     * @param (callable(): ConnectionProvider) $factory
32
     *     The factory is invoked once: the first time {@link connection_for_id} is invoked.
33
     *
34
     * @return (callable(): ConnectionProvider)|null
35
     *     The previous factory, or `null` if none was defined.
36
     */
37
    public static function define(callable $factory): ?callable
38
    {
39
        $previous = self::$factory;
×
40

41
        self::$factory = $factory(...);
×
42
        self::$provider = null;
×
43

44
        return $previous;
×
45
    }
46

47
    /**
48
     * Returns the current {@link ConnectionProvider} factory.
49
     *
50
     * @return (callable(): ConnectionProvider)|null
51
     */
52
    public static function defined(): ?callable
53
    {
54
        return self::$factory;
×
55
    }
56

57
    /**
58
     * Undefines the {@link ConnectionProvider} factory.
59
     */
60
    public static function undefine(): void
61
    {
62
        self::$factory = null;
×
63
        self::$provider = null;
×
64
    }
65

66
    /**
67
     * @param non-empty-string $id
68
     *     A connection identifier.
69
     */
70
    public static function connection_for_id(string $id): Connection
71
    {
72
        $factory = self::$factory
×
73
            ?? throw new LogicException(
×
74
                "No factory defined yet. Please define one with `StaticConnectionProvider::define()`"
×
75
            );
×
76

77
        return (self::$provider ??= $factory())->connection_for_id($id);
×
78
    }
79
}
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