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

diego-ninja / granite / 16670003981

01 Aug 2025 08:14AM UTC coverage: 51.478% (+1.1%) from 50.423%
16670003981

push

github

web-flow
Merge pull request #8 from diego-ninja/feature/carbon_support

fix: fixes readonly property init in php 8.3

12 of 55 new or added lines in 1 file covered. (21.82%)

60 existing lines in 2 files now uncovered.

1515 of 2943 relevant lines covered (51.48%)

11.39 hits per line

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

92.86
/src/GraniteVO.php
1
<?php
2

3
namespace Ninja\Granite;
4

5
use DateMalformedStringException;
6
use InvalidArgumentException;
7
use Ninja\Granite\Exceptions\SerializationException;
8

9
abstract readonly class GraniteVO extends Granite
10
{
11
    /**
12
     * Create a new Value Object instance with validation.
13
     *
14
     * @param mixed ...$args Variable arguments supporting multiple patterns
15
     * @return static The new Value Object instance
16
     * @throws InvalidArgumentException If validation fails
17
     * @throws DateMalformedStringException
18
     * @throws Exceptions\ReflectionException
19
     */
20
    public static function from(mixed ...$args): static
38✔
21
    {
22
        if (empty($args)) {
38✔
UNCOV
23
            throw new InvalidArgumentException('At least one argument is required');
×
24
        }
25

26
        return parent::from(...$args);
38✔
27
    }
28

29
    /**
30
     * Compare this Value Object with another Value Object or array.
31
     * Two Value Objects are equal if they have the same class and the same property values.
32
     *
33
     * @param mixed $other The Value Object or array to compare with
34
     * @return bool True if equal, false otherwise
35
     * @throws Exceptions\ReflectionException
36
     * @throws SerializationException
37
     */
38
    public function equals(mixed $other): bool
10✔
39
    {
40
        // If comparing with the same instance
41
        if ($this === $other) {
10✔
42
            return true;
1✔
43
        }
44

45
        // If comparing with another Value Object
46
        if ($other instanceof self) {
9✔
47
            // Must be the same class
48
            if (get_class($this) !== get_class($other)) {
5✔
49
                return false;
1✔
50
            }
51

52
            // Convert both to arrays and compare
53
            $thisArray = $this->array();
4✔
54
            $otherArray = $other->array();
4✔
55

56
            return $thisArray === $otherArray; // Using loose comparison for array values
4✔
57
        }
58

59
        // If comparing with an array
60
        if (is_array($other)) {
4✔
61
            $thisArray = $this->array();
4✔
62

63
            // Check if the array has all the properties
64
            foreach ($thisArray as $key => $value) {
4✔
65
                if ( ! array_key_exists($key, $other) || $other[$key] !== $value) {
4✔
66
                    return false;
2✔
67
                }
68
            }
69

70
            // Check if the array has extra properties
71
            foreach ($other as $key => $value) {
2✔
72
                if ( ! array_key_exists($key, $thisArray)) {
2✔
73
                    return false;
1✔
74
                }
75
            }
76

77
            return true;
1✔
78
        }
79

UNCOV
80
        return false;
×
81
    }
82

83
    /**
84
     * Create a new instance with some properties modified.
85
     * This respects immutability by creating a new instance.
86
     *
87
     * @param array $modifications Properties to modify
88
     * @return static New Value Object with modifications
89
     * @throws InvalidArgumentException If validation fails
90
     * @throws DateMalformedStringException
91
     * @throws SerializationException|Exceptions\ReflectionException
92
     */
93
    public function with(array $modifications): static
5✔
94
    {
95
        // Start with the current values
96
        $data = $this->array();
5✔
97

98
        // Apply modifications
99
        foreach ($modifications as $property => $value) {
5✔
100
            $data[$property] = $value;
5✔
101
        }
102

103
        // Create new instance with modified data
104
        return static::from($data);
5✔
105
    }
106
}
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