CannotInsertRecord   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
dl 0
loc 66
ccs 9
cts 13
cp 0.6923
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

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