AbstractCsv.php
2 months ago
ByteSequence.php
2 months ago
CannotInsertRecord.php
2 months ago
CharsetConverter.php
2 months ago
ColumnConsistency.php
2 months ago
EncloseField.php
2 months ago
EscapeFormula.php
2 months ago
Exception.php
2 months ago
HTMLConverter.php
2 months ago
Info.php
2 months ago
InvalidArgument.php
2 months ago
MapIterator.php
2 months ago
RFC4180Field.php
2 months ago
Reader.php
2 months ago
ResultSet.php
2 months ago
Statement.php
2 months ago
Stream.php
2 months ago
SyntaxError.php
2 months ago
TabularDataReader.php
2 months ago
UnableToProcessCsv.php
2 months ago
UnavailableFeature.php
2 months ago
UnavailableStream.php
2 months ago
Writer.php
2 months ago
XMLConverter.php
2 months ago
functions.php
2 months ago
functions_include.php
2 months ago
ColumnConsistency.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * League.Csv (https://csv.thephpleague.com) |
| 5 | * |
| 6 | * (c) Ignace Nyamagana Butera <nyamsprod@gmail.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | declare (strict_types=1); |
| 12 | namespace ProfilePressVendor\League\Csv; |
| 13 | |
| 14 | use function count; |
| 15 | /** |
| 16 | * Validates column consistency when inserting records into a CSV document. |
| 17 | */ |
| 18 | class ColumnConsistency |
| 19 | { |
| 20 | protected int $columns_count; |
| 21 | /** |
| 22 | * @throws InvalidArgument if the column count is lesser than -1 |
| 23 | */ |
| 24 | public function __construct(int $columns_count = -1) |
| 25 | { |
| 26 | if ($columns_count < -1) { |
| 27 | throw InvalidArgument::dueToInvalidColumnCount($columns_count, __METHOD__); |
| 28 | } |
| 29 | $this->columns_count = $columns_count; |
| 30 | } |
| 31 | /** |
| 32 | * Returns the column count. |
| 33 | */ |
| 34 | public function getColumnCount(): int |
| 35 | { |
| 36 | return $this->columns_count; |
| 37 | } |
| 38 | /** |
| 39 | * Tell whether the submitted record is valid. |
| 40 | */ |
| 41 | public function __invoke(array $record): bool |
| 42 | { |
| 43 | $count = count($record); |
| 44 | if (-1 === $this->columns_count) { |
| 45 | $this->columns_count = $count; |
| 46 | return \true; |
| 47 | } |
| 48 | return $count === $this->columns_count; |
| 49 | } |
| 50 | } |
| 51 |