Completed
Push — master ( ecd0f8...3ad52b )
by ignace nyamagana
15:08
created

CannotInsertRecord::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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