Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
InvalidStringForValueObjectException
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\Core\ValueObjects\Exceptions;
3
4use Apie\Core\Exceptions\ApieException;
5use Apie\Core\ValueObjects\Interfaces\ValueObjectInterface;
6use Apie\Core\ValueObjects\Utils;
7use ReflectionClass;
8use Throwable;
9
10/**
11 * Exception thrown by a value object that the input is not valid for a
12 * value object.
13 */
14class InvalidStringForValueObjectException extends ApieException
15{
16    /**
17     * @param ValueObjectInterface|ReflectionClass<object> $valueObject
18     */
19    public function __construct(string $input, ValueObjectInterface|ReflectionClass $valueObject, ?Throwable $previous = null)
20    {
21        if (strlen($input) > 80) {
22            $halfLength = (80 - 3) / 2;
23            $input = substr($input, 0, (int) floor($halfLength)) . '...' . substr($input, (int) -ceil($halfLength));
24        }
25        parent::__construct(
26            sprintf(
27                'Value "%s" is not valid for value object of type: %s',
28                $input,
29                Utils::getDisplayNameForValueObject($valueObject)
30            ),
31            0,
32            $previous
33        );
34    }
35}