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

diego-ninja / granite / 18554422350

16 Oct 2025 07:59AM UTC coverage: 82.689% (-0.4%) from 83.133%
18554422350

Pull #15

github

web-flow
Merge 8e39c5ac3 into dd1631bf7
Pull Request #15: refactor: hydrators

126 of 136 new or added lines in 9 files covered. (92.65%)

25 existing lines in 1 file now uncovered.

2651 of 3206 relevant lines covered (82.69%)

16.55 hits per line

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

10.71
/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
12✔
21
    {
22
        if (empty($args)) {
12✔
UNCOV
23
            throw new InvalidArgumentException('At least one argument is required');
×
24
        }
25

26
        return parent::from(...$args);
12✔
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
     */
UNCOV
38
    public function equals(mixed $other): bool
×
39
    {
40
        // If comparing with the same instance
UNCOV
41
        if ($this === $other) {
×
UNCOV
42
            return true;
×
43
        }
44

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

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

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

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

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

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

UNCOV
77
            return true;
×
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
     */
UNCOV
93
    public function with(array $modifications): static
×
94
    {
95
        // Start with the current values
UNCOV
96
        $data = $this->array();
×
97

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

103
        // Create new instance with modified data
UNCOV
104
        return static::from($data);
×
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