Completed
Push — master ( aa23c0...364b30 )
by ignace nyamagana
05:47 queued 02:02
created

CannotInsertRecord   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A triggerOnInsertion() 0 7 1
A triggerOnValidation() 0 8 1
A getName() 0 4 1
A getRecord() 0 4 1
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 3
    public static function triggerOnInsertion(array $record): self
46
    {
47 3
        $exception = new static('Unable to write record to the CSV document');
48 3
        $exception->record = $record;
49
50 3
        return $exception;
51
    }
52
53
    /**
54
     * Create an Exception from a Record Validation.
55
     */
56 12
    public static function triggerOnValidation(string $name, array $record): self
57
    {
58 12
        $exception = new static('Record validation failed');
59 12
        $exception->name = $name;
60 12
        $exception->record = $record;
61
62 12
        return $exception;
63
    }
64
65
    /**
66
     * return the validator name.
67
     *
68
     */
69 9
    public function getName(): string
70
    {
71 9
        return $this->name;
72
    }
73
74
    /**
75
     * return the invalid data submitted.
76
     *
77
     */
78 9
    public function getRecord(): array
79
    {
80 9
        return $this->record;
81
    }
82
}
83