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

ICanBoogie / ActiveRecord / 4542546258

pending completion
4542546258

push

github

Olivier Laviale
Add 'belongs_to' to the SchemaBuilder

29 of 29 new or added lines in 4 files covered. (100.0%)

1356 of 1726 relevant lines covered (78.56%)

36.14 hits per line

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

60.0
/lib/ActiveRecord/Schema/Integer.php
1
<?php
2

3
namespace ICanBoogie\ActiveRecord\Schema;
4

5
use Attribute;
6
use LogicException;
7

8
use function in_array;
9

10
/**
11
 * Represents an integer value:
12
 *
13
 * - `TINYINT` is `Integer(size: Integer::SIZE_TINY)` or `Integer(1)`
14
 */
15
#[Attribute(Attribute::TARGET_PROPERTY)]
16
class Integer extends Constraints implements SchemaColumn
17
{
18
    public const SIZE_TINY = 1;
19
    public const SIZE_SMALL = 2;
20
    public const SIZE_MEDIUM = 3;
21
    public const SIZE_REGULAR = 4;
22
    public const SIZE_BIG = 8;
23

24
    private const ALLOWED_SIZES = [
25
        self::SIZE_TINY,
26
        self::SIZE_SMALL,
27
        self::SIZE_MEDIUM,
28
        self::SIZE_REGULAR,
29
        self::SIZE_BIG
30
    ];
31

32
    /**
33
     * @param array{
34
     *     size: positive-int,
35
     *     unsigned: bool,
36
     *     serial: bool,
37
     *     null: bool,
38
     *     unique: bool,
39
     *     default: int|string|null,
40
     * } $an_array
41
     *
42
     * @return object
43
     */
44
    public static function __set_state(array $an_array): object
45
    {
46
        return new self(
×
47
            $an_array['size'],
×
48
            $an_array['unsigned'],
×
49
            $an_array['serial'],
×
50
            $an_array['null'],
×
51
            $an_array['unique'],
×
52
            $an_array['default'],
×
53
        );
×
54
    }
55

56
    /**
57
     * @param positive-int $size
58
     *     Number of bytes used to store values. Must be one of: {@link self::SIZE_TINY}, {@link self::SIZE_SMALL},
59
     *     {@link self::SIZE_MEDIUM}, {@link self::SIZE_REGULAR}, {@link self::SIZE_BIG}.
60
     * @param bool $unsigned
61
     *     Whether values are unsigned.
62
     *     Values are signed by default.
63
     * @param bool $serial
64
     *     An integer that is automatically incremented by the database. This has a few constraints:
65
     *     - `$size` must at least 2 bytes
66
     *     - `$unsigned` must be `true`
67
     *     - `$null` must be `false`
68
     *     - `$unique` must be `true`
69
     *     Values are not serial by default.
70
     */
71
    public function __construct(
72
        public readonly int $size = self::SIZE_REGULAR,
73
        public readonly bool $unsigned = false,
74
        public readonly bool $serial = false,
75
        bool $null = false,
76
        bool $unique = false,
77
        int|string $default = null,
78
    ) {
79
        in_array($size, self::ALLOWED_SIZES)
131✔
80
            or throw new LogicException("Size must be one of the allowed ones");
131✔
81

82
        if ($serial) {
129✔
83
            $size > 1 or throw new LogicException("A serial integer must be at least 2 bytes");
128✔
84
            $unsigned or throw new LogicException("A serial integer must be unsigned");
127✔
85
            !$null or throw new LogicException("A serial integer cannot be nullable");
126✔
86
            $unique or throw new LogicException("A serial integer must be unique");
125✔
87
        }
88

89
        parent::__construct(
125✔
90
            null: $null,
125✔
91
            default: $default === null ? null : "$default",
125✔
92
            unique: $unique,
125✔
93
        );
125✔
94
    }
95
}
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