PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.2.2
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.2.2
2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 All 67 releases
better-payment / vendor / league / csv / src / ColumnConsistency.php

ColumnConsistency.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.2.2, at vendor/league/csv/src/ColumnConsistency.php

60 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 use function count;
17
18 /**
19 * Validates column consistency when inserting records into a CSV document.
20 */
21 class ColumnConsistency
22 {
23 protected int $columns_count;
24
25 /**
26 * @throws InvalidArgument if the column count is lesser than -1
27 */
28 public function __construct(int $columns_count = -1)
29 {
30 if ($columns_count < -1) {
31 throw InvalidArgument::dueToInvalidColumnCount($columns_count, __METHOD__);
32 }
33
34 $this->columns_count = $columns_count;
35 }
36
37 /**
38 * Returns the column count.
39 */
40 public function getColumnCount(): int
41 {
42 return $this->columns_count;
43 }
44
45 /**
46 * Tell whether the submitted record is valid.
47 */
48 public function __invoke(array $record): bool
49 {
50 $count = count($record);
51 if (-1 === $this->columns_count) {
52 $this->columns_count = $count;
53
54 return true;
55 }
56
57 return $count === $this->columns_count;
58 }
59 }
60