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

webboy / measurement-units / 12734123994

12 Jan 2025 01:52PM UTC coverage: 96.259% (+1.0%) from 95.262%
12734123994

push

github

webboy
Merge remote-tracking branch 'origin/main'

386 of 401 relevant lines covered (96.26%)

6.07 hits per line

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

87.5
/src/MeasurementValueDto.php
1
<?php
2

3
namespace Webboy\MeasurementUnits;
4

5
use Webboy\MeasurementUnits\Exceptions\MeasurementValueExceptions\IllegalInstantiationMeasurementValueException;
6

7
/**
8
 * The base class for all measurement value DTOs.
9
 */
10
class MeasurementValueDto
11
{
12
    /**
13
     * @var int | float The value of the measurement.
14
     */
15
    public int | float $value;
16

17
    /**
18
     * @var UnitDto The unit of the measurement.
19
     */
20
    public UnitDto $unit;
21

22
    /**
23
     * @var MeasurementDto The measurement of the value.
24
     */
25
    public MeasurementDto $measurement;
26

27
    /**
28
     * Create a new measurement value DTO.
29
     *
30
     * @param int | float $value The value of the measurement.
31
     * @param UnitDto $unit The unit of the measurement.
32
     * @param MeasurementDto $measurement The measurement of the value.
33
     */
34
    protected function __construct(int | float $value, UnitDto $unit, MeasurementDto $measurement)
6✔
35
    {
36
        $this->value = $value;
6✔
37
        $this->unit = $unit;
6✔
38
        $this->measurement = $measurement;
6✔
39
    }
40

41
    /**
42
     * Create a new measurement value DTO from a factory.
43
     *
44
     * @param int | float $value The value of the measurement.
45
     * @param UnitDto $unit The unit of the measurement.
46
     * @param MeasurementDto $measurement The measurement of the value.
47
     * @param string $caller The class that called the factory.
48
     * @return static The new measurement value DTO.
49
     * @throws IllegalInstantiationMeasurementValueException
50
     */
51
    public static function createFromFactory(int | float $value, UnitDto $unit, MeasurementDto $measurement, string $caller): self
6✔
52
    {
53
        if ($caller !== get_class($measurement)) {
6✔
54
            throw new IllegalInstantiationMeasurementValueException();
×
55
        }
56

57
        return new self($value, $unit, $measurement);
6✔
58
    }
59
}
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