Skip to content

Commit

Permalink
Merge pull request #121 from laminas/2.34.x-merge-up-into-3.0.x_7KXMQT7W
Browse files Browse the repository at this point in the history
Merge release 2.34.0 into 3.0.x
  • Loading branch information
gsteel authored Jan 4, 2024
2 parents facd841 + 7415da9 commit 3577a59
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 261 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
},
"require-dev": {
"laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-i18n": "^2.23",
"laminas/laminas-i18n": "^2.25.0",
"laminas/laminas-uri": "^2.11.0",
"pear/archive_tar": "^1.4.14",
"phpunit/phpunit": "^10.4.2",
"phpunit/phpunit": "^10.5.5",
"psalm/plugin-phpunit": "^0.18.4",
"psr/http-factory": "^1.0.2",
"vimeo/psalm": "^5.15.0"
"vimeo/psalm": "^5.18.0"
},
"conflict": {
"laminas/laminas-validator": "<2.10.1",
Expand Down
350 changes: 189 additions & 161 deletions composer.lock

Large diffs are not rendered by default.

54 changes: 2 additions & 52 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19">
<file src="src/AbstractDateDropdown.php">
<MixedArgumentTypeCoercion>
<code>$value</code>
Expand Down Expand Up @@ -102,15 +102,9 @@
</RedundantCastGivenDocblockType>
</file>
<file src="src/Compress.php">
<ArgumentTypeCoercion>
<code>$options</code>
</ArgumentTypeCoercion>
<LessSpecificImplementedReturnType>
<code>($option is null ? array : mixed)</code>
</LessSpecificImplementedReturnType>
<MixedArgumentTypeCoercion>
<code>$adapterOptions</code>
</MixedArgumentTypeCoercion>
<MixedReturnStatement>
<code><![CDATA[$adapter->getOptions($option)]]></code>
</MixedReturnStatement>
Expand Down Expand Up @@ -329,16 +323,6 @@
</MixedReturnStatement>
</file>
<file src="src/Decompress.php">
<MixedInferredReturnType>
<code>string</code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$this->filter($value)]]></code>
</MixedReturnStatement>
<MoreSpecificImplementedParamType>
<code>$value</code>
<code>$value</code>
</MoreSpecificImplementedParamType>
<PossiblyNullArgument>
<code>$value</code>
</PossiblyNullArgument>
Expand Down Expand Up @@ -386,7 +370,6 @@
<code><![CDATA[$file['target']]]></code>
<code><![CDATA[$file['target']]]></code>
<code>$value</code>
<code>$value</code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code>$options</code>
Expand Down Expand Up @@ -531,31 +514,9 @@
</RedundantCastGivenDocblockType>
</file>
<file src="src/File/UpperCase.php">
<DocblockTypeContradiction>
<code><![CDATA[! is_scalar($value) && ! is_array($value)]]></code>
</DocblockTypeContradiction>
<MixedArgument>
<code>$value</code>
<code>$value</code>
<code>$value</code>
<code>$value</code>
</MixedArgument>
<MixedAssignment>
<code>$value</code>
</MixedAssignment>
<MixedInferredReturnType>
<code>string|array</code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code>$uploadData</code>
<code>$value</code>
<code>$value</code>
<code>$value</code>
</MixedReturnStatement>
<MoreSpecificImplementedParamType>
<code>$value</code>
<code>$value</code>
</MoreSpecificImplementedParamType>
<PossiblyUndefinedVariable>
<code>$uploadData</code>
</PossiblyUndefinedVariable>
Expand Down Expand Up @@ -824,13 +785,8 @@
<MixedArgument>
<code><![CDATA[$options['allowAttribs']]]></code>
<code><![CDATA[$options['allowTags']]]></code>
<code><![CDATA[$this->tagsAllowed[$tagName]]]></code>
</MixedArgument>
<MixedArrayAssignment>
<code><![CDATA[$this->tagsAllowed[$tagName][$attributeName]]]></code>
</MixedArrayAssignment>
<MixedAssignment>
<code>$attribute</code>
<code>$attribute</code>
<code>$element</code>
<code><![CDATA[$temp['allowAttribs']]]></code>
Expand All @@ -842,6 +798,7 @@
</PossiblyUndefinedVariable>
<RedundantConditionGivenDocblockType>
<code>is_array($options)</code>
<code>is_string($attribute)</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/ToNull.php">
Expand Down Expand Up @@ -1091,16 +1048,9 @@
</PossiblyUnusedMethod>
</file>
<file src="test/DecompressTest.php">
<MixedArgument>
<code>$compressed</code>
<code>$input</code>
</MixedArgument>
<MixedAssignment>
<code>$compressed</code>
</MixedAssignment>
<NullArgument>
<code>null</code>
</NullArgument>
<PossiblyUnusedMethod>
<code>returnUnfilteredDataProvider</code>
</PossiblyUnusedMethod>
Expand Down
30 changes: 17 additions & 13 deletions src/Compress.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
/**
* Compresses a given string
*
* phpcs:disable Generic.Files.LineLength.TooLong
* @psalm-type AdapterArg = class-string<CompressionAlgorithmInterface>|CompressionAlgorithmInterface|'Bz2'|'Gz'|'Tar'|'Zip'
* @psalm-type AdapterType = 'Bz2'|'Gz'|'Tar'|'Zip'|class-string<CompressionAlgorithmInterface>
* @psalm-type AdapterTypeOrInstance = CompressionAlgorithmInterface|AdapterType
* @psalm-type Options = array{
* adapter?: AdapterArg,
* adapter_options?: array,
* options?: array,
* adapter?: AdapterTypeOrInstance,
* options?: array<string, mixed>,
* adapter_options?: array<string, mixed>,
* }
* @extends AbstractFilter<Options>
*/
Expand All @@ -38,7 +38,7 @@ class Compress extends AbstractFilter
/**
* Compression adapter
*
* @var AdapterArg
* @var AdapterTypeOrInstance
*/
private string|CompressionAlgorithmInterface $adapter = self::DEFAULT_ADAPTER;

Expand All @@ -52,26 +52,30 @@ class Compress extends AbstractFilter
/**
* Given a string or a compression adapter interface, set the adapter. Otherwise, an iterable will set options
*
* @param string|array|Traversable|CompressionAlgorithmInterface $options (Optional) Options to set
* @param Options|Traversable<string, mixed>|null|AdapterTypeOrInstance $options
*/
public function __construct($options = null)
{
if ($options instanceof Traversable) {
/** @psalm-var Options $options */
$options = ArrayUtils::iteratorToArray($options);
}
if (is_string($options)) {
$this->setAdapter($options);
} elseif ($options instanceof CompressionAlgorithmInterface) {

if (is_string($options) || $options instanceof CompressionAlgorithmInterface) {
$this->setAdapter($options);
} elseif (is_array($options)) {

return;
}

if (is_array($options)) {
$this->setOptions($options);
}
}

/**
* Set filter state
*
* @param Options|iterable $options
* @param Options|iterable $options
* @throws Exception\InvalidArgumentException If options is not an array or Traversable.
* @return $this
*/
Expand Down Expand Up @@ -145,7 +149,7 @@ public function getAdapterName(): string
/**
* Sets compression adapter
*
* @param AdapterArg $adapter Adapter to use
* @param AdapterTypeOrInstance $adapter Adapter to use
* @return $this
* @throws Exception\InvalidArgumentException
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Decompress.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ final class Decompress extends Compress
*
* Decompresses the content $value with the defined settings
*
* @param string $value Content to decompress
* @return string The decompressed content
* @param mixed $value Content to decompress
* @return mixed|string The decompressed content
*/
public function __invoke(mixed $value): mixed
{
Expand All @@ -29,8 +29,8 @@ public function __invoke(mixed $value): mixed
*
* Decompresses the content $value with the defined settings
*
* @param mixed $value Content to decompress
* @return mixed The decompressed content
* @param mixed $value Content to decompress
* @return mixed|string The decompressed content
*/
public function filter(mixed $value): mixed
{
Expand Down
4 changes: 2 additions & 2 deletions src/File/Rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function getNewName($value, $source = false)
* Returns the file $value, removing all but digit characters
*
* @param mixed $value Full path of file to change or $_FILES data array
* @return mixed The new filename which has been set
* @return mixed|string|array The new filename which has been set
* @throws Exception\RuntimeException
*/
public function filter(mixed $value): mixed
Expand All @@ -198,7 +198,7 @@ public function filter(mixed $value): mixed
$value = $value['tmp_name'];
}

$file = $this->getNewName($value, true);
$file = $this->getNewName((string) $value, true);
if (is_string($file)) {
if ($isFileUpload) {
return $uploadData;
Expand Down
7 changes: 4 additions & 3 deletions src/File/UpperCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use function file_put_contents;
use function is_array;
use function is_scalar;
use function is_string;
use function is_writable;

final class UpperCase extends StringToUpper
Expand All @@ -21,8 +22,8 @@ final class UpperCase extends StringToUpper
*
* Does a lowercase on the content of the given file
*
* @param string|array $value Full path of file to change or $_FILES data array
* @return string|array The given $value
* @param mixed $value Full path of file to change or $_FILES data array
* @return mixed|string|array The given $value
* @throws Exception\RuntimeException
* @throws Exception\InvalidArgumentException
*/
Expand All @@ -44,7 +45,7 @@ public function filter(mixed $value): mixed
$value = $value['tmp_name'];
}

if (! file_exists($value)) {
if (! is_string($value) || ! file_exists($value)) {
throw new Exception\InvalidArgumentException("File '$value' not found");
}

Expand Down
4 changes: 1 addition & 3 deletions src/PregReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

use function func_get_args;
use function get_debug_type;
use function gettype;
use function is_array;
use function is_object;
use function is_string;
use function iterator_to_array;
use function preg_match;
Expand Down Expand Up @@ -76,7 +74,7 @@ public function setPattern($pattern)
throw new Exception\InvalidArgumentException(sprintf(
'%s expects pattern to be array or string; received "%s"',
__METHOD__,
is_object($pattern) ? $pattern::class : gettype($pattern)
get_debug_type($pattern),
));
}

Expand Down
5 changes: 2 additions & 3 deletions src/StringPrefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace Laminas\Filter;

use function gettype;
use function is_object;
use function get_debug_type;
use function is_scalar;
use function is_string;
use function sprintf;
Expand Down Expand Up @@ -46,7 +45,7 @@ public function setPrefix($prefix)
throw new Exception\InvalidArgumentException(sprintf(
'%s expects "prefix" to be string; received "%s"',
__METHOD__,
is_object($prefix) ? $prefix::class : gettype($prefix)
get_debug_type($prefix),
));
}

Expand Down
5 changes: 2 additions & 3 deletions src/StringSuffix.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace Laminas\Filter;

use function gettype;
use function is_object;
use function get_debug_type;
use function is_scalar;
use function is_string;
use function sprintf;
Expand Down Expand Up @@ -46,7 +45,7 @@ public function setSuffix($suffix)
throw new Exception\InvalidArgumentException(sprintf(
'%s expects "suffix" to be string; received "%s"',
__METHOD__,
is_object($suffix) ? $suffix::class : gettype($suffix)
get_debug_type($suffix),
));
}

Expand Down
13 changes: 6 additions & 7 deletions src/StripTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class StripTags extends AbstractFilter
* Tags are stored in the array keys, and the array values are themselves
* arrays of the attributes allowed for the corresponding tag.
*
* @var array
* @var array<string, array<string, null>>
*/
protected $tagsAllowed = [];

Expand All @@ -54,7 +54,7 @@ final class StripTags extends AbstractFilter
*
* Attributes stored here are allowed for all of the allowed tags.
*
* @var array
* @var array<string, null>
*/
protected $attributesAllowed = [];

Expand Down Expand Up @@ -101,7 +101,7 @@ public function __construct($options = null)
/**
* Returns the tagsAllowed option
*
* @return array
* @return array<string, array<string, null>>
*/
public function getTagsAllowed()
{
Expand Down Expand Up @@ -153,7 +153,7 @@ public function setTagsAllowed($tagsAllowed)
/**
* Returns the attributesAllowed option
*
* @return array
* @return array<string, null>
*/
public function getAttributesAllowed()
{
Expand All @@ -163,7 +163,7 @@ public function getAttributesAllowed()
/**
* Sets the attributesAllowed option
*
* @param array|string $attributesAllowed
* @param list<string>|string $attributesAllowed
* @return self Provides a fluent interface
*/
public function setAttributesAllowed($attributesAllowed)
Expand Down Expand Up @@ -246,8 +246,7 @@ public function filter(mixed $value): mixed
* @param string $tag
* @return string
*/
// @codingStandardsIgnoreStart
protected function _filterTag($tag)
protected function _filterTag($tag) // phpcs:ignore
{
// @codingStandardsIgnoreEnd
// Parse the tag into:
Expand Down
Loading

0 comments on commit 3577a59

Please sign in to comment.