Skip to content

Commit cf54169

Browse files
committed
remove deprecated methods
1 parent 9dfd08b commit cf54169

File tree

13 files changed

+122
-245
lines changed

13 files changed

+122
-245
lines changed

CHANGELOG.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ All Notable changes to `League\Csv` will be documented in this file
66
### Added
77
- Stream Filter API in `League\Csv\AbstractCsv`
88
- named constructors `createFromPath` and `createFromFileObject` in `League\Csv\AbstractCsv` to ease CSV object instantiation
9-
- `detectDelimiters` in `League\Csv\AbstractCsv` to replace and remove the use of `Exception` in `detectDelimiter`
10-
- `setEncodingFrom` and `setDecodingFrom` in `League\Csv\AbstractCsv`
9+
- `detectDelimiterList` in `League\Csv\AbstractCsv` to replace and remove the use of `Exception` in `detectDelimiter`
10+
- `setEncodingFrom` and `setDecodingFrom` in `League\Csv\AbstractCsv` to replace `setEncoding` and `getEncoding` for naming consistency
1111

1212
### Deprecated
13-
- `detectDelimiter` in `League\Csv\AbstractCsv` in favor of `detectDelimiters`
14-
- `setEncoding` and `getEncoding` in `League\Csv\AbstractCsv` replaced by `setEncodingFrom` and `setDecodingFrom` for naming consistency
13+
- Nothing
1514

1615
### Fixed
1716
- `League\Csv\Reader::each` more stric `$callable` MUST returns true
1817

1918
### Remove
20-
- Nothing
19+
- `detectDelimiter`
20+
- `setEncoding` and `getEncoding`
21+
- `League\Csv\Reader::setSortBy`
22+
- `League\Csv\Reader::setFilter`
2123

2224
### Security
2325
- Nothing
@@ -126,7 +128,7 @@ All Notable changes to `League\Csv` will be documented in this file
126128
- Nothing
127129

128130
### Remove
129-
- Change namespace from `Bakame\Csv` to `League\Csv`
131+
- Nothing
130132

131133
### Security
132134
- Nothing

src/AbstractCsv.php

Lines changed: 13 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44
*
55
* @license http://opensource.org/licenses/MIT
66
* @link https://github.com/thephpleague/csv/
7-
* @version 5.5.0
7+
* @version 6.0.0
88
* @package League.csv
99
*
1010
* For the full copyright and license information, please view the LICENSE
1111
* file that was distributed with this source code.
1212
*/
1313
namespace League\Csv;
1414

15-
use CallbackFilterIterator;
1615
use DomDocument;
1716
use InvalidArgumentException;
1817
use IteratorAggregate;
1918
use JsonSerializable;
2019
use League\Csv\Config\Controls;
2120
use League\Csv\Config\StreamFilter;
22-
use LimitIterator;
23-
use RuntimeException;
2421
use SplFileInfo;
2522
use SplFileObject;
2623
use SplTempFileObject;
@@ -243,86 +240,6 @@ public function newReader($open_mode = 'r+')
243240
return $this->newInstance('\League\Csv\Reader', $open_mode);
244241
}
245242

246-
/**
247-
* detect the actual number of row according to a delimiter
248-
*
249-
* @param string $delimiter a CSV delimiter
250-
* @param integer $nb_rows the number of row to consider
251-
*
252-
* @return integer
253-
*/
254-
protected function fetchRowsCountByDelimiter($delimiter, $nb_rows = 1)
255-
{
256-
$iterator = $this->getIterator();
257-
$iterator->setCsvControl($delimiter, $this->enclosure, $this->escape);
258-
//"reduce" the csv length to a maximum of $nb_rows
259-
$iterator = new LimitIterator($iterator, 0, $nb_rows);
260-
//return the parse rows
261-
$iterator = new CallbackFilterIterator($iterator, function ($row) {
262-
return is_array($row) && count($row) > 1;
263-
});
264-
265-
return count(iterator_to_array($iterator, false));
266-
}
267-
268-
/**
269-
* Detect the CSV file delimiter
270-
*
271-
* @param integer $nb_rows
272-
* @param string[] $delimiters additional delimiters
273-
*
274-
* @return string[]
275-
*
276-
* @throws \InvalidArgumentException If $nb_rows value is invalid
277-
*/
278-
public function detectDelimiters($nb_rows = 1, array $delimiters = [])
279-
{
280-
$nb_rows = filter_var($nb_rows, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
281-
if (! $nb_rows) {
282-
throw new InvalidArgumentException('`$nb_rows` must be a valid positive integer');
283-
}
284-
285-
$delimiters = array_filter($delimiters, function ($str) {
286-
return 1 == mb_strlen($str);
287-
});
288-
$delimiters = array_merge([$this->delimiter, ',', ';', "\t"], $delimiters);
289-
$delimiters = array_unique($delimiters);
290-
$res = array_fill_keys($delimiters, 0);
291-
array_walk($res, function (&$value, $delim) use ($nb_rows) {
292-
$value = $this->fetchRowsCountByDelimiter($delim, $nb_rows);
293-
});
294-
295-
arsort($res, SORT_NUMERIC);
296-
297-
return array_keys(array_filter($res));
298-
}
299-
300-
/**
301-
* DEPRECATION WARNING! This method will be removed in the next major point release
302-
*
303-
* @deprecated deprecated since version 5.5
304-
*
305-
* Detect the CSV file delimiter
306-
*
307-
* @param integer $nb_rows
308-
* @param string[] $delimiters additional delimiters
309-
*
310-
* @return null|string
311-
*
312-
* @throws \InvalidArgumentException If $nb_rows value is invalid
313-
* @throws \RuntimeException If too many delimiters are found
314-
*/
315-
public function detectDelimiter($nb_rows = 1, array $delimiters = [])
316-
{
317-
$res = $this->detectDelimiters($nb_rows, $delimiters);
318-
if (! $res) {
319-
return null;
320-
} elseif (1 == count($res)) {
321-
return $res[0];
322-
}
323-
throw new RuntimeException('too many delimiters were found: `'.implode('`,`', $res).'`');
324-
}
325-
326243
/**
327244
* Return the CSV Iterator
328245
*
@@ -430,4 +347,16 @@ public function toHTML($class_name = 'table-csv-data')
430347

431348
return $doc->saveHTML($doc->documentElement);
432349
}
350+
351+
/**
352+
* Validate a variable to be stringable
353+
*
354+
* @param mixed $str
355+
*
356+
* @return boolean
357+
*/
358+
public static function isValidString($str)
359+
{
360+
return is_scalar($str) || (is_object($str) && method_exists($str, '__toString'));
361+
}
433362
}

src/Config/Controls.php

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
*
55
* @license http://opensource.org/licenses/MIT
66
* @link https://github.com/thephpleague/csv/
7-
* @version 5.5.0
7+
* @version 6.0.0
88
* @package League.csv
99
*
1010
* For the full copyright and license information, please view the LICENSE
1111
* file that was distributed with this source code.
1212
*/
1313
namespace League\Csv\Config;
1414

15+
use CallbackFilterIterator;
1516
use InvalidArgumentException;
1617
use League\Csv\Iterator\MapIterator;
18+
use LimitIterator;
1719
use SplFileObject;
1820
use Traversable;
1921

@@ -66,7 +68,7 @@ trait Controls
6668
*
6769
* @param string $delimiter
6870
*
69-
* @return self
71+
* @return $this
7072
*
7173
* @throws \InvalidArgumentException If $delimeter is not a single character
7274
*/
@@ -90,12 +92,73 @@ public function getDelimiter()
9092
return $this->delimiter;
9193
}
9294

95+
/**
96+
* detect the actual number of row according to a delimiter
97+
*
98+
* @param string $delimiter a CSV delimiter
99+
* @param integer $nb_rows the number of row to consider
100+
*
101+
* @return integer
102+
*/
103+
protected function fetchRowsCountByDelimiter($delimiter, $nb_rows = 1)
104+
{
105+
$iterator = $this->getIterator();
106+
$iterator->setCsvControl($delimiter, $this->enclosure, $this->escape);
107+
//"reduce" the csv length to a maximum of $nb_rows
108+
$iterator = new LimitIterator($iterator, 0, $nb_rows);
109+
//return the parse rows
110+
$iterator = new CallbackFilterIterator($iterator, function ($row) {
111+
return is_array($row) && count($row) > 1;
112+
});
113+
114+
return count(iterator_to_array($iterator, false));
115+
}
116+
117+
/**
118+
* Detect the CSV file delimiter
119+
*
120+
* @param integer $nb_rows
121+
* @param string[] $delimiters additional delimiters
122+
*
123+
* @return string[]
124+
*
125+
* @throws \InvalidArgumentException If $nb_rows value is invalid
126+
*/
127+
public function detectDelimiterList($nb_rows = 1, array $delimiters = [])
128+
{
129+
$nb_rows = filter_var($nb_rows, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
130+
if (! $nb_rows) {
131+
throw new InvalidArgumentException('`$nb_rows` must be a valid positive integer');
132+
}
133+
134+
$delimiters = array_filter($delimiters, function ($str) {
135+
return 1 == mb_strlen($str);
136+
});
137+
$delimiters = array_merge([$this->delimiter, ',', ';', "\t"], $delimiters);
138+
$delimiters = array_unique($delimiters);
139+
$res = array_fill_keys($delimiters, 0);
140+
array_walk($res, function (&$value, $delim) use ($nb_rows) {
141+
$value = $this->fetchRowsCountByDelimiter($delim, $nb_rows);
142+
});
143+
144+
arsort($res, SORT_NUMERIC);
145+
146+
return array_keys(array_filter($res));
147+
}
148+
149+
/**
150+
* return a SplFileOjbect
151+
*
152+
* @return \SplFileOjbect
153+
*/
154+
abstract public function getIterator();
155+
93156
/**
94157
* set the field enclosure
95158
*
96159
* @param string $enclosure
97160
*
98-
* @return self
161+
* @return $this
99162
*
100163
* @throws \InvalidArgumentException If $enclosure is not a single character
101164
*/
@@ -124,7 +187,7 @@ public function getEnclosure()
124187
*
125188
* @param string $escape
126189
*
127-
* @return self
190+
* @return $this
128191
*
129192
* @throws \InvalidArgumentException If $escape is not a single character
130193
*/
@@ -153,7 +216,7 @@ public function getEscape()
153216
*
154217
* @param integer $flags
155218
*
156-
* @return self
219+
* @return $this
157220
*
158221
* @throws \InvalidArgumentException If the argument is not a valid integer
159222
*/
@@ -178,38 +241,12 @@ public function getFlags()
178241
return $this->flags;
179242
}
180243

181-
/**
182-
* DEPRECATION WARNING! This method will be removed in the next major point release
183-
*
184-
* @deprecated deprecated since version 5.5
185-
*
186-
* @param string $str
187-
*
188-
* @return static The invoked object
189-
*/
190-
public function setEncoding($str)
191-
{
192-
return $this->setEncodingFrom($str);
193-
}
194-
195-
/**
196-
* DEPRECATION WARNING! This method will be removed in the next major point release
197-
*
198-
* @deprecated deprecated since version 5.5
199-
*
200-
* @return string
201-
*/
202-
public function getEncoding()
203-
{
204-
return $this->getEncodingFrom();
205-
}
206-
207244
/**
208245
* Set the CSV encoding charset
209246
*
210247
* @param string $str
211248
*
212-
* @return self
249+
* @return $this
213250
*/
214251
public function setEncodingFrom($str)
215252
{
@@ -253,16 +290,4 @@ protected function convertToUtf8(Traversable $iterator)
253290
return $row;
254291
});
255292
}
256-
257-
/**
258-
* Validate a variable to be stringable
259-
*
260-
* @param mixed $str
261-
*
262-
* @return boolean
263-
*/
264-
public static function isValidString($str)
265-
{
266-
return is_scalar($str) || (is_object($str) && method_exists($str, '__toString'));
267-
}
268293
}

src/Config/StreamFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @license http://opensource.org/licenses/MIT
66
* @link https://github.com/thephpleague/csv/
7-
* @version 5.5.0
7+
* @version 6.0.0
88
* @package League.csv
99
*
1010
* For the full copyright and license information, please view the LICENSE

0 commit comments

Comments
 (0)