CannotInsertRecord::getRecord()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * League.Csv (https://csv.thephpleague.com)
5
 *
6
 * (c) Ignace Nyamagana Butera <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace League\Csv;
15
16
/**
17
 * Thrown when a data is not added to the Csv Document.
18
 */
19
class CannotInsertRecord extends Exception
20
{
21
    /**
22
     * The record submitted for insertion.
23
     *
24
     * @var array
25
     */
26
    protected $record;
27
28
    /**
29
     * Validator which did not validated the data.
30
     *
31
     * @var string
32
     */
33
    protected $name = '';
34
35
    /**
36
     * Create an Exception from a record insertion into a stream.
37
     */
38 3
    public static function triggerOnInsertion(array $record): self
39
    {
40 3
        $exception = new self('Unable to write record to the CSV document');
41 3
        $exception->record = $record;
42
43 3
        return $exception;
44
    }
45
46
    /**
47
     * Create an Exception from a Record Validation.
48
     */
49 12
    public static function triggerOnValidation(string $name, array $record): self
50
    {
51 12
        $exception = new self('Record validation failed');
52 12
        $exception->name = $name;
53 12
        $exception->record = $record;
54
55 12
        return $exception;
56
    }
57
58
    /**
59
     * return the validator name.
60
     *
61
     */
62 9
    public function getName(): string
63
    {
64 9
        return $this->name;
65
    }
66
67
    /**
68
     * return the invalid data submitted.
69
     *
70
     */
71 9
    public function getRecord(): array
72
    {
73 9
        return $this->record;
74
    }
75
}
76