Completed
Push — master ( b6ead1...d7f0f7 )
by Jesse
03:42
created

NoSuchValue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A couldNotFind() 0 6 1
A noneOfTheValuesMatched() 0 5 1
1
<?php
2
3
namespace Stratadox\ImmutableCollection;
4
5
use function get_class;
6
use function sprintf;
7
use Stratadox\Collection\Collection;
8
use Stratadox\Collection\NotFound;
9
use Stratadox\Collection\Searchable;
10
use UnexpectedValueException;
11
use function var_export;
12
13
/**
14
 * Exception to notify the client code that the requested value does not exist.
15
 *
16
 * In order to prevent this exception from being thrown, client code can usually
17
 * implement a method like @see Searchable::has() to be certain that the value
18
 * actually exists.
19
 * When looking for an object by reference, use @see Searchable::hasThe() instead.
20
 *
21
 * @package Stratadox\Collection
22
 * @author  Stratadox
23
 */
24
class NoSuchValue extends UnexpectedValueException implements NotFound
25
{
26
    /**
27
     * @param Collection $collection The collection that does not have the item.
28
     * @param mixed      $theValue   The value that was not found.
29
     * @return NotFound              The exception object to throw.
30
     */
31
    public static function couldNotFind(Collection $collection, $theValue): NotFound
32
    {
33
        return new static(sprintf(
34
            'Could not find %s in %s',
35
            var_export($theValue, true),
36
            get_class($collection)
37
        ));
38
    }
39
40
    public static function noneOfTheValuesMatched(Collection $collection): self
41
    {
42
        return new self(sprintf(
43
            'Could not find any accepted item in the %s.',
44
            get_class($collection)
45
        ));
46
    }
47
}
48