Skip to content

Commit

Permalink
Merge pull request #190 from samsonasik/update-to-php81-syntax
Browse files Browse the repository at this point in the history
Update to latest PHP 8.1 syntax
  • Loading branch information
gsteel authored Nov 3, 2024
2 parents 515f081 + a7e47b5 commit f9894b7
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 98 deletions.
14 changes: 0 additions & 14 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
</TypeDoesNotContainType>
</file>
<file src="src/AbstractFilter.php">
<DocblockTypeContradiction>
<code><![CDATA[gettype($options)]]></code>
</DocblockTypeContradiction>
<InvalidPropertyAssignmentValue>
<code><![CDATA[[]]]></code>
</InvalidPropertyAssignmentValue>
Expand All @@ -37,9 +34,6 @@
<PossiblyInvalidPropertyAssignmentValue>
<code><![CDATA[$this->options]]></code>
</PossiblyInvalidPropertyAssignmentValue>
<RedundantConditionGivenDocblockType>
<code><![CDATA[is_object($options)]]></code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/AbstractUnicode.php">
<DeprecatedClass>
Expand Down Expand Up @@ -394,13 +388,6 @@
</RedundantCastGivenDocblockType>
</file>
<file src="src/Compress/Zip.php">
<InvalidArgument>
<code><![CDATA[$res]]></code>
<code><![CDATA[$res]]></code>
<code><![CDATA[$res]]></code>
<code><![CDATA[$res]]></code>
<code><![CDATA[$res]]></code>
</InvalidArgument>
<InvalidNullableReturnType>
<code><![CDATA[string]]></code>
</InvalidNullableReturnType>
Expand Down Expand Up @@ -2078,7 +2065,6 @@
<PossiblyUnusedMethod>
<code><![CDATA[objectCallback]]></code>
<code><![CDATA[objectCallbackWithParams]]></code>
<code><![CDATA[staticCallback]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/TestAsset/LowerCase.php">
Expand Down
5 changes: 2 additions & 3 deletions src/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

use function array_key_exists;
use function array_map;
use function gettype;
use function get_debug_type;
use function is_array;
use function is_iterable;
use function is_object;
use function is_scalar;
use function is_string;
use function method_exists;
Expand Down Expand Up @@ -56,7 +55,7 @@ public function setOptions($options)
throw new Exception\InvalidArgumentException(sprintf(
'"%s" expects an array or Traversable; received "%s"',
__METHOD__,
is_object($options) ? $options::class : gettype($options)
get_debug_type($options)
));
}

Expand Down
101 changes: 27 additions & 74 deletions src/Compress/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,84 +240,37 @@ public function decompress($content)
/**
* Returns the proper string based on the given error constant
*
* @param string $error
* @param int|false $error
* @return string
*/
public function errorString($error)
{
switch ($error) {
case ZipArchive::ER_MULTIDISK:
return 'Multidisk ZIP Archives not supported';

case ZipArchive::ER_RENAME:
return 'Failed to rename the temporary file for ZIP';

case ZipArchive::ER_CLOSE:
return 'Failed to close the ZIP Archive';

case ZipArchive::ER_SEEK:
return 'Failure while seeking the ZIP Archive';

case ZipArchive::ER_READ:
return 'Failure while reading the ZIP Archive';

case ZipArchive::ER_WRITE:
return 'Failure while writing the ZIP Archive';

case ZipArchive::ER_CRC:
return 'CRC failure within the ZIP Archive';

case ZipArchive::ER_ZIPCLOSED:
return 'ZIP Archive already closed';

case ZipArchive::ER_NOENT:
return 'No such file within the ZIP Archive';

case ZipArchive::ER_EXISTS:
return 'ZIP Archive already exists';

case ZipArchive::ER_OPEN:
return 'Can not open ZIP Archive';

case ZipArchive::ER_TMPOPEN:
return 'Failure creating temporary ZIP Archive';

case ZipArchive::ER_ZLIB:
return 'ZLib Problem';

case ZipArchive::ER_MEMORY:
return 'Memory allocation problem while working on a ZIP Archive';

case ZipArchive::ER_CHANGED:
return 'ZIP Entry has been changed';

case ZipArchive::ER_COMPNOTSUPP:
return 'Compression method not supported within ZLib';

case ZipArchive::ER_EOF:
return 'Premature EOF within ZIP Archive';

case ZipArchive::ER_INVAL:
return 'Invalid argument for ZLIB';

case ZipArchive::ER_NOZIP:
return 'Given file is no zip archive';

case ZipArchive::ER_INTERNAL:
return 'Internal error while working on a ZIP Archive';

case ZipArchive::ER_INCONS:
return 'Inconsistent ZIP archive';

case ZipArchive::ER_REMOVE:
return 'Can not remove ZIP Archive';

case ZipArchive::ER_DELETED:
return 'ZIP Entry has been deleted';

default:
return 'Unknown error within ZIP Archive';
}
return match ($error) {
ZipArchive::ER_MULTIDISK => 'Multidisk ZIP Archives not supported',
ZipArchive::ER_RENAME => 'Failed to rename the temporary file for ZIP',
ZipArchive::ER_CLOSE => 'Failed to close the ZIP Archive',
ZipArchive::ER_SEEK => 'Failure while seeking the ZIP Archive',
ZipArchive::ER_READ => 'Failure while reading the ZIP Archive',
ZipArchive::ER_WRITE => 'Failure while writing the ZIP Archive',
ZipArchive::ER_CRC => 'CRC failure within the ZIP Archive',
ZipArchive::ER_ZIPCLOSED => 'ZIP Archive already closed',
ZipArchive::ER_NOENT => 'No such file within the ZIP Archive',
ZipArchive::ER_EXISTS => 'ZIP Archive already exists',
ZipArchive::ER_OPEN => 'Can not open ZIP Archive',
ZipArchive::ER_TMPOPEN => 'Failure creating temporary ZIP Archive',
ZipArchive::ER_ZLIB => 'ZLib Problem',
ZipArchive::ER_MEMORY => 'Memory allocation problem while working on a ZIP Archive',
ZipArchive::ER_CHANGED => 'ZIP Entry has been changed',
ZipArchive::ER_COMPNOTSUPP => 'Compression method not supported within ZLib',
ZipArchive::ER_EOF => 'Premature EOF within ZIP Archive',
ZipArchive::ER_INVAL => 'Invalid argument for ZLIB',
ZipArchive::ER_NOZIP => 'Given file is no zip archive',
ZipArchive::ER_INTERNAL => 'Internal error while working on a ZIP Archive',
ZipArchive::ER_INCONS => 'Inconsistent ZIP archive',
ZipArchive::ER_REMOVE => 'Can not remove ZIP Archive',
ZipArchive::ER_DELETED => 'ZIP Entry has been deleted',
default => 'Unknown error within ZIP Archive',
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/FilterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function attach($callback, $priority = self::DEFAULT_PRIORITY)
get_debug_type($callback)
));
}
$callback = [$callback, 'filter'];
$callback = $callback->filter(...);
}
$this->filters->insert($callback, $priority);
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/ForceUriScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class ForceUriScheme implements FilterInterface
private const DEFAULT_SCHEME = 'https';

/** @var non-empty-string */
private string $scheme;
private readonly string $scheme;

/** @param Options $options */
public function __construct(array $options = ['scheme' => self::DEFAULT_SCHEME])
Expand Down
2 changes: 1 addition & 1 deletion test/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testConstructorWithOptions(): void
public function testStaticCallback(): void
{
$filter = new CallbackFilter(
[CallbackClass::class, 'staticCallback']
CallbackClass::staticCallback(...)
);
self::assertSame('staticCallback-test', $filter('test'));
}
Expand Down
6 changes: 3 additions & 3 deletions test/FilterPluginManagerCompatibilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use ReflectionProperty;

use function in_array;
use function strpos;
use function str_contains;

class FilterPluginManagerCompatibilityTest extends TestCase
{
Expand Down Expand Up @@ -73,12 +73,12 @@ public static function aliasProvider(): Generator
self::assertIsString($alias);
self::assertIsString($target);
// Skipping as laminas-i18n is not required by this package
if (strpos($target, '\\I18n\\') !== false) {
if (str_contains($target, '\\I18n\\')) {
continue;
}

// Skipping as it has required options
if (strpos($target, 'DataUnitFormatter') !== false) {
if (str_contains($target, 'DataUnitFormatter')) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion test/StaticAnalysis/PluginRetrieval.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/** @psalm-suppress UnusedClass */
final class PluginRetrieval
{
public function __construct(private FilterPluginManager $pluginManager)
public function __construct(private readonly FilterPluginManager $pluginManager)
{
}

Expand Down

0 comments on commit f9894b7

Please sign in to comment.