Skip to content

Commit

Permalink
Adding a LogicException class
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Mar 1, 2017
1 parent d1e8c0f commit c6e36ed
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 27 deletions.
97 changes: 77 additions & 20 deletions CHANGELOG.md
Expand Up @@ -2,34 +2,91 @@

All Notable changes to `Csv` will be documented in this file

## Next
## 9.0.0 - TBD

### Added

- None
- `League\Csv\Statement`
- `League\Csv\RecordSet`
- `League\Csv\Exception\CsvException`
- `League\Csv\Exception\InsertionException`
- `League\Csv\Exception\InvalidArgumentException`
- `League\Csv\Exception\LogicException`
- `League\Csv\Exception\RuntimeException`
- `League\Csv\Reader::getHeader`
- `League\Csv\Reader::getHeaderOffset`
- `League\Csv\Reader::setHeaderOffset`
- `League\Csv\Reader::select`
- `League\Csv\Writer::setFlushThreshold`
- `League\Csv\Writer::getFlushThreshold`

### Deprecated

- Nothing

### Fixed

- None
- `League\Csv\Writer::insertOne` only accept an array and returns a integer
- `League\Csv\Writer::insertAll` only accept an iterable of array and returns an integer

### Removed

- PHP5 support
- `examples` directory
- `League\Csv\AbstractCsv::jsonSerialize`
- `League\Csv\AbstractCsv::toHTML`
- `League\Csv\AbstractCsv::toXML`
- `League\Csv\AbstractCsv::stripBom`
- `League\Csv\Reader::fetch`
- `League\Csv\AbstractCsv::addFilter`
- `League\Csv\AbstractCsv::addSortBy`
- `League\Csv\AbstractCsv::setOffset`
- `League\Csv\AbstractCsv::setLimit`
- `League\Csv\AbstractCsv::isActiveStreamFilter`
- `League\Csv\AbstractCsv::setStreamFilterMode`
- `League\Csv\AbstractCsv::getStreamFilterMode`
- `League\Csv\AbstractCsv::appendStreamFilter`
- `League\Csv\AbstractCsv::prependStreamFilter`
- `League\Csv\AbstractCsv::removeStreamFilter`
- `League\Csv\AbstractCsv::clearStreamFilters`
- `League\Csv\AbstractCsv::setInputEncoding`
- `League\Csv\AbstractCsv::getInputEncoding`
- `League\Csv\Exception\InvalidRowException`
- `League\Csv\Reader::each`
- `League\Csv\Reader::fetchPairsWithoutDuplicates`
- `League\Csv\Reader::fetch`
- `League\Csv\Reader::fetchAll`
- `League\Csv\Reader::fetchAssoc`
- `League\Csv\Writer::removeFormatter`
- `League\Csv\Reader::fetchColumn`
- `League\Csv\Reader::fetchPairs`
- `League\Csv\Reader::fetchPairsWithoutDuplicates`
- `League\Csv\Reader::getNewline`
- `League\Csv\Reader::setNewline`
- `League\Csv\Writer::hasFormatter`
- `League\Csv\Writer::removeFormatter`
- `League\Csv\Writer::clearFormatters`
- `League\Csv\Writer::removeValidator`
- `League\Csv\Writer::hasValidator`
- `League\Csv\Writer::removeValidator`
- `League\Csv\Writer::clearValidators`
- `League\Csv\Writer::jsonSerialize`
- `League\Csv\Writer::toHTML`
- `League\Csv\Writer::toXML`
- `League\Csv\Writer::getIterator`
- `League\Csv\Writer::fetchDelimitersOccurrence`

## 8.2.1 - 2017-02-22

### Added

- Nothing

### Deprecated

- Nothing

### Fixed

- internal `Reader::getRow` when using a `StreamIterator` [issue #213](https://github.com/thephpleague/csv/issues/213)
- Removed `@deprecated` from selected methods [issue #208](https://github.com/thephpleague/csv/issues/213)

### Removed

- Nothing

## 8.2.0 - 2017-01-25

Expand Down Expand Up @@ -64,21 +121,21 @@ All Notable changes to `Csv` will be documented in this file

### Fixed

- None
- Nothing

### Removed

- None
- Nothing

## 8.1.2 - 2016-10-27

### Added

- None
- Nothing

### Deprecated

- None
- Nothing

### Fixed

Expand All @@ -87,17 +144,17 @@ All Notable changes to `Csv` will be documented in this file

### Removed

- None
- Nothing

## 8.1.1 - 2016-09-05

### Added

- None
- Nothing

### Deprecated

- None
- Nothing

### Fixed

Expand All @@ -107,7 +164,7 @@ All Notable changes to `Csv` will be documented in this file

### Removed

- None
- Nothing

## 8.1.0 - 2016-05-31

Expand All @@ -129,7 +186,7 @@ All Notable changes to `Csv` will be documented in this file

### Removed

- None
- Nothing

## 8.0.0 - 2015-12-11

Expand All @@ -140,7 +197,7 @@ All Notable changes to `Csv` will be documented in this file

### Deprecated

- None
- Nothing

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion src/AbstractCsv.php
Expand Up @@ -14,8 +14,8 @@

namespace League\Csv;

use League\Csv\Exception\LogicException;
use League\Csv\Exception\RuntimeException;
use LogicException;
use SplFileObject;

/**
Expand Down
27 changes: 27 additions & 0 deletions src/Exception/LogicException.php
@@ -0,0 +1,27 @@
<?php
/**
* This file is part of the League.csv library
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
* @version 9.0.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace League\Csv\Exception;

/**
* Thrown when there is an error in the program logic
*
* @package League.csv
* @since 9.0.0
* @author Ignace Nyamagana Butera <nyamsprod@gmail.com>
*
*/
class LogicException extends \LogicException implements CsvException
{
}
9 changes: 5 additions & 4 deletions src/RecordSet.php
Expand Up @@ -23,6 +23,7 @@
use IteratorAggregate;
use JsonSerializable;
use League\Csv\Exception\InvalidArgumentException;
use League\Csv\Exception\RuntimeException;
use LimitIterator;

/**
Expand Down Expand Up @@ -287,7 +288,7 @@ public function fetchOne(int $offset = 0): array
*/
public function fetchColumn($index = 0): Generator
{
$offset = $this->getColumnIndex($index, 'the column index value is invalid');
$offset = $this->getColumnIndex($index, 'the column index `%s` value is invalid');
$filter = function (array $row) use ($offset) {
return isset($row[$offset]);
};
Expand All @@ -308,7 +309,7 @@ public function fetchColumn($index = 0): Generator
* @param string|int $field the field name or the field index
* @param string $error_message the associated error message
*
* @throws InvalidArgumentException if the field is invalid
* @throws RuntimeException if the field is invalid
*
* @return string|int
*/
Expand All @@ -319,7 +320,7 @@ protected function getColumnIndex($field, string $error_message)
}

if (!is_int($field)) {
throw new InvalidArgumentException($error_message);
throw new RuntimeException(sprintf($error_message, $field));
}

$index = $this->filterInteger($field, 0, $error_message);
Expand All @@ -329,7 +330,7 @@ protected function getColumnIndex($field, string $error_message)
return $index;
}

throw new InvalidArgumentException($error_message);
throw new RuntimeException(sprintf($error_message, $field));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/StreamIterator.php
Expand Up @@ -16,7 +16,7 @@

use Iterator;
use League\Csv\Exception\InvalidArgumentException;
use LogicException;
use League\Csv\Exception\LogicException;
use SplFileObject;

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/RecordSetTest.php
Expand Up @@ -3,6 +3,7 @@
namespace LeagueTest\Csv;

use DOMDocument;
use League\Csv\Exception\CsvException;
use League\Csv\Exception\InvalidArgumentException;
use League\Csv\Exception\RuntimeException;
use League\Csv\Reader;
Expand Down Expand Up @@ -190,7 +191,7 @@ public function testFetchColumnWithColumnIndex()
*/
public function testFetchColumnTriggersException($field)
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(CsvException::class);
$keys = ['firstname', 'lastname', 'email'];
$stmt = (new Statement())->columns($keys);
$res = $stmt->process($this->csv)->fetchColumn($field);
Expand Down

0 comments on commit c6e36ed

Please sign in to comment.