AbstractCsv.php
4 days ago
ByteSequence.php
4 days ago
CannotInsertRecord.php
4 days ago
CharsetConverter.php
4 days ago
ColumnConsistency.php
4 days ago
EncloseField.php
4 days ago
EscapeFormula.php
4 days ago
Exception.php
9 months ago
HTMLConverter.php
4 days ago
Info.php
4 days ago
InvalidArgument.php
9 months ago
MapIterator.php
4 days ago
RFC4180Field.php
4 days ago
Reader.php
4 days ago
ResultSet.php
4 days ago
Statement.php
4 days ago
Stream.php
4 days ago
SyntaxError.php
4 days ago
TabularDataReader.php
4 days ago
UnableToProcessCsv.php
9 months ago
UnavailableFeature.php
9 months ago
UnavailableStream.php
9 months ago
Writer.php
4 days ago
XMLConverter.php
4 days ago
functions.php
9 months ago
functions_include.php
9 months ago
ColumnConsistency.php
52 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 IAWPSCOPED\League\Csv; |
| 13 | |
| 14 | use function count; |
| 15 | /** |
| 16 | * Validates column consistency when inserting records into a CSV document. |
| 17 | * @internal |
| 18 | */ |
| 19 | class ColumnConsistency |
| 20 | { |
| 21 | protected int $columns_count; |
| 22 | /** |
| 23 | * @throws InvalidArgument if the column count is lesser than -1 |
| 24 | */ |
| 25 | public function __construct(int $columns_count = -1) |
| 26 | { |
| 27 | if ($columns_count < -1) { |
| 28 | throw InvalidArgument::dueToInvalidColumnCount($columns_count, __METHOD__); |
| 29 | } |
| 30 | $this->columns_count = $columns_count; |
| 31 | } |
| 32 | /** |
| 33 | * Returns the column count. |
| 34 | */ |
| 35 | public function getColumnCount() : int |
| 36 | { |
| 37 | return $this->columns_count; |
| 38 | } |
| 39 | /** |
| 40 | * Tell whether the submitted record is valid. |
| 41 | */ |
| 42 | public function __invoke(array $record) : bool |
| 43 | { |
| 44 | $count = count($record); |
| 45 | if (-1 === $this->columns_count) { |
| 46 | $this->columns_count = $count; |
| 47 | return \true; |
| 48 | } |
| 49 | return $count === $this->columns_count; |
| 50 | } |
| 51 | } |
| 52 |