InsertionException   A
last analyzed

↳ Parent: Project

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 68
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 createFromCsv() 0 7 1
A createFromValidator() 0 8 1
A getName() 0 4 1
A getRecord() 0 4 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.0.0
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\Exception;
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
 */
25
class InsertionException extends RuntimeException
26
{
27
    /**
28
     * The record submitted for insertion
29
     *
30
     * @var array
31
     */
32
    protected $record;
33
34
    /**
35
     * Validator which did not validated the data
36
     *
37
     * @var string
38
     */
39
    protected $name = '';
40
41
    /**
42
     * Create an Exception from a record insertion
43
     *
44
     * @param string[] $record
45
     *
46
     * @return self
47
     */
48 2
    public static function createFromCsv(array $record): self
49
    {
50 2
        $exception = new static('Unable to write record to the CSV document');
51 2
        $exception->record = $record;
52
53 2
        return $exception;
54
    }
55
56
    /**
57
     * Create an Exception from a Record Validation
58
     *
59
     * @param string   $name   validator name
60
     * @param string[] $record invalid  data
61
     *
62
     * @return self
63
     */
64 6
    public static function createFromValidator(string $name, array $record): self
65
    {
66 6
        $exception = new static('Record validation failed');
67 6
        $exception->name = $name;
68 6
        $exception->record = $record;
69
70 6
        return $exception;
71
    }
72
73
    /**
74
     * return the validator name
75
     *
76
     * @return string
77
     */
78 2
    public function getName(): string
79
    {
80 2
        return $this->name;
81
    }
82
83
    /**
84
     * return the invalid data submitted
85
     *
86
     * @return array
87
     */
88 4
    public function getRecord(): array
89
    {
90 4
        return $this->record;
91
    }
92
}
93