Skip to content

Commit

Permalink
Upgrade Psalm to 5.22.x
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Mar 4, 2024
1 parent 1e5ec63 commit b05f727
Show file tree
Hide file tree
Showing 24 changed files with 751 additions and 735 deletions.
1,340 changes: 665 additions & 675 deletions psalm-baseline.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function setTranslations($translations)
*/
public function getTranslations()
{
return $this->options['translations'];
return $this->options['translations'] ?? [];
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Compress/Bz2.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/
class Bz2 extends AbstractCompressionAlgorithm
{
private const DEFAULT_BLOCK_SIZE = 4;

/**
* Compression Options
* array(
Expand All @@ -39,7 +41,7 @@ class Bz2 extends AbstractCompressionAlgorithm
* @var Options
*/
protected $options = [
'blocksize' => 4,
'blocksize' => self::DEFAULT_BLOCK_SIZE,
'archive' => null,
];

Expand All @@ -62,7 +64,7 @@ public function __construct($options = null)
*/
public function getBlocksize()
{
return $this->options['blocksize'];
return $this->options['blocksize'] ?? self::DEFAULT_BLOCK_SIZE;
}

/**
Expand Down Expand Up @@ -114,7 +116,7 @@ public function setArchive($archive)
public function compress($content)
{
$archive = $this->getArchive();
if (! empty($archive)) {
if ($archive !== null) {
$file = bzopen($archive, 'w');
if (! $file) {
throw new Exception\RuntimeException("Error opening the archive '" . $archive . "'");
Expand Down
2 changes: 1 addition & 1 deletion src/Compress/Gz.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function compress($content)
$compressed = gzcompress($content, $this->getLevel());
}

if (! $compressed) {
if ($compressed === false) {
throw new Exception\RuntimeException('Error during compression');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Compress/Tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ public function compress($content)
*/
public function decompress($content)
{
$archive = $this->getArchive();
$archive = (string) $this->getArchive();
if (file_exists($content)) {
$archive = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, realpath($content));
} elseif (empty($archive) || ! file_exists($archive)) {
} elseif ($archive === '' || ! file_exists($archive)) {
throw new Exception\RuntimeException('Tar Archive not found');
}

Expand Down
6 changes: 3 additions & 3 deletions src/Compress/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ public function decompress($content)
$res = $zip->open($archive);

$target = $this->getTarget();
if (! empty($target) && ! is_dir($target)) {
if (is_string($target) && ! is_dir($target)) {
$target = dirname($target);
}

if (! empty($target)) {
if (is_string($target)) {
$target = rtrim($target, '/\\') . DIRECTORY_SEPARATOR;
}

if (empty($target) || ! is_dir($target)) {
if (! is_string($target) || ! is_dir($target)) {
throw new Exception\RuntimeException('No target for ZIP decompression set');
}

Expand Down
13 changes: 7 additions & 6 deletions src/DataUnitFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class DataUnitFormatter extends AbstractFilter
public const BASE_BINARY = 1024;
public const BASE_DECIMAL = 1000;

private const DEFAULT_PRECISION = 2;
/**
* A list of all possible filter modes:
*
Expand Down Expand Up @@ -64,7 +65,7 @@ final class DataUnitFormatter extends AbstractFilter
protected $options = [
'mode' => self::MODE_DECIMAL,
'unit' => '',
'precision' => 2,
'precision' => self::DEFAULT_PRECISION,
'prefixes' => [],
];

Expand Down Expand Up @@ -106,7 +107,7 @@ protected function setMode($mode)
*/
protected function getMode()
{
return $this->options['mode'];
return $this->options['mode'] ?? self::MODE_DECIMAL;
}

/**
Expand Down Expand Up @@ -146,7 +147,7 @@ protected function setUnit($unit)
*/
protected function getUnit()
{
return $this->options['unit'];
return $this->options['unit'] ?? '';
}

/**
Expand All @@ -166,7 +167,7 @@ protected function setPrecision($precision)
*/
protected function getPrecision()
{
return $this->options['precision'];
return $this->options['precision'] ?? self::DEFAULT_PRECISION;
}

/**
Expand All @@ -186,8 +187,8 @@ protected function setPrefixes(array $prefixes)
*/
protected function getPrefixes()
{
$prefixes = $this->options['prefixes'];
if ($prefixes) {
$prefixes = $this->options['prefixes'] ?? null;
if ($prefixes !== null && $prefixes !== []) {
return $prefixes;
}

Expand Down
2 changes: 1 addition & 1 deletion src/DateTimeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DateTimeFormatter extends AbstractFilter
*/
public function __construct($options = null)
{
if ($options) {
if ($options !== null) {
$this->setOptions($options);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/File/Decrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ public function filter($value)
}

$content = file_get_contents($value);
if (! $content) {
if ($content === false) {
throw new Exception\RuntimeException("Problem while reading file '$value'");
}

$decrypted = parent::filter($content);
$result = file_put_contents($this->filename, $decrypted);

if (! $result) {
if ($result === false) {
throw new Exception\RuntimeException("Problem while writing file '{$this->filename}'");
}

Expand Down
4 changes: 2 additions & 2 deletions src/File/Encrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ public function filter($value)
}

$content = file_get_contents($value);
if (! $content) {
if ($content === false) {
throw new Exception\RuntimeException("Problem while reading file '$value'");
}

$encrypted = parent::filter($content);
$result = file_put_contents($this->filename, $encrypted);

if (! $result) {
if ($result === false) {
throw new Exception\RuntimeException("Problem while writing file '{$this->filename}'");
}

Expand Down
4 changes: 2 additions & 2 deletions src/File/LowerCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ public function filter($value)
}

$content = file_get_contents($value);
if (! $content) {
if ($content === false) {
throw new Exception\RuntimeException("Problem while reading file '$value'");
}

$content = parent::filter($content);
$result = file_put_contents($value, $content);

if (! $result) {
if ($result === false) {
throw new Exception\RuntimeException("Problem while writing file '$value'");
}

Expand Down
13 changes: 7 additions & 6 deletions src/File/Rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function count;
use function file_exists;
use function is_array;
use function is_bool;
use function is_dir;
use function is_scalar;
use function is_string;
Expand Down Expand Up @@ -232,7 +233,7 @@ public function filter($value)
* Supports single and nested arrays
*
* @param array $options
* @return array
* @return $this
*/
// @codingStandardsIgnoreStart
protected function _convertOptions($options)
Expand Down Expand Up @@ -267,23 +268,23 @@ protected function _convertOptions($options)
}
}

if (empty($files)) {
if ($files === []) {
return $this;
}

if (empty($files['source'])) {
if (! is_string($files['source'] ?? null)) {
$files['source'] = '*';
}

if (empty($files['target'])) {
if (! is_string($files['target'] ?? null)) {
$files['target'] = '*';
}

if (empty($files['overwrite'])) {
if (! is_bool($files['overwrite'] ?? null)) {
$files['overwrite'] = false;
}

if (empty($files['randomize'])) {
if (! is_bool($files['randomize'] ?? null)) {
$files['randomize'] = false;
}

Expand Down
14 changes: 7 additions & 7 deletions src/File/RenameUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

/**
* @psalm-type Options = array{
* target?: string|null,
* use_upload_name?: bool,
* use_upload_extension?: bool,
* overwrite?: bool,
* randomize?: bool,
* stream_factory?: StreamFactoryInterface|null,
* upload_file_factory?: UploadedFileFactoryInterface|null,
* target: string|null,
* use_upload_name: bool,
* use_upload_extension: bool,
* overwrite: bool,
* randomize: bool,
* stream_factory: StreamFactoryInterface|null,
* upload_file_factory: UploadedFileFactoryInterface|null,
* ...
* }
* @template TOptions of Options
Expand Down
4 changes: 2 additions & 2 deletions src/File/UpperCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public function filter($value)
}

$content = file_get_contents($value);
if (! $content) {
if ($content === false) {
throw new Exception\RuntimeException("Problem while reading file '$value'");
}

$content = parent::filter($content);
$result = file_put_contents($value, $content);

if (! $result) {
if ($result === false) {
throw new Exception\RuntimeException("Problem while writing file '$value'");
}

Expand Down
5 changes: 3 additions & 2 deletions src/FilterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function get_debug_type;
use function is_array;
use function is_callable;
use function is_string;
use function sprintf;
use function strtolower;

Expand Down Expand Up @@ -86,7 +87,7 @@ public function setOptions($options)
foreach ($value as $spec) {
$callback = $spec['callback'] ?? false;
$priority = $spec['priority'] ?? static::DEFAULT_PRIORITY;
if ($callback) {
if (is_callable($callback)) {
$this->attach($callback, $priority);
}
}
Expand All @@ -96,7 +97,7 @@ public function setOptions($options)
$name = $spec['name'] ?? false;
$options = $spec['options'] ?? [];
$priority = $spec['priority'] ?? static::DEFAULT_PRIORITY;
if ($name) {
if (is_string($name) && $name !== '') {
$this->attachByName($name, $options, $priority);
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/FilterPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
use Laminas\ServiceManager\Config;
use Laminas\ServiceManager\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\ServiceManager\ServiceManager;
use Psr\Container\ContainerInterface;

use function is_array;

/**
* @psalm-import-type ServiceManagerConfiguration from ServiceManager
*/
class FilterPluginManagerFactory implements FactoryInterface
{
/**
Expand All @@ -23,11 +27,12 @@ class FilterPluginManagerFactory implements FactoryInterface
/**
* {@inheritDoc}
*
* @param ServiceManagerConfiguration|null $options
* @return FilterPluginManager
*/
public function __invoke(ContainerInterface $container, $name, ?array $options = null)
{
$pluginManager = new FilterPluginManager($container, $options ?: []);
$pluginManager = new FilterPluginManager($container, $options ?? []);

// If this is in a laminas-mvc application, the ServiceListener will inject
// merged configuration during bootstrap.
Expand Down
4 changes: 2 additions & 2 deletions src/PregReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

/**
* @psalm-type Options = array{
* pattern?: string|list<string>|null,
* replacement?: string|list<string>,
* pattern: string|list<string>|null,
* replacement: string|list<string>,
* }
* @extends AbstractFilter<Options>
* @final
Expand Down
4 changes: 2 additions & 2 deletions src/RealPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/**
* @psalm-type Options = array{
* exists?: bool,
* exists: bool,
* ...
* }
* @template TOptions of Options
Expand Down Expand Up @@ -101,7 +101,7 @@ public function filter($value)
ErrorHandler::start();
$realpath = realpath($path);
ErrorHandler::stop();
if ($realpath) {
if ($realpath !== false) {
return $realpath;
}

Expand Down
6 changes: 4 additions & 2 deletions src/StringTrim.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ public function filter($value)
}
$value = (string) $value;

if (null === $this->options['charlist']) {
$charlist = $this->options['charlist'];

if ($charlist === null) {
return $this->unicodeTrim($value);
}

return $this->unicodeTrim($value, $this->options['charlist']);
return $this->unicodeTrim($value, $charlist);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ToNull.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/**
* @psalm-type Options = array{
* type?: int-mask-of<self::TYPE_*>,
* type: int-mask-of<self::TYPE_*>,
* }
* @extends AbstractFilter<Options>
* @final
Expand Down
Loading

0 comments on commit b05f727

Please sign in to comment.