Polyfill
10 months ago
AbstractCsv.php
10 months ago
ByteSequence.php
10 months ago
CannotInsertRecord.php
10 months ago
CharsetConverter.php
10 months ago
ColumnConsistency.php
10 months ago
EncloseField.php
10 months ago
EscapeFormula.php
10 months ago
Exception.php
10 months ago
HTMLConverter.php
10 months ago
Info.php
10 months ago
InvalidArgument.php
10 months ago
MapIterator.php
10 months ago
RFC4180Field.php
10 months ago
Reader.php
10 months ago
ResultSet.php
10 months ago
Statement.php
10 months ago
Stream.php
10 months ago
SyntaxError.php
10 months ago
TabularDataReader.php
10 months ago
UnableToProcessCsv.php
10 months ago
UnavailableFeature.php
10 months ago
UnavailableStream.php
10 months ago
Writer.php
10 months ago
XMLConverter.php
10 months ago
functions.php
10 months ago
functions_include.php
10 months ago
ColumnConsistency.php
59 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 | /** |
| 22 | * The number of column per record. |
| 23 | * |
| 24 | * @var int |
| 25 | */ |
| 26 | protected $columns_count; |
| 27 | /** |
| 28 | * New Instance. |
| 29 | * |
| 30 | * @throws InvalidArgument if the column count is lesser than -1 |
| 31 | */ |
| 32 | public function __construct(int $columns_count = -1) |
| 33 | { |
| 34 | if ($columns_count < -1) { |
| 35 | throw InvalidArgument::dueToInvalidColumnCount($columns_count, __METHOD__); |
| 36 | } |
| 37 | $this->columns_count = $columns_count; |
| 38 | } |
| 39 | /** |
| 40 | * Returns the column count. |
| 41 | */ |
| 42 | public function getColumnCount() : int |
| 43 | { |
| 44 | return $this->columns_count; |
| 45 | } |
| 46 | /** |
| 47 | * Tell whether the submitted record is valid. |
| 48 | */ |
| 49 | public function __invoke(array $record) : bool |
| 50 | { |
| 51 | $count = count($record); |
| 52 | if (-1 === $this->columns_count) { |
| 53 | $this->columns_count = $count; |
| 54 | return \true; |
| 55 | } |
| 56 | return $count === $this->columns_count; |
| 57 | } |
| 58 | } |
| 59 |