Skip to content

Commit

Permalink
Improve Deprecated attribute usage in the package
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 23, 2024
1 parent 3cfd85f commit b063031
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 59 deletions.
12 changes: 6 additions & 6 deletions src/AbstractCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public function addStreamFilter(string $filtername, null|array $params = null):
*
* Returns the stream filter mode.
*/
#[Deprecated(message:'Use AbstractCsv::supportsStreamFilterOnRead or AbstractCsv::supportsStreamFilterOnWrite instead', since:'league/csv:9.7.0')]
#[Deprecated(message:'use League\Csv\AbstractCsv::supportsStreamFilterOnRead() or League\Csv\AbstractCsv::supportsStreamFilterOnWrite() instead', since:'league/csv:9.7.0')]
public function getStreamFilterMode(): int
{
return static::STREAM_FILTER_MODE;
Expand All @@ -416,7 +416,7 @@ public function getStreamFilterMode(): int
*
* Tells whether the stream filter capabilities can be used.
*/
#[Deprecated(message:'Use AbstractCsv::supportsStreamFilterOnRead or AbstractCsv::supportsStreamFilterOnWrite instead', since:'league/csv:9.7.0')]
#[Deprecated(message:'use League\Csv\AbstractCsv::supportsStreamFilterOnRead() or League\Csv\AbstractCsv::supportsStreamFilterOnWrite() instead', since:'league/csv:9.7.0')]
public function supportsStreamFilter(): bool
{
return $this->document instanceof Stream;
Expand All @@ -431,7 +431,7 @@ public function supportsStreamFilter(): bool
* @see AbstractCsv::toString
* @codeCoverageIgnore
*/
#[Deprecated(message:'Use AbstractCsv::toString instead', since:'league/csv:9.7.0')]
#[Deprecated(message:'use League\Csv\AbstractCsv::toString() instead', since:'league/csv:9.7.0')]
public function getContent(): string
{
return $this->toString();
Expand All @@ -446,7 +446,7 @@ public function getContent(): string
*
* Retrieves the CSV content
*/
#[Deprecated(message:'Use AbstractCsv::toString instead', since:'league/csv:9.1.0')]
#[Deprecated(message:'use League\Csv\AbstractCsv::toString() instead', since:'league/csv:9.1.0')]
public function __toString(): string
{
return $this->toString();
Expand All @@ -467,7 +467,7 @@ public function __toString(): string
* @deprecated since version 9.17.0
* @see https://tools.ietf.org/html/rfc6266#section-4.3
*/
#[Deprecated(message:'Use HttpHeaders::forFileDownload instead', since:'league/csv:9.17.0')]
#[Deprecated(message:'the method no longer affect the outcome of the class, use League\Csv\HttpHeaders::forFileDownload instead', since:'league/csv:9.17.0')]
protected function sendHeaders(string $filename): void
{
if (strlen($filename) !== strcspn($filename, '\\/')) {
Expand Down Expand Up @@ -507,7 +507,7 @@ protected function sendHeaders(string $filename): void
*
* @throws Exception
*/
#[Deprecated(message:'Use AbstractCsv::download instead', since:'league/csv:9.18.0')]
#[Deprecated(message:'use League\Csv\AbstractCsv::download() instead', since:'league/csv:9.18.0')]
public function output(?string $filename = null): int
{
try {
Expand Down
10 changes: 5 additions & 5 deletions src/ByteSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
*/
interface ByteSequence
{
#[Deprecated(message: 'Use Bom:Utf8 instead', since: 'league/csv:9.16.0')]
#[Deprecated(message: 'use League\Csv\Bom:Utf8 instead', since: 'league/csv:9.16.0')]
public const BOM_UTF8 = "\xEF\xBB\xBF";
#[Deprecated(message: 'Use Bom:Utf16be instead', since: 'league/csv:9.16.0')]
#[Deprecated(message: 'use League\Csv\Bom:Utf16be instead', since: 'league/csv:9.16.0')]
public const BOM_UTF16_BE = "\xFE\xFF";
#[Deprecated(message: 'Use Bom:Utf16Le instead', since: 'league/csv:9.16.0')]
#[Deprecated(message: 'use League\Csv\Bom:Utf16Le instead', since: 'league/csv:9.16.0')]
public const BOM_UTF16_LE = "\xFF\xFE";
#[Deprecated(message: 'Use Bom:Utf32Be instead', since: 'league/csv:9.16.0')]
#[Deprecated(message: 'use League\Csv\Bom:Utf32Be instead', since: 'league/csv:9.16.0')]
public const BOM_UTF32_BE = "\x00\x00\xFE\xFF";
#[Deprecated(message: 'Use Bom:Utf32Le instead', since: 'league/csv:9.16.0')]
#[Deprecated(message: 'use League\Csv\Bom:Utf32Le instead', since: 'league/csv:9.16.0')]
public const BOM_UTF32_LE = "\xFF\xFE\x00\x00";
}
7 changes: 2 additions & 5 deletions src/EncloseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*/
class EncloseField extends php_user_filter
{
#[Deprecated(message: 'use League\Csv\Writer::forceEnclosure() instead', since: 'league/csv:9.10.0')]
public const FILTERNAME = 'convert.league.csv.enclosure';

/** Default sequence. */
Expand All @@ -50,7 +51,6 @@ class EncloseField extends php_user_filter
/**
* Static method to return the stream filter filtername.
*/
#[Deprecated(message: 'Use Writer::forceEnclosure instead', since: 'league/csv:9.10.0')]
public static function getFiltername(): string
{
return self::FILTERNAME;
Expand All @@ -59,7 +59,6 @@ public static function getFiltername(): string
/**
* Static method to register the class as a stream filter.
*/
#[Deprecated(message: 'Use Writer::forceEnclosure instead', since: 'league/csv:9.10.0')]
public static function register(): void
{
if (!in_array(self::FILTERNAME, stream_get_filters(), true)) {
Expand All @@ -73,7 +72,6 @@ public static function register(): void
* @throws InvalidArgumentException if the sequence is malformed
* @throws Exception
*/
#[Deprecated(message: 'Use Writer::forceEnclosure instead', since: 'league/csv:9.10.0')]
public static function addTo(Writer $csv, string $sequence): Writer
{
self::register();
Expand All @@ -97,7 +95,7 @@ protected static function isValidSequence(string $sequence): bool
return strlen($sequence) !== strcspn($sequence, self::$force_enclosure);
}

#[Deprecated(message: 'Use Writer::forceEnclosure instead', since: 'league/csv:9.10.0')]
#[Deprecated(message: 'use League\Csv\Writer::forceEnclosure() instead', since: 'league/csv:9.10.0')]
public function onCreate(): bool
{
return is_array($this->params)
Expand All @@ -110,7 +108,6 @@ public function onCreate(): bool
* @param resource $out
* @param int $consumed
*/
#[Deprecated(message: 'Use Writer::forceEnclosure instead', since: 'league/csv:9.10.0')]
public function filter($in, $out, &$consumed, bool $closing): int
{
/** @var array $params */
Expand Down
2 changes: 1 addition & 1 deletion src/EscapeFormula.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected function isStringable(mixed $value): bool
*
* @see escapeRecord
*/
#[Deprecated(message:'use EscapeFormula::escapeRecord instead', since:'league/csv:9.11.0')]
#[Deprecated(message:'use League\Csv\EscapeFormula::escapeRecord() instead', since:'league/csv:9.11.0')]
public function __invoke(array $record): array
{
return $this->escapeRecord($record);
Expand Down
1 change: 0 additions & 1 deletion src/HTMLConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public static function create(): self
* @see HTMLConverter::create()
* @deprecated since version 9.7.0
*/
#[Deprecated(message:'use HTMLConverter::create instead', since:'league/csv:9.7.0')]
public function __construct()
{
$this->xml_converter = XMLConverter::create()
Expand Down
2 changes: 1 addition & 1 deletion src/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class Info implements ByteSequence
* @see Bom::tryFromSequence()
* @codeCoverageIgnore
*/
#[Deprecated(message:'use Bom::tryFromSequence instead', since:'league/csv:9.16.0')]
#[Deprecated(message:'use League\Csv\Bom::tryFromSequence() instead', since:'league/csv:9.16.0')]
public static function fetchBOMSequence(string $str): ?string
{
return Bom::tryFromSequence($str)?->value;
Expand Down
1 change: 0 additions & 1 deletion src/InvalidArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class InvalidArgument extends Exception
*
* @deprecated since version 9.7.0
*/
#[Deprecated(message:'use its named constructor instead', since:'league/csv:9.7.0')]
public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
Expand Down
2 changes: 1 addition & 1 deletion src/JsonConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public function convert(iterable $records): Iterator
*
* @param int<1, max> $indentSize
*/
#[Deprecated(message:'Use JsonConverter::withPrettyPrint instead', since:'league/csv:9.19.0')]
#[Deprecated(message:'use League\Csv\JsonConverter::withPrettyPrint() instead', since:'league/csv:9.19.0')]
public function indentSize(int $indentSize): self
{
return match ($indentSize) {
Expand Down
9 changes: 3 additions & 6 deletions src/RFC4180Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
*/
class RFC4180Field extends php_user_filter
{
#[Deprecated(message: 'use League\Csv\Reader::setEscape or League\Csv\Writer::setEscape instead', since: 'league/csv:9.2.0')]
public const FILTERNAME = 'convert.league.csv.rfc4180';

/**
Expand All @@ -68,7 +69,6 @@ class RFC4180Field extends php_user_filter
/**
* Static method to add the stream filter to a {@link AbstractCsv} object.
*/
#[Deprecated(message: 'Use Reader::setEscape or Writer::setEscape instead', since: 'league/csv:9.2.0')]
public static function addTo(AbstractCsv $csv, string $whitespace_replace = ''): AbstractCsv
{
self::register();
Expand All @@ -91,7 +91,7 @@ public static function addTo(AbstractCsv $csv, string $whitespace_replace = ''):
* Add a formatter to the {@link Writer} object to format the record
* field to avoid enclosure around a field with an empty space.
*/
#[Deprecated(message: 'Use Reader::setEscape or Writer::setEscape instead', since: 'league/csv:9.2.0')]
#[Deprecated(message: 'use League\Csv\Reader::setEscape or League\Csv\Writer::setEscape instead', since: 'league/csv:9.2.0')]
public static function addFormatterTo(Writer $csv, string $whitespace_replace): Writer
{
if ('' == $whitespace_replace || strlen($whitespace_replace) !== strcspn($whitespace_replace, self::$force_enclosure)) {
Expand All @@ -108,7 +108,6 @@ public static function addFormatterTo(Writer $csv, string $whitespace_replace):
/**
* Static method to register the class as a stream filter.
*/
#[Deprecated(message: 'Use Reader::setEscape or Writer::setEscape instead', since: 'league/csv:9.2.0')]
public static function register(): void
{
if (!in_array(self::FILTERNAME, stream_get_filters(), true)) {
Expand All @@ -119,7 +118,6 @@ public static function register(): void
/**
* Static method to return the stream filter filtername.
*/
#[Deprecated(message: 'Use Reader::setEscape or Writer::setEscape instead', since: 'league/csv:9.2.0')]
public static function getFiltername(): string
{
return self::FILTERNAME;
Expand All @@ -130,7 +128,6 @@ public static function getFiltername(): string
* @param resource $out
* @param int $consumed
*/
#[Deprecated(message: 'Use Reader::setEscape or Writer::setEscape instead', since: 'league/csv:9.2.0')]
public function filter($in, $out, &$consumed, bool $closing): int
{
while (null !== ($bucket = stream_bucket_make_writeable($in))) {
Expand All @@ -142,7 +139,7 @@ public function filter($in, $out, &$consumed, bool $closing): int
return PSFS_PASS_ON;
}

#[Deprecated(message: 'Use Reader::setEscape or Writer::setEscape instead', since: 'league/csv:9.2.0')]
#[Deprecated(message: 'use League\Csv\Reader::setEscape or League\Csv\Writer::setEscape instead', since: 'league/csv:9.2.0')]
public function onCreate(): bool
{
if (!is_array($this->params)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ protected function combineHeader(Iterator $iterator, array $header): Iterator
* @deprecated since version 9.9.0
* @codeCoverageIgnore
*/
#[Deprecated(message:'Use Reader::nth instead', since:'league/csv:9.9.0')]
#[Deprecated(message:'use League\Csv\Reader::nth() instead', since:'league/csv:9.9.0')]
public function fetchOne(int $nth_record = 0): array
{
return $this->nth($nth_record);
Expand All @@ -635,7 +635,7 @@ public function fetchOne(int $nth_record = 0): array
* @throws MappingFailed
* @throws TypeCastingFailed
*/
#[Deprecated(message:'Use Reader::getRecordsAsObject instead', since:'league/csv:9.15.0')]
#[Deprecated(message:'use League\Csv\Reader::getRecordsAsObject() instead', since:'league/csv:9.15.0')]
public function getObjects(string $className, array $header = []): Iterator
{
return $this->getRecordsAsObject($className, $header);
Expand Down
4 changes: 2 additions & 2 deletions src/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public function fetchPairs($offset_index = 0, $value_index = 1): Iterator
* @deprecated since version 9.9.0
* @codeCoverageIgnore
*/
#[Deprecated(message:'Use Resultset::nth instead', since:'league/csv:9.9.0')]
#[Deprecated(message:'use League\Csv\Resultset::nth() instead', since:'league/csv:9.9.0')]
public function fetchOne(int $nth_record = 0): array
{
return $this->nth($nth_record);
Expand All @@ -567,7 +567,7 @@ public function fetchOne(int $nth_record = 0): array
* @throws MappingFailed
* @throws TypeCastingFailed
*/
#[Deprecated(message:'Use ResultSet::getRecordsAsObject instead', since:'league/csv:9.15.0')]
#[Deprecated(message:'use League\Csv\ResultSet::getRecordsAsObject() instead', since:'league/csv:9.15.0')]
public function getObjects(string $className, array $header = []): Iterator
{
return $this->getRecordsAsObject($className, $header);
Expand Down
16 changes: 6 additions & 10 deletions src/Serializer/AfterMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,22 @@ final class AfterMapping
public readonly MapRecord $mapRecord;
public readonly array $methods;

#[Deprecated(message: 'Use Leauge\Csv\Serializer\MapRecord instead', since: 'league/csv:9.17.0')]
#[Deprecated(message: 'use League\Csv\Serializer\MapRecord instead', since: 'league/csv:9.17.0')]
public function __construct(string ...$methods)
{
$this->mapRecord = new MapRecord($methods);
$this->methods = $this->mapRecord->afterMapping;
}

#[Deprecated(message: 'Use Leauge\Csv\Serializer\MapRecord instead', since: 'league/csv:9.17.0')]
public static function from(ReflectionClass $class): ?self
{
$attributes = $class->getAttributes(self::class, ReflectionAttribute::IS_INSTANCEOF);
$nbAttributes = count($attributes);
if (0 === $nbAttributes) {
return null;
}

if (1 < $nbAttributes) {
throw new MappingFailed('Using more than one `'.self::class.'` attribute on a class property or method is not supported.');
}

return $attributes[0]->newInstance();
return match (true) {
0 === $nbAttributes => null,
1 < $nbAttributes => throw new MappingFailed('Using more than one `'.self::class.'` attribute on a class property or method is not supported.'),
default => $attributes[0]->newInstance(),
};
}
}
2 changes: 1 addition & 1 deletion src/Serializer/CallbackCasting.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private static function getTypes(?ReflectionType $type): array
* @see CallbackCasting::unregisterType()
* @codeCoverageIgnore
*/
#[Deprecated(message:'Use CallbackCasting::unregisterType instead', since:'league/csv:9.13.0')]
#[Deprecated(message:'use League\Csv\Serializer\CallbackCasting::unregisterType() instead', since:'league/csv:9.13.0')]
public static function unregister(string $type): bool
{
return self::unregisterType($type);
Expand Down
4 changes: 2 additions & 2 deletions src/Serializer/Denormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(string $className, array $propertyNames = [])
*
* Enables converting empty string to the null value.
*/
#[Deprecated(message:'Use MapRecord::$convertEmptyStringToNull or MapCell::$convertEmptyStringToNullinstead', since:'league/csv:9.17.0')]
#[Deprecated(message:'use League\Csv\Serializer\MapRecord::$convertEmptyStringToNull or League\Csv\Serializer\MapCell::$convertEmptyStringToNullinstead', since:'league/csv:9.17.0')]
public static function allowEmptyStringAsNull(): void
{
self::$convertEmptyStringToNull = true;
Expand All @@ -80,7 +80,7 @@ public static function allowEmptyStringAsNull(): void
*
* Disables converting empty string to the null value.
*/
#[Deprecated(message:'Use MapRecord::$convertEmptyStringToNull or MapCell::$convertEmptyStringToNullinstead', since:'league/csv:9.17.0')]
#[Deprecated(message:'use League\Csv\Serializer\MapRecord::$convertEmptyStringToNull or League\Csv\Serializer\MapCell::$convertEmptyStringToNullinstead', since:'league/csv:9.17.0')]
public static function disallowEmptyStringAsNull(): void
{
self::$convertEmptyStringToNull = false;
Expand Down
8 changes: 4 additions & 4 deletions src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function process(TabularDataReader $tabular_data, array $header = []): Ta
* @see Statement::process()
* @deprecated Since version 9.16.0
*/
#[Deprecated(message:'Use Statement::process() instead', since:'league/csv:9.16.0')]
#[Deprecated(message:'this method no longer affects on the outcome of the class, use League\Csv\Statement::process() instead', since:'league/csv:9.16.0')]
protected function applySelect(Iterator $records, array $recordsHeader, array $select): TabularDataReader
{
$hasHeader = [] !== $recordsHeader;
Expand Down Expand Up @@ -380,7 +380,7 @@ protected function applySelect(Iterator $records, array $recordsHeader, array $s
* @deprecated Since version 9.15.0
* @codeCoverageIgnore
*/
#[Deprecated(message:'Use Statement::applyFilter() instead', since:'league/csv:9.15.0')]
#[Deprecated(message:'this method no longer affects on the outcome of the class, use League\Csv\Statement::applyFilter() instead', since:'league/csv:9.15.0')]
protected function filter(Iterator $iterator, callable $callable): CallbackFilterIterator
{
return new CallbackFilterIterator($iterator, $callable);
Expand All @@ -395,7 +395,7 @@ protected function filter(Iterator $iterator, callable $callable): CallbackFilte
* @deprecated Since version 9.16.0
* @codeCoverageIgnore
*/
#[Deprecated(message:'Use Statement::process() instead', since:'league/csv:9.16.0')]
#[Deprecated(message:'this method no longer affects on the outcome of the class, use League\Csv\Statement::process() instead', since:'league/csv:9.16.0')]
protected function applyFilter(Iterator $iterator): Iterator
{
$filter = function (array $record, string|int $key): bool {
Expand All @@ -420,7 +420,7 @@ protected function applyFilter(Iterator $iterator): Iterator
* @deprecated Since version 9.16.0
* @codeCoverageIgnore
*/
#[Deprecated(message:'Use Statement::process() instead', since:'league/csv:9.16.0')]
#[Deprecated(message:'this method no longer affects on the outcome of the class, use League\Csv\Statement::process() instead', since:'league/csv:9.16.0')]
protected function buildOrderBy(Iterator $iterator): Iterator
{
if ([] === $this->order_by) {
Expand Down
1 change: 0 additions & 1 deletion src/SyntaxError.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class SyntaxError extends Exception
*
* @deprecated since version 9.7.0
*/
#[Deprecated(message:'Use named constructor instead', since:'league/csv:9.7.0')]
public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
Expand Down
2 changes: 1 addition & 1 deletion src/TabularDataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function fetchPairs($offset_index = 0, $value_index = 1): Iterator;
*
* @throws UnableToProcessCsv if argument is less than 0
*/
#[Deprecated(message:'Use TabularDataReader::nth() instead', since:'league/csv:9.9.0')]
#[Deprecated(message:'use League\Csv\TabularDataReader::nth() instead', since:'league/csv:9.9.0')]
public function fetchOne(int $nth_record = 0): array;

/**
Expand Down
1 change: 0 additions & 1 deletion src/UnavailableFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class UnavailableFeature extends Exception
*
* @deprecated since version 9.7.0
*/
#[Deprecated(message:'Use named constructor instead', since:'league/csv:9.9.0')]
public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
Expand Down
Loading

0 comments on commit b063031

Please sign in to comment.