From eded4bd583297e43c63cf8087e9e12e18552309a Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Wed, 25 Jun 2025 04:59:07 +0200 Subject: [PATCH 01/15] add a simple Justfile to run in php7.4 and execute phpunit from the current working directory instead of in tests --- .gitignore | 1 + Justfile | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Justfile diff --git a/.gitignore b/.gitignore index 7611d841f..026115fef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock tests/.phpunit.result.cache vendor +phpunit.xml diff --git a/Justfile b/Justfile new file mode 100644 index 000000000..cff9ab852 --- /dev/null +++ b/Justfile @@ -0,0 +1,36 @@ +set dotenv-load := false +set positional-arguments + +export COLUMNS := '550' + +default: + @just --list + +php := "/usr/bin/php7.4" +composer := "/usr/bin/php7.4 /usr/local/bin/composer" + +cli *args='': + {{ php }} bin/console "$@" + +phpstan *args='': + {{ php }} vendor/bin/phpstan "${@}" + +watch-phpstan *args='': + find hamcrest/ tests/ -name '*.php' | entr {{ php }} vendor/bin/phpstan "${@}" + +setup-phpunit: + cp tests/phpunit.xml.dist phpunit.xml + sed -i 's|bootstrap="bootstrap\.php"|bootstrap="tests/bootstrap.php"|g; s|../hamcrest|hamcrest|g; s|\.|tests/|g' phpunit.xml + +phpunit *args='': + {{ php }} vendor/bin/phpunit "${@}" + +composer *args='': + {{ composer }} "${@}" + +units: + j phpunit --exclude-group=integration + +prep: + j phpstan + j phpunit From 2436a19799160f2a0a14670f17159f8ba50b7aaf Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Wed, 25 Jun 2025 08:44:45 +0200 Subject: [PATCH 02/15] install phpstan and configure including baseline --- .gitignore | 3 ++- Justfile | 15 ++++++------ composer.json | 6 +++-- phpstan.neon | 19 ++++++++++++++ tests/phpstan-baseline.neon | 49 +++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 phpstan.neon create mode 100644 tests/phpstan-baseline.neon diff --git a/.gitignore b/.gitignore index 026115fef..73f9b899d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ composer.lock tests/.phpunit.result.cache vendor -phpunit.xml +/.phpunit.result.cache +/tests/phpunit.xml diff --git a/Justfile b/Justfile index cff9ab852..c49720005 100644 --- a/Justfile +++ b/Justfile @@ -18,19 +18,18 @@ phpstan *args='': watch-phpstan *args='': find hamcrest/ tests/ -name '*.php' | entr {{ php }} vendor/bin/phpstan "${@}" -setup-phpunit: - cp tests/phpunit.xml.dist phpunit.xml - sed -i 's|bootstrap="bootstrap\.php"|bootstrap="tests/bootstrap.php"|g; s|../hamcrest|hamcrest|g; s|\.|tests/|g' phpunit.xml - phpunit *args='': - {{ php }} vendor/bin/phpunit "${@}" + {{ php }} vendor/bin/phpunit --config=tests/phpunit.xml.dist "${@}" composer *args='': {{ composer }} "${@}" units: - j phpunit --exclude-group=integration + just phpunit --exclude-group=integration + +phpstan-generate-baseline: + just phpstan analyse --generate-baseline=tests/phpstan-baseline.neon prep: - j phpstan - j phpunit + just phpstan + just phpunit diff --git a/composer.json b/composer.json index fc65f833d..4a08fda8b 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,9 @@ "require-dev": { "phpunit/php-file-iterator": "^1.4 || ^2.0 || ^3.0", - "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-phpunit": "^2.0" }, "replace": { @@ -33,7 +35,7 @@ "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "3.0-dev" } } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 000000000..27b204db8 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,19 @@ +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + - tests/phpstan-baseline.neon + +parameters: + level: 8 + paths: + - hamcrest + - tests + + excludePaths: + analyse: + - tests/ + + + editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%&project=hamcrest-php' + + reportUnmatchedIgnoredErrors: false + diff --git a/tests/phpstan-baseline.neon b/tests/phpstan-baseline.neon new file mode 100644 index 000000000..48e69f310 --- /dev/null +++ b/tests/phpstan-baseline.neon @@ -0,0 +1,49 @@ +parameters: + ignoreErrors: + - + message: '#^Cannot call method matches\(\) on Hamcrest\\Matcher\|null\.$#' + identifier: method.nonObject + count: 1 + path: ../hamcrest/Hamcrest/Arrays/SeriesMatchingOnce.php + + - + message: '#^Parameter \#1 \$matcher of method Hamcrest\\Arrays\\SeriesMatchingOnce\:\:_describeMismatch\(\) expects Hamcrest\\Matcher, Hamcrest\\Matcher\|null given\.$#' + identifier: argument.type + count: 1 + path: ../hamcrest/Hamcrest/Arrays/SeriesMatchingOnce.php + + - + message: '#^Cannot call method toString\(\) on class\-string\|object\.$#' + identifier: method.nonObject + count: 1 + path: ../hamcrest/Hamcrest/Core/HasToString.php + + - + message: '#^Cannot cast Hamcrest\\BaseDescription to string\.$#' + identifier: cast.string + count: 1 + path: ../hamcrest/Hamcrest/StringDescription.php + + - + message: '#^Argument of an invalid type list\\|false supplied for foreach, only iterables are supported\.$#' + identifier: foreach.nonIterable + count: 1 + path: ../hamcrest/Hamcrest/Text/IsEqualIgnoringWhiteSpace.php + + - + message: '#^Cannot access offset int\<0, max\> on non\-empty\-array\, string\>\|false\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: ../hamcrest/Hamcrest/Text/IsEqualIgnoringWhiteSpace.php + + - + message: '#^Method Hamcrest\\Xml\\HasXPath\:\:matchesContent\(\) has parameter \$nodes with generic class DOMNodeList but does not specify its types\: TNode$#' + identifier: missingType.generics + count: 1 + path: ../hamcrest/Hamcrest/Xml/HasXPath.php + + - + message: '#^Parameter \#1 \$document of class DOMXPath constructor expects DOMDocument, DOMDocument\|null given\.$#' + identifier: argument.type + count: 1 + path: ../hamcrest/Hamcrest/Xml/HasXPath.php From db81cfa2b5f2029d6f33d25b2e67389c1f8e617f Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Wed, 25 Jun 2025 09:49:38 +0200 Subject: [PATCH 03/15] add mostly native typehints to all files in hamcrest --- Justfile | 5 +- hamcrest/Hamcrest.php | 187 ++++++++++------- hamcrest/Hamcrest/Arrays/IsArray.php | 25 ++- .../Hamcrest/Arrays/IsArrayContaining.php | 10 +- .../Arrays/IsArrayContainingInAnyOrder.php | 15 +- .../Arrays/IsArrayContainingInOrder.php | 15 +- .../Hamcrest/Arrays/IsArrayContainingKey.php | 10 +- .../Arrays/IsArrayContainingKeyValuePair.php | 17 +- hamcrest/Hamcrest/Arrays/IsArrayWithSize.php | 6 +- hamcrest/Hamcrest/Arrays/MatchingOnce.php | 32 ++- .../Hamcrest/Arrays/SeriesMatchingOnce.php | 40 +++- hamcrest/Hamcrest/BaseDescription.php | 15 +- hamcrest/Hamcrest/BaseMatcher.php | 10 +- .../Collection/IsEmptyTraversable.php | 16 +- .../Collection/IsTraversableWithSize.php | 3 +- hamcrest/Hamcrest/Core/AllOf.php | 16 +- hamcrest/Hamcrest/Core/AnyOf.php | 12 +- hamcrest/Hamcrest/Core/CombinableMatcher.php | 19 +- hamcrest/Hamcrest/Core/DescribedAs.php | 30 +-- hamcrest/Hamcrest/Core/Every.php | 8 +- hamcrest/Hamcrest/Core/HasToString.php | 5 +- hamcrest/Hamcrest/Core/Is.php | 11 +- hamcrest/Hamcrest/Core/IsAnything.php | 10 +- .../Hamcrest/Core/IsCollectionContaining.php | 12 +- hamcrest/Hamcrest/Core/IsEqual.php | 14 +- hamcrest/Hamcrest/Core/IsIdentical.php | 11 +- hamcrest/Hamcrest/Core/IsInstanceOf.php | 10 +- hamcrest/Hamcrest/Core/IsNot.php | 9 +- hamcrest/Hamcrest/Core/IsNull.php | 14 +- hamcrest/Hamcrest/Core/IsSame.php | 12 +- hamcrest/Hamcrest/Core/IsTypeOf.php | 15 +- hamcrest/Hamcrest/Core/Set.php | 22 +- .../Hamcrest/Core/ShortcutCombination.php | 12 +- hamcrest/Hamcrest/Description.php | 15 +- hamcrest/Hamcrest/DiagnosingMatcher.php | 9 +- hamcrest/Hamcrest/FeatureMatcher.php | 16 +- .../Hamcrest/Internal/SelfDescribingValue.php | 9 +- hamcrest/Hamcrest/Matcher.php | 6 +- hamcrest/Hamcrest/MatcherAssert.php | 10 +- hamcrest/Hamcrest/Matchers.php | 191 +++++++++++------- hamcrest/Hamcrest/NullDescription.php | 10 +- hamcrest/Hamcrest/Number/IsCloseTo.php | 24 ++- .../Hamcrest/Number/OrderingComparison.php | 46 ++++- hamcrest/Hamcrest/SelfDescribing.php | 2 +- hamcrest/Hamcrest/StringDescription.php | 11 +- hamcrest/Hamcrest/Text/IsEmptyString.php | 20 +- .../Hamcrest/Text/IsEqualIgnoringCase.php | 16 +- .../Text/IsEqualIgnoringWhiteSpace.php | 18 +- hamcrest/Hamcrest/Text/MatchesPattern.php | 11 +- hamcrest/Hamcrest/Text/StringContains.php | 13 +- .../Text/StringContainsIgnoringCase.php | 10 +- .../Hamcrest/Text/StringContainsInOrder.php | 17 +- hamcrest/Hamcrest/Text/StringEndsWith.php | 11 +- hamcrest/Hamcrest/Text/StringStartsWith.php | 10 +- hamcrest/Hamcrest/Text/SubstringMatcher.php | 16 +- hamcrest/Hamcrest/Type/IsArray.php | 2 +- hamcrest/Hamcrest/Type/IsBoolean.php | 2 +- hamcrest/Hamcrest/Type/IsCallable.php | 4 +- hamcrest/Hamcrest/Type/IsDouble.php | 2 +- hamcrest/Hamcrest/Type/IsInteger.php | 2 +- hamcrest/Hamcrest/Type/IsNumeric.php | 4 +- hamcrest/Hamcrest/Type/IsObject.php | 2 +- hamcrest/Hamcrest/Type/IsResource.php | 2 +- hamcrest/Hamcrest/Type/IsScalar.php | 4 +- hamcrest/Hamcrest/Type/IsString.php | 2 +- .../Hamcrest/TypeSafeDiagnosingMatcher.php | 11 +- hamcrest/Hamcrest/TypeSafeMatcher.php | 39 ++-- hamcrest/Hamcrest/Util.php | 10 +- hamcrest/Hamcrest/Xml/HasXPath.php | 25 ++- tests/Hamcrest/BaseMatcherTest.php | 4 +- tests/Hamcrest/Core/IsInstanceOfTest.php | 2 +- tests/Hamcrest/InvokedMatcherTest.php | 2 +- tests/Hamcrest/StringDescriptionTest.php | 2 +- 73 files changed, 780 insertions(+), 480 deletions(-) diff --git a/Justfile b/Justfile index c49720005..d6d915053 100644 --- a/Justfile +++ b/Justfile @@ -19,14 +19,11 @@ watch-phpstan *args='': find hamcrest/ tests/ -name '*.php' | entr {{ php }} vendor/bin/phpstan "${@}" phpunit *args='': - {{ php }} vendor/bin/phpunit --config=tests/phpunit.xml.dist "${@}" + {{ php }} vendor/bin/phpunit --config=tests/phpunit.xml "${@}" composer *args='': {{ composer }} "${@}" -units: - just phpunit --exclude-group=integration - phpstan-generate-baseline: just phpstan analyse --generate-baseline=tests/phpstan-baseline.neon diff --git a/hamcrest/Hamcrest.php b/hamcrest/Hamcrest.php index a521de8a4..5612c0987 100644 --- a/hamcrest/Hamcrest.php +++ b/hamcrest/Hamcrest.php @@ -6,6 +6,8 @@ // This file is generated from the static method @factory doctags. +use Hamcrest\Matcher; + if (!function_exists('assertThat')) { /** * Make an assertion and throw {@link Hamcrest_AssertionError} if it fails. @@ -20,7 +22,7 @@ * assertThat("some error", $a > $b); * */ - function assertThat() + function assertThat(): void { $args = func_get_args(); call_user_func_array( @@ -34,7 +36,7 @@ function assertThat() /** * Evaluates to true only if each $matcher[$i] is satisfied by $array[$i]. */ - function anArray(/* args... */) + function anArray(/* args... */): \Hamcrest\Arrays\IsArray { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArray', 'anArray'), $args); @@ -49,7 +51,7 @@ function anArray(/* args... */) * * @return \Hamcrest\Arrays\IsArrayContaining */ - function hasItemInArray($item) + function hasItemInArray($item): \Hamcrest\Arrays\IsArrayContaining { return \Hamcrest\Arrays\IsArrayContaining::hasItemInArray($item); } @@ -63,7 +65,7 @@ function hasItemInArray($item) * * @return \Hamcrest\Arrays\IsArrayContaining */ - function hasValue($item) + function hasValue($item): \Hamcrest\Arrays\IsArrayContaining { return \Hamcrest\Arrays\IsArrayContaining::hasItemInArray($item); } @@ -73,7 +75,7 @@ function hasValue($item) /** * An array with elements that match the given matchers. */ - function arrayContainingInAnyOrder(/* args... */) + function arrayContainingInAnyOrder(/* args... */): \Hamcrest\Arrays\IsArrayContainingInAnyOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args); @@ -84,7 +86,7 @@ function arrayContainingInAnyOrder(/* args... */) /** * An array with elements that match the given matchers. */ - function containsInAnyOrder(/* args... */) + function containsInAnyOrder(/* args... */): \Hamcrest\Arrays\IsArrayContainingInAnyOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args); @@ -95,7 +97,7 @@ function containsInAnyOrder(/* args... */) /** * An array with elements that match the given matchers in the same order. */ - function arrayContaining(/* args... */) + function arrayContaining(/* args... */): \Hamcrest\Arrays\IsArrayContainingInOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args); @@ -106,7 +108,7 @@ function arrayContaining(/* args... */) /** * An array with elements that match the given matchers in the same order. */ - function contains(/* args... */) + function contains(/* args... */): \Hamcrest\Arrays\IsArrayContainingInOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args); @@ -121,7 +123,7 @@ function contains(/* args... */) * * @return \Hamcrest\Arrays\IsArrayContainingKey */ - function hasKeyInArray($key) + function hasKeyInArray($key): \Hamcrest\Arrays\IsArrayContainingKey { return \Hamcrest\Arrays\IsArrayContainingKey::hasKeyInArray($key); } @@ -135,7 +137,7 @@ function hasKeyInArray($key) * * @return \Hamcrest\Arrays\IsArrayContainingKey */ - function hasKey($key) + function hasKey($key): \Hamcrest\Arrays\IsArrayContainingKey { return \Hamcrest\Arrays\IsArrayContainingKey::hasKeyInArray($key); } @@ -144,8 +146,10 @@ function hasKey($key) if (!function_exists('hasKeyValuePair')) { /** * Test if an array has both an key and value in parity with each other. + * @param mixed $key + * @param mixed $value */ - function hasKeyValuePair($key, $value) + function hasKeyValuePair($key, $value): \Hamcrest\Arrays\IsArrayContainingKeyValuePair { return \Hamcrest\Arrays\IsArrayContainingKeyValuePair::hasKeyValuePair($key, $value); } @@ -154,8 +158,10 @@ function hasKeyValuePair($key, $value) if (!function_exists('hasEntry')) { /** * Test if an array has both an key and value in parity with each other. + * @param mixed $key + * @param mixed $value */ - function hasEntry($key, $value) + function hasEntry($key, $value): \Hamcrest\Arrays\IsArrayContainingKeyValuePair { return \Hamcrest\Arrays\IsArrayContainingKeyValuePair::hasKeyValuePair($key, $value); } @@ -169,7 +175,7 @@ function hasEntry($key, $value) * * @return \Hamcrest\Arrays\IsArrayWithSize */ - function arrayWithSize($size) + function arrayWithSize($size): \Hamcrest\Arrays\IsArrayWithSize { return \Hamcrest\Arrays\IsArrayWithSize::arrayWithSize($size); } @@ -179,7 +185,7 @@ function arrayWithSize($size) /** * Matches an empty array. */ - function emptyArray() + function emptyArray(): \Hamcrest\Core\DescribedAs { return \Hamcrest\Arrays\IsArrayWithSize::emptyArray(); } @@ -189,7 +195,7 @@ function emptyArray() /** * Matches an empty array. */ - function nonEmptyArray() + function nonEmptyArray(): \Hamcrest\Core\DescribedAs { return \Hamcrest\Arrays\IsArrayWithSize::nonEmptyArray(); } @@ -199,7 +205,7 @@ function nonEmptyArray() /** * Returns true if traversable is empty. */ - function emptyTraversable() + function emptyTraversable(): \Hamcrest\Collection\IsEmptyTraversable { return \Hamcrest\Collection\IsEmptyTraversable::emptyTraversable(); } @@ -209,7 +215,7 @@ function emptyTraversable() /** * Returns true if traversable is not empty. */ - function nonEmptyTraversable() + function nonEmptyTraversable(): \Hamcrest\Collection\IsEmptyTraversable { return \Hamcrest\Collection\IsEmptyTraversable::nonEmptyTraversable(); } @@ -218,8 +224,9 @@ function nonEmptyTraversable() if (!function_exists('traversableWithSize')) { /** * Does traversable size satisfy a given matcher? + * @param mixed $size */ - function traversableWithSize($size) + function traversableWithSize($size): \Hamcrest\Collection\IsTraversableWithSize { return \Hamcrest\Collection\IsTraversableWithSize::traversableWithSize($size); } @@ -229,7 +236,7 @@ function traversableWithSize($size) /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ - function allOf(/* args... */) + function allOf(/* args... */): \Hamcrest\Core\AllOf { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AllOf', 'allOf'), $args); @@ -240,7 +247,7 @@ function allOf(/* args... */) /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ - function anyOf(/* args... */) + function anyOf(/* args... */): \Hamcrest\Core\AnyOf { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'anyOf'), $args); @@ -251,7 +258,7 @@ function anyOf(/* args... */) /** * Evaluates to false if ANY of the passed in matchers evaluate to true. */ - function noneOf(/* args... */) + function noneOf(/* args... */): \Hamcrest\Core\IsNot { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'noneOf'), $args); @@ -266,7 +273,7 @@ function noneOf(/* args... */) * assertThat($string, both(containsString("a"))->andAlso(containsString("b"))); * */ - function both(\Hamcrest\Matcher $matcher) + function both(\Hamcrest\Matcher $matcher): \Hamcrest\Core\CombinableMatcher { return \Hamcrest\Core\CombinableMatcher::both($matcher); } @@ -280,7 +287,7 @@ function both(\Hamcrest\Matcher $matcher) * assertThat($string, either(containsString("a"))->orElse(containsString("b"))); * */ - function either(\Hamcrest\Matcher $matcher) + function either(\Hamcrest\Matcher $matcher): \Hamcrest\Core\CombinableMatcher { return \Hamcrest\Core\CombinableMatcher::either($matcher); } @@ -290,7 +297,7 @@ function either(\Hamcrest\Matcher $matcher) /** * Wraps an existing matcher and overrides the description when it fails. */ - function describedAs(/* args... */) + function describedAs(/* args... */): \Hamcrest\Core\DescribedAs { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\DescribedAs', 'describedAs'), $args); @@ -305,7 +312,7 @@ function describedAs(/* args... */) * @return \Hamcrest\Core\Every * Evaluates to TRUE for a collection in which every item matches $itemMatcher */ - function everyItem(\Hamcrest\Matcher $itemMatcher) + function everyItem(\Hamcrest\Matcher $itemMatcher): \Hamcrest\Core\Every { return \Hamcrest\Core\Every::everyItem($itemMatcher); } @@ -316,7 +323,7 @@ function everyItem(\Hamcrest\Matcher $itemMatcher) * Creates a matcher that matches any examined object whose toString or * __toString() method returns a value equalTo the specified string. */ - function hasToString($matcher) + function hasToString($matcher): \Hamcrest\Core\HasToString { return \Hamcrest\Core\HasToString::hasToString($matcher); } @@ -329,8 +336,9 @@ function hasToString($matcher) * * For example: assertThat($cheese, equalTo($smelly)) * vs. assertThat($cheese, is(equalTo($smelly))) + * @param mixed $value */ - function is($value) + function is($value): \Hamcrest\Core\Is { return \Hamcrest\Core\Is::is($value); } @@ -344,7 +352,7 @@ function is($value) * * @return \Hamcrest\Core\IsAnything */ - function anything($description = 'ANYTHING') + function anything(string $description = 'ANYTHING'): \Hamcrest\Core\IsAnything { return \Hamcrest\Core\IsAnything::anything($description); } @@ -361,7 +369,7 @@ function anything($description = 'ANYTHING') * assertThat(array('a', 'b'), hasItem('b')); * */ - function hasItem(/* args... */) + function hasItem(/* args... */): \Hamcrest\Core\IsCollectionContaining { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItem'), $args); @@ -378,7 +386,7 @@ function hasItem(/* args... */) * assertThat(array('a', 'b', 'c'), hasItems(equalTo('a'), equalTo('b'))); * */ - function hasItems(/* args... */) + function hasItems(/* args... */): \Hamcrest\Core\AllOf { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItems'), $args); @@ -389,8 +397,9 @@ function hasItems(/* args... */) /** * Is the value equal to another value, as tested by the use of the "==" * comparison operator? + * @param mixed $item */ - function equalTo($item) + function equalTo($item): \Hamcrest\Core\IsEqual { return \Hamcrest\Core\IsEqual::equalTo($item); } @@ -399,8 +408,9 @@ function equalTo($item) if (!function_exists('identicalTo')) { /** * Tests of the value is identical to $value as tested by the "===" operator. + * @param mixed $value */ - function identicalTo($value) + function identicalTo($value): \Hamcrest\Core\IsIdentical { return \Hamcrest\Core\IsIdentical::identicalTo($value); } @@ -413,7 +423,7 @@ function identicalTo($value) * the signature of the method that sets it up, for example in * assertThat($anObject, anInstanceOf('Thing')); */ - function anInstanceOf($theClass) + function anInstanceOf(string $theClass): \Hamcrest\Core\IsInstanceOf { return \Hamcrest\Core\IsInstanceOf::anInstanceOf($theClass); } @@ -426,7 +436,7 @@ function anInstanceOf($theClass) * the signature of the method that sets it up, for example in * assertThat($anObject, anInstanceOf('Thing')); */ - function any($theClass) + function any(string $theClass): \Hamcrest\Core\IsInstanceOf { return \Hamcrest\Core\IsInstanceOf::anInstanceOf($theClass); } @@ -435,8 +445,9 @@ function any($theClass) if (!function_exists('not')) { /** * Matches if value does not match $value. + * @param mixed $value */ - function not($value) + function not($value): \Hamcrest\Core\IsNot { return \Hamcrest\Core\IsNot::not($value); } @@ -446,7 +457,7 @@ function not($value) /** * Matches if value is null. */ - function nullValue() + function nullValue(): \Hamcrest\Core\IsNull { return \Hamcrest\Core\IsNull::nullValue(); } @@ -456,7 +467,7 @@ function nullValue() /** * Matches if value is not null. */ - function notNullValue() + function notNullValue(): \Hamcrest\Core\IsNot { return \Hamcrest\Core\IsNull::notNullValue(); } @@ -472,7 +483,7 @@ function notNullValue() * * @return \Hamcrest\Core\IsSame */ - function sameInstance($object) + function sameInstance($object): \Hamcrest\Core\IsSame { return \Hamcrest\Core\IsSame::sameInstance($object); } @@ -482,7 +493,7 @@ function sameInstance($object) /** * Is the value a particular built-in type? */ - function typeOf($theType) + function typeOf(string $theType): \Hamcrest\Core\IsTypeOf { return \Hamcrest\Core\IsTypeOf::typeOf($theType); } @@ -491,8 +502,9 @@ function typeOf($theType) if (!function_exists('set')) { /** * Matches if value (class, object, or array) has named $property. + * @param mixed $property */ - function set($property) + function set($property): \Hamcrest\Core\Set { return \Hamcrest\Core\Set::set($property); } @@ -501,8 +513,9 @@ function set($property) if (!function_exists('notSet')) { /** * Matches if value (class, object, or array) does not have named $property. + * @param mixed $property */ - function notSet($property) + function notSet($property): \Hamcrest\Core\Set { return \Hamcrest\Core\Set::notSet($property); } @@ -512,8 +525,10 @@ function notSet($property) /** * Matches if value is a number equal to $value within some range of * acceptable error $delta. + * @param mixed $value + * @param mixed $delta */ - function closeTo($value, $delta) + function closeTo($value, $delta): \Hamcrest\Number\IsCloseTo { return \Hamcrest\Number\IsCloseTo::closeTo($value, $delta); } @@ -522,8 +537,9 @@ function closeTo($value, $delta) if (!function_exists('comparesEqualTo')) { /** * The value is not > $value, nor < $value. + * @param mixed $value */ - function comparesEqualTo($value) + function comparesEqualTo($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::comparesEqualTo($value); } @@ -532,8 +548,9 @@ function comparesEqualTo($value) if (!function_exists('greaterThan')) { /** * The value is > $value. + * @param mixed $value */ - function greaterThan($value) + function greaterThan($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::greaterThan($value); } @@ -542,8 +559,9 @@ function greaterThan($value) if (!function_exists('greaterThanOrEqualTo')) { /** * The value is >= $value. + * @param mixed $value */ - function greaterThanOrEqualTo($value) + function greaterThanOrEqualTo($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::greaterThanOrEqualTo($value); } @@ -552,8 +570,9 @@ function greaterThanOrEqualTo($value) if (!function_exists('atLeast')) { /** * The value is >= $value. + * @param mixed $value */ - function atLeast($value) + function atLeast($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::greaterThanOrEqualTo($value); } @@ -562,8 +581,9 @@ function atLeast($value) if (!function_exists('lessThan')) { /** * The value is < $value. + * @param mixed $value */ - function lessThan($value) + function lessThan($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::lessThan($value); } @@ -572,8 +592,9 @@ function lessThan($value) if (!function_exists('lessThanOrEqualTo')) { /** * The value is <= $value. + * @param mixed $value */ - function lessThanOrEqualTo($value) + function lessThanOrEqualTo($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::lessThanOrEqualTo($value); } @@ -582,8 +603,9 @@ function lessThanOrEqualTo($value) if (!function_exists('atMost')) { /** * The value is <= $value. + * @param mixed $value */ - function atMost($value) + function atMost($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::lessThanOrEqualTo($value); } @@ -593,7 +615,7 @@ function atMost($value) /** * Matches if value is a zero-length string. */ - function isEmptyString() + function isEmptyString(): \Hamcrest\Text\IsEmptyString { return \Hamcrest\Text\IsEmptyString::isEmptyString(); } @@ -603,7 +625,7 @@ function isEmptyString() /** * Matches if value is a zero-length string. */ - function emptyString() + function emptyString(): \Hamcrest\Text\IsEmptyString { return \Hamcrest\Text\IsEmptyString::isEmptyString(); } @@ -613,7 +635,7 @@ function emptyString() /** * Matches if value is null or a zero-length string. */ - function isEmptyOrNullString() + function isEmptyOrNullString(): \Hamcrest\Core\AnyOf { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } @@ -623,7 +645,7 @@ function isEmptyOrNullString() /** * Matches if value is null or a zero-length string. */ - function nullOrEmptyString() + function nullOrEmptyString(): \Hamcrest\Core\AnyOf { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } @@ -633,7 +655,7 @@ function nullOrEmptyString() /** * Matches if value is a non-zero-length string. */ - function isNonEmptyString() + function isNonEmptyString(): \Hamcrest\Text\IsEmptyString { return \Hamcrest\Text\IsEmptyString::isNonEmptyString(); } @@ -643,7 +665,7 @@ function isNonEmptyString() /** * Matches if value is a non-zero-length string. */ - function nonEmptyString() + function nonEmptyString(): \Hamcrest\Text\IsEmptyString { return \Hamcrest\Text\IsEmptyString::isNonEmptyString(); } @@ -652,8 +674,9 @@ function nonEmptyString() if (!function_exists('equalToIgnoringCase')) { /** * Matches if value is a string equal to $string, regardless of the case. + * @param mixed $string */ - function equalToIgnoringCase($string) + function equalToIgnoringCase($string): \Hamcrest\Text\IsEqualIgnoringCase { return \Hamcrest\Text\IsEqualIgnoringCase::equalToIgnoringCase($string); } @@ -662,8 +685,9 @@ function equalToIgnoringCase($string) if (!function_exists('equalToIgnoringWhiteSpace')) { /** * Matches if value is a string equal to $string, regardless of whitespace. + * @param mixed $string */ - function equalToIgnoringWhiteSpace($string) + function equalToIgnoringWhiteSpace($string): \Hamcrest\Text\IsEqualIgnoringWhiteSpace { return \Hamcrest\Text\IsEqualIgnoringWhiteSpace::equalToIgnoringWhiteSpace($string); } @@ -672,8 +696,9 @@ function equalToIgnoringWhiteSpace($string) if (!function_exists('matchesPattern')) { /** * Matches if value is a string that matches regular expression $pattern. + * @param mixed $pattern */ - function matchesPattern($pattern) + function matchesPattern($pattern): \Hamcrest\Text\MatchesPattern { return \Hamcrest\Text\MatchesPattern::matchesPattern($pattern); } @@ -682,8 +707,9 @@ function matchesPattern($pattern) if (!function_exists('containsString')) { /** * Matches if value is a string that contains $substring. + * @param mixed $substring */ - function containsString($substring) + function containsString($substring): \Hamcrest\Text\StringContains { return \Hamcrest\Text\StringContains::containsString($substring); } @@ -692,8 +718,9 @@ function containsString($substring) if (!function_exists('containsStringIgnoringCase')) { /** * Matches if value is a string that contains $substring regardless of the case. + * @param mixed $substring */ - function containsStringIgnoringCase($substring) + function containsStringIgnoringCase($substring): \Hamcrest\Text\StringContainsIgnoringCase { return \Hamcrest\Text\StringContainsIgnoringCase::containsStringIgnoringCase($substring); } @@ -703,7 +730,7 @@ function containsStringIgnoringCase($substring) /** * Matches if value contains $substrings in a constrained order. */ - function stringContainsInOrder(/* args... */) + function stringContainsInOrder(/* args... */): \Hamcrest\Text\StringContainsInOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Text\StringContainsInOrder', 'stringContainsInOrder'), $args); @@ -713,8 +740,9 @@ function stringContainsInOrder(/* args... */) if (!function_exists('endsWith')) { /** * Matches if value is a string that ends with $substring. + * @param mixed $substring */ - function endsWith($substring) + function endsWith($substring): \Hamcrest\Text\StringEndsWith { return \Hamcrest\Text\StringEndsWith::endsWith($substring); } @@ -723,8 +751,9 @@ function endsWith($substring) if (!function_exists('startsWith')) { /** * Matches if value is a string that starts with $substring. + * @param mixed $substring */ - function startsWith($substring) + function startsWith($substring): \Hamcrest\Text\StringStartsWith { return \Hamcrest\Text\StringStartsWith::startsWith($substring); } @@ -734,7 +763,7 @@ function startsWith($substring) /** * Is the value an array? */ - function arrayValue() + function arrayValue(): \Hamcrest\Type\IsArray { return \Hamcrest\Type\IsArray::arrayValue(); } @@ -744,7 +773,7 @@ function arrayValue() /** * Is the value a boolean? */ - function booleanValue() + function booleanValue(): \Hamcrest\Type\IsBoolean { return \Hamcrest\Type\IsBoolean::booleanValue(); } @@ -754,7 +783,7 @@ function booleanValue() /** * Is the value a boolean? */ - function boolValue() + function boolValue(): \Hamcrest\Type\IsBoolean { return \Hamcrest\Type\IsBoolean::booleanValue(); } @@ -764,7 +793,7 @@ function boolValue() /** * Is the value callable? */ - function callableValue() + function callableValue(): \Hamcrest\Type\IsCallable { return \Hamcrest\Type\IsCallable::callableValue(); } @@ -774,7 +803,7 @@ function callableValue() /** * Is the value a float/double? */ - function doubleValue() + function doubleValue(): \Hamcrest\Type\IsDouble { return \Hamcrest\Type\IsDouble::doubleValue(); } @@ -784,7 +813,7 @@ function doubleValue() /** * Is the value a float/double? */ - function floatValue() + function floatValue(): \Hamcrest\Type\IsDouble { return \Hamcrest\Type\IsDouble::doubleValue(); } @@ -794,7 +823,7 @@ function floatValue() /** * Is the value an integer? */ - function integerValue() + function integerValue(): \Hamcrest\Type\IsInteger { return \Hamcrest\Type\IsInteger::integerValue(); } @@ -804,7 +833,7 @@ function integerValue() /** * Is the value an integer? */ - function intValue() + function intValue(): \Hamcrest\Type\IsInteger { return \Hamcrest\Type\IsInteger::integerValue(); } @@ -814,7 +843,7 @@ function intValue() /** * Is the value a numeric? */ - function numericValue() + function numericValue(): \Hamcrest\Type\IsNumeric { return \Hamcrest\Type\IsNumeric::numericValue(); } @@ -824,7 +853,7 @@ function numericValue() /** * Is the value an object? */ - function objectValue() + function objectValue(): \Hamcrest\Type\IsObject { return \Hamcrest\Type\IsObject::objectValue(); } @@ -834,7 +863,7 @@ function objectValue() /** * Is the value an object? */ - function anObject() + function anObject(): \Hamcrest\Type\IsObject { return \Hamcrest\Type\IsObject::objectValue(); } @@ -844,7 +873,7 @@ function anObject() /** * Is the value a resource? */ - function resourceValue() + function resourceValue(): \Hamcrest\Type\IsResource { return \Hamcrest\Type\IsResource::resourceValue(); } @@ -854,7 +883,7 @@ function resourceValue() /** * Is the value a scalar (boolean, integer, double, or string)? */ - function scalarValue() + function scalarValue(): \Hamcrest\Type\IsScalar { return \Hamcrest\Type\IsScalar::scalarValue(); } @@ -864,7 +893,7 @@ function scalarValue() /** * Is the value a string? */ - function stringValue() + function stringValue(): \Hamcrest\Type\IsString { return \Hamcrest\Type\IsString::stringValue(); } @@ -875,8 +904,10 @@ function stringValue() * Wraps $matcher with {@link Hamcrest\Core\IsEqual) * if it's not a matcher and the XPath in count() * if it's an integer. + * @param string $xpath + * @param null|Matcher|int|mixed $matcher */ - function hasXPath($xpath, $matcher = null) + function hasXPath($xpath, $matcher = null): \Hamcrest\Xml\HasXPath { return \Hamcrest\Xml\HasXPath::hasXPath($xpath, $matcher); } diff --git a/hamcrest/Hamcrest/Arrays/IsArray.php b/hamcrest/Hamcrest/Arrays/IsArray.php index 9ea569703..0d90d3860 100644 --- a/hamcrest/Hamcrest/Arrays/IsArray.php +++ b/hamcrest/Hamcrest/Arrays/IsArray.php @@ -10,6 +10,7 @@ // TODO: Allow this to take matchers or values within the array use Hamcrest\Description; +use Hamcrest\Matcher; use Hamcrest\TypeSafeMatcher; use Hamcrest\Util; @@ -20,8 +21,14 @@ class IsArray extends TypeSafeMatcher { - private $_elementMatchers; + /** + * @var array + */ + private array $_elementMatchers; + /** + * @param array $elementMatchers + */ public function __construct(array $elementMatchers) { parent::__construct(self::TYPE_ARRAY); @@ -31,13 +38,12 @@ public function __construct(array $elementMatchers) $this->_elementMatchers = $elementMatchers; } - protected function matchesSafely($array) + protected function matchesSafely($array): bool { if (array_keys($array) != array_keys($this->_elementMatchers)) { return false; } - /** @var $matcher \Hamcrest\Matcher */ foreach ($this->_elementMatchers as $k => $matcher) { if (!$matcher->matches($array[$k])) { return false; @@ -47,7 +53,7 @@ protected function matchesSafely($array) return true; } - protected function describeMismatchSafely($actual, Description $mismatchDescription) + protected function describeMismatchSafely($actual, Description $mismatchDescription): void { if (count($actual) != count($this->_elementMatchers)) { $mismatchDescription->appendText('array length was ' . count($actual)); @@ -66,7 +72,6 @@ protected function describeMismatchSafely($actual, Description $mismatchDescript return; } - /** @var $matcher \Hamcrest\Matcher */ foreach ($this->_elementMatchers as $k => $matcher) { if (!$matcher->matches($actual[$k])) { $mismatchDescription->appendText('element ')->appendValue($k) @@ -77,7 +82,7 @@ protected function describeMismatchSafely($actual, Description $mismatchDescript } } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendList( $this->descriptionStart(), @@ -92,7 +97,7 @@ public function describeTo(Description $description) * * @factory ... */ - public static function anArray(/* args... */) + public static function anArray(/* args... */): self { $args = func_get_args(); @@ -101,17 +106,17 @@ public static function anArray(/* args... */) // -- Protected Methods - protected function descriptionStart() + protected function descriptionStart(): string { return '['; } - protected function descriptionSeparator() + protected function descriptionSeparator(): string { return ', '; } - protected function descriptionEnd() + protected function descriptionEnd(): string { return ']'; } diff --git a/hamcrest/Hamcrest/Arrays/IsArrayContaining.php b/hamcrest/Hamcrest/Arrays/IsArrayContaining.php index 0e4a1eda9..b267e3fb7 100644 --- a/hamcrest/Hamcrest/Arrays/IsArrayContaining.php +++ b/hamcrest/Hamcrest/Arrays/IsArrayContaining.php @@ -15,7 +15,7 @@ class IsArrayContaining extends TypeSafeMatcher { - private $_elementMatcher; + private Matcher $_elementMatcher; public function __construct(Matcher $elementMatcher) { @@ -24,7 +24,7 @@ public function __construct(Matcher $elementMatcher) $this->_elementMatcher = $elementMatcher; } - protected function matchesSafely($array) + protected function matchesSafely($array): bool { foreach ($array as $element) { if ($this->_elementMatcher->matches($element)) { @@ -35,12 +35,12 @@ protected function matchesSafely($array) return false; } - protected function describeMismatchSafely($array, Description $mismatchDescription) + protected function describeMismatchSafely($array, Description $mismatchDescription): void { $mismatchDescription->appendText('was ')->appendValue($array); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description ->appendText('an array containing ') @@ -56,7 +56,7 @@ public function describeTo(Description $description) * @return \Hamcrest\Arrays\IsArrayContaining * @factory hasValue */ - public static function hasItemInArray($item) + public static function hasItemInArray($item): self { return new self(Util::wrapValueWithIsEqual($item)); } diff --git a/hamcrest/Hamcrest/Arrays/IsArrayContainingInAnyOrder.php b/hamcrest/Hamcrest/Arrays/IsArrayContainingInAnyOrder.php index 9009026b8..185737e75 100644 --- a/hamcrest/Hamcrest/Arrays/IsArrayContainingInAnyOrder.php +++ b/hamcrest/Hamcrest/Arrays/IsArrayContainingInAnyOrder.php @@ -5,6 +5,7 @@ Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; +use Hamcrest\Matcher; use Hamcrest\TypeSafeDiagnosingMatcher; use Hamcrest\Util; @@ -14,8 +15,14 @@ class IsArrayContainingInAnyOrder extends TypeSafeDiagnosingMatcher { - private $_elementMatchers; + /** + * @var array + */ + private array $_elementMatchers; + /** + * @param array $elementMatchers + */ public function __construct(array $elementMatchers) { parent::__construct(self::TYPE_ARRAY); @@ -25,7 +32,7 @@ public function __construct(array $elementMatchers) $this->_elementMatchers = $elementMatchers; } - protected function matchesSafelyWithDiagnosticDescription($array, Description $mismatchDescription) + protected function matchesSafelyWithDiagnosticDescription($array, Description $mismatchDescription): bool { $matching = new MatchingOnce($this->_elementMatchers, $mismatchDescription); @@ -38,7 +45,7 @@ protected function matchesSafelyWithDiagnosticDescription($array, Description $m return $matching->isFinished($array); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendList('[', ', ', ']', $this->_elementMatchers) ->appendText(' in any order') @@ -50,7 +57,7 @@ public function describeTo(Description $description) * * @factory containsInAnyOrder ... */ - public static function arrayContainingInAnyOrder(/* args... */) + public static function arrayContainingInAnyOrder(/* args... */): self { $args = func_get_args(); diff --git a/hamcrest/Hamcrest/Arrays/IsArrayContainingInOrder.php b/hamcrest/Hamcrest/Arrays/IsArrayContainingInOrder.php index 611574045..b28cd442a 100644 --- a/hamcrest/Hamcrest/Arrays/IsArrayContainingInOrder.php +++ b/hamcrest/Hamcrest/Arrays/IsArrayContainingInOrder.php @@ -5,6 +5,7 @@ Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; +use Hamcrest\Matcher; use Hamcrest\TypeSafeDiagnosingMatcher; use Hamcrest\Util; @@ -14,8 +15,14 @@ class IsArrayContainingInOrder extends TypeSafeDiagnosingMatcher { - private $_elementMatchers; + /** + * @var array + */ + private array $_elementMatchers; + /** + * @param array $elementMatchers + */ public function __construct(array $elementMatchers) { parent::__construct(self::TYPE_ARRAY); @@ -25,7 +32,7 @@ public function __construct(array $elementMatchers) $this->_elementMatchers = $elementMatchers; } - protected function matchesSafelyWithDiagnosticDescription($array, Description $mismatchDescription) + protected function matchesSafelyWithDiagnosticDescription($array, Description $mismatchDescription): bool { $series = new SeriesMatchingOnce($this->_elementMatchers, $mismatchDescription); @@ -38,7 +45,7 @@ protected function matchesSafelyWithDiagnosticDescription($array, Description $m return $series->isFinished(); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendList('[', ', ', ']', $this->_elementMatchers); } @@ -48,7 +55,7 @@ public function describeTo(Description $description) * * @factory contains ... */ - public static function arrayContaining(/* args... */) + public static function arrayContaining(/* args... */): self { $args = func_get_args(); diff --git a/hamcrest/Hamcrest/Arrays/IsArrayContainingKey.php b/hamcrest/Hamcrest/Arrays/IsArrayContainingKey.php index 523477e7b..be556bde6 100644 --- a/hamcrest/Hamcrest/Arrays/IsArrayContainingKey.php +++ b/hamcrest/Hamcrest/Arrays/IsArrayContainingKey.php @@ -15,7 +15,7 @@ class IsArrayContainingKey extends TypeSafeMatcher { - private $_keyMatcher; + private Matcher $_keyMatcher; public function __construct(Matcher $keyMatcher) { @@ -24,7 +24,7 @@ public function __construct(Matcher $keyMatcher) $this->_keyMatcher = $keyMatcher; } - protected function matchesSafely($array) + protected function matchesSafely($array): bool { foreach ($array as $key => $element) { if ($this->_keyMatcher->matches($key)) { @@ -35,7 +35,7 @@ protected function matchesSafely($array) return false; } - protected function describeMismatchSafely($array, Description $mismatchDescription) + protected function describeMismatchSafely($array, Description $mismatchDescription): void { //Not using appendValueList() so that keys can be shown $mismatchDescription->appendText('array was ') @@ -52,7 +52,7 @@ protected function describeMismatchSafely($array, Description $mismatchDescripti $mismatchDescription->appendText(']'); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description ->appendText('array with key ') @@ -68,7 +68,7 @@ public function describeTo(Description $description) * @return \Hamcrest\Arrays\IsArrayContainingKey * @factory hasKey */ - public static function hasKeyInArray($key) + public static function hasKeyInArray($key): self { return new self(Util::wrapValueWithIsEqual($key)); } diff --git a/hamcrest/Hamcrest/Arrays/IsArrayContainingKeyValuePair.php b/hamcrest/Hamcrest/Arrays/IsArrayContainingKeyValuePair.php index 9ac3eba80..627466dd8 100644 --- a/hamcrest/Hamcrest/Arrays/IsArrayContainingKeyValuePair.php +++ b/hamcrest/Hamcrest/Arrays/IsArrayContainingKeyValuePair.php @@ -15,8 +15,13 @@ class IsArrayContainingKeyValuePair extends TypeSafeMatcher { - + /** + * @var mixed $_keyMatcher + */ private $_keyMatcher; + /** + * @var mixed $_valueMatcher + */ private $_valueMatcher; public function __construct(Matcher $keyMatcher, Matcher $valueMatcher) @@ -27,7 +32,7 @@ public function __construct(Matcher $keyMatcher, Matcher $valueMatcher) $this->_valueMatcher = $valueMatcher; } - protected function matchesSafely($array) + protected function matchesSafely($array): bool { foreach ($array as $key => $value) { if ($this->_keyMatcher->matches($key) && $this->_valueMatcher->matches($value)) { @@ -38,7 +43,7 @@ protected function matchesSafely($array) return false; } - protected function describeMismatchSafely($array, Description $mismatchDescription) + protected function describeMismatchSafely($array, Description $mismatchDescription): void { //Not using appendValueList() so that keys can be shown $mismatchDescription->appendText('array was ') @@ -55,7 +60,7 @@ protected function describeMismatchSafely($array, Description $mismatchDescripti $mismatchDescription->appendText(']'); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('array containing [') ->appendDescriptionOf($this->_keyMatcher) @@ -69,8 +74,10 @@ public function describeTo(Description $description) * Test if an array has both an key and value in parity with each other. * * @factory hasEntry + * @param mixed $key + * @param mixed $value */ - public static function hasKeyValuePair($key, $value) + public static function hasKeyValuePair($key, $value): self { return new self( Util::wrapValueWithIsEqual($key), diff --git a/hamcrest/Hamcrest/Arrays/IsArrayWithSize.php b/hamcrest/Hamcrest/Arrays/IsArrayWithSize.php index 074375ce1..4be0ef31e 100644 --- a/hamcrest/Hamcrest/Arrays/IsArrayWithSize.php +++ b/hamcrest/Hamcrest/Arrays/IsArrayWithSize.php @@ -40,7 +40,7 @@ protected function featureValueOf($array) * @return \Hamcrest\Arrays\IsArrayWithSize * @factory */ - public static function arrayWithSize($size) + public static function arrayWithSize($size): self { return new self(Util::wrapValueWithIsEqual($size)); } @@ -50,7 +50,7 @@ public static function arrayWithSize($size) * * @factory */ - public static function emptyArray() + public static function emptyArray(): DescribedAs { return DescribedAs::describedAs( 'an empty array', @@ -63,7 +63,7 @@ public static function emptyArray() * * @factory */ - public static function nonEmptyArray() + public static function nonEmptyArray(): DescribedAs { return DescribedAs::describedAs( 'a non-empty array', diff --git a/hamcrest/Hamcrest/Arrays/MatchingOnce.php b/hamcrest/Hamcrest/Arrays/MatchingOnce.php index 324c7e089..f8051afde 100644 --- a/hamcrest/Hamcrest/Arrays/MatchingOnce.php +++ b/hamcrest/Hamcrest/Arrays/MatchingOnce.php @@ -6,25 +6,38 @@ */ use Hamcrest\Description; +use Hamcrest\Matcher; class MatchingOnce { - private $_elementMatchers; - private $_mismatchDescription; + /** + * @var array + */ + private array $_elementMatchers; + private Description $_mismatchDescription; + /** + * @param array $elementMatchers + */ public function __construct(array $elementMatchers, Description $mismatchDescription) { $this->_elementMatchers = $elementMatchers; $this->_mismatchDescription = $mismatchDescription; } - public function matches($item) + /** + * @param mixed $item + */ + public function matches($item): bool { return $this->_isNotSurplus($item) && $this->_isMatched($item); } - public function isFinished($items) + /** + * @param mixed $items + */ + public function isFinished($items): bool { if (empty($this->_elementMatchers)) { return true; @@ -40,7 +53,10 @@ public function isFinished($items) // -- Private Methods - private function _isNotSurplus($item) + /** + * @param mixed $item + */ + private function _isNotSurplus($item): bool { if (empty($this->_elementMatchers)) { $this->_mismatchDescription->appendText('Not matched: ')->appendValue($item); @@ -51,9 +67,11 @@ private function _isNotSurplus($item) return true; } - private function _isMatched($item) + /** + * @param mixed $item + */ + private function _isMatched($item): bool { - /** @var $matcher \Hamcrest\Matcher */ foreach ($this->_elementMatchers as $i => $matcher) { if ($matcher->matches($item)) { unset($this->_elementMatchers[$i]); diff --git a/hamcrest/Hamcrest/Arrays/SeriesMatchingOnce.php b/hamcrest/Hamcrest/Arrays/SeriesMatchingOnce.php index 12a912d86..3df544a03 100644 --- a/hamcrest/Hamcrest/Arrays/SeriesMatchingOnce.php +++ b/hamcrest/Hamcrest/Arrays/SeriesMatchingOnce.php @@ -11,11 +11,23 @@ class SeriesMatchingOnce { - private $_elementMatchers; - private $_keys; - private $_mismatchDescription; + /** + * @var array + */ + private array $_elementMatchers; + /** + * @var list + */ + private array $_keys; + private Description $_mismatchDescription; + /** + * @var int|string|null + */ private $_nextMatchKey; + /** + * @param array $elementMatchers + */ public function __construct(array $elementMatchers, Description $mismatchDescription) { $this->_elementMatchers = $elementMatchers; @@ -23,12 +35,15 @@ public function __construct(array $elementMatchers, Description $mismatchDescrip $this->_mismatchDescription = $mismatchDescription; } - public function matches($item) + /** + * @param mixed $item + */ + public function matches($item): bool { return $this->_isNotSurplus($item) && $this->_isMatched($item); } - public function isFinished() + public function isFinished(): bool { if (!empty($this->_elementMatchers)) { $nextMatcher = current($this->_elementMatchers); @@ -42,7 +57,10 @@ public function isFinished() // -- Private Methods - private function _isNotSurplus($item) + /** + * @param mixed $item + */ + private function _isNotSurplus($item): bool { if (empty($this->_elementMatchers)) { $this->_mismatchDescription->appendText('Not matched: ')->appendValue($item); @@ -53,7 +71,10 @@ private function _isNotSurplus($item) return true; } - private function _isMatched($item) + /** + * @param mixed $item + */ + private function _isMatched($item): bool { $this->_nextMatchKey = array_shift($this->_keys); $nextMatcher = array_shift($this->_elementMatchers); @@ -67,7 +88,10 @@ private function _isMatched($item) return true; } - private function _describeMismatch(Matcher $matcher, $item) + /** + * @param mixed $item + */ + private function _describeMismatch(Matcher $matcher, $item): void { $this->_mismatchDescription->appendText('item with key ' . $this->_nextMatchKey . ': '); $matcher->describeMismatch($item, $this->_mismatchDescription); diff --git a/hamcrest/Hamcrest/BaseDescription.php b/hamcrest/Hamcrest/BaseDescription.php index bcd4fef8c..4f0fce55f 100644 --- a/hamcrest/Hamcrest/BaseDescription.php +++ b/hamcrest/Hamcrest/BaseDescription.php @@ -12,21 +12,21 @@ abstract class BaseDescription implements Description { - public function appendText($text) + public function appendText(string $text): self { $this->append($text); return $this; } - public function appendDescriptionOf(SelfDescribing $value) + public function appendDescriptionOf(SelfDescribing $value): self { $value->describeTo($this); return $this; } - public function appendValue($value) + public function appendValue($value): self { if (is_null($value)) { $this->append('null'); @@ -55,7 +55,7 @@ public function appendValue($value) return $this; } - public function appendValueList($start, $separator, $end, $values) + public function appendValueList(string $start, string $separator, string $end, iterable $values): self { $list = array(); foreach ($values as $v) { @@ -67,7 +67,7 @@ public function appendValueList($start, $separator, $end, $values) return $this; } - public function appendList($start, $separator, $end, $values) + public function appendList(string $start, string $separator, string $end, iterable $values): self { $this->append($start); @@ -96,12 +96,13 @@ public function appendList($start, $separator, $end, $values) /** * Append the String $str to the description. + * @param mixed $str */ - abstract protected function append($str); + abstract protected function append($str): void; // -- Private Methods - private function _toPhpSyntax($value) + private function _toPhpSyntax(string $value): void { $str = '"'; for ($i = 0, $len = strlen($value); $i < $len; ++$i) { diff --git a/hamcrest/Hamcrest/BaseMatcher.php b/hamcrest/Hamcrest/BaseMatcher.php index 06055698c..679f38112 100644 --- a/hamcrest/Hamcrest/BaseMatcher.php +++ b/hamcrest/Hamcrest/BaseMatcher.php @@ -12,18 +12,20 @@ */ abstract class BaseMatcher implements Matcher { - - public function describeMismatch($item, Description $description) + /** + * @param mixed $item + */ + public function describeMismatch($item, Description $description): void { $description->appendText('was ')->appendValue($item); } - public function __toString() + public function __toString(): string { return StringDescription::toString($this); } - public function __invoke() + public function __invoke(): bool { return call_user_func_array(array($this, 'matches'), func_get_args()); } diff --git a/hamcrest/Hamcrest/Collection/IsEmptyTraversable.php b/hamcrest/Hamcrest/Collection/IsEmptyTraversable.php index 8ab58ea5a..855d4e4ac 100644 --- a/hamcrest/Hamcrest/Collection/IsEmptyTraversable.php +++ b/hamcrest/Hamcrest/Collection/IsEmptyTraversable.php @@ -13,17 +13,17 @@ class IsEmptyTraversable extends BaseMatcher { - private static $_INSTANCE; - private static $_NOT_INSTANCE; + private static ?self $_INSTANCE = null; + private static ?self $_NOT_INSTANCE = null; - private $_empty; + private bool $_empty; - public function __construct($empty = true) + public function __construct(bool $empty = true) { $this->_empty = $empty; } - public function matches($item) + public function matches($item): bool { if (!$item instanceof \Traversable) { return false; @@ -36,7 +36,7 @@ public function matches($item) return $this->_empty; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText($this->_empty ? 'an empty traversable' : 'a non-empty traversable'); } @@ -46,7 +46,7 @@ public function describeTo(Description $description) * * @factory */ - public static function emptyTraversable() + public static function emptyTraversable(): self { if (!self::$_INSTANCE) { self::$_INSTANCE = new self; @@ -60,7 +60,7 @@ public static function emptyTraversable() * * @factory */ - public static function nonEmptyTraversable() + public static function nonEmptyTraversable(): self { if (!self::$_NOT_INSTANCE) { self::$_NOT_INSTANCE = new self(false); diff --git a/hamcrest/Hamcrest/Collection/IsTraversableWithSize.php b/hamcrest/Hamcrest/Collection/IsTraversableWithSize.php index c95edc5c3..a0f89c801 100644 --- a/hamcrest/Hamcrest/Collection/IsTraversableWithSize.php +++ b/hamcrest/Hamcrest/Collection/IsTraversableWithSize.php @@ -39,8 +39,9 @@ protected function featureValueOf($actual) * Does traversable size satisfy a given matcher? * * @factory + * @param mixed $size */ - public static function traversableWithSize($size) + public static function traversableWithSize($size): self { return new self(Util::wrapValueWithIsEqual($size)); } diff --git a/hamcrest/Hamcrest/Core/AllOf.php b/hamcrest/Hamcrest/Core/AllOf.php index 7aefd5386..bdf3faf84 100644 --- a/hamcrest/Hamcrest/Core/AllOf.php +++ b/hamcrest/Hamcrest/Core/AllOf.php @@ -6,6 +6,7 @@ */ use Hamcrest\Description; use Hamcrest\DiagnosingMatcher; +use Hamcrest\Matcher; use Hamcrest\Util; /** @@ -16,8 +17,14 @@ class AllOf extends DiagnosingMatcher { - private $_matchers; + /** + * @var array + */ + private array $_matchers; + /** + * @param array $matchers + */ public function __construct(array $matchers) { Util::checkAllAreMatchers($matchers); @@ -25,9 +32,8 @@ public function __construct(array $matchers) $this->_matchers = $matchers; } - public function matchesWithDiagnosticDescription($item, Description $mismatchDescription) + public function matchesWithDiagnosticDescription($item, Description $mismatchDescription): bool { - /** @var $matcher \Hamcrest\Matcher */ foreach ($this->_matchers as $matcher) { if (!$matcher->matches($item)) { $mismatchDescription->appendDescriptionOf($matcher)->appendText(' '); @@ -40,7 +46,7 @@ public function matchesWithDiagnosticDescription($item, Description $mismatchDes return true; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendList('(', ' and ', ')', $this->_matchers); } @@ -50,7 +56,7 @@ public function describeTo(Description $description) * * @factory ... */ - public static function allOf(/* args... */) + public static function allOf(/* args... */): self { $args = func_get_args(); diff --git a/hamcrest/Hamcrest/Core/AnyOf.php b/hamcrest/Hamcrest/Core/AnyOf.php index 4504279f3..4f04d8c00 100644 --- a/hamcrest/Hamcrest/Core/AnyOf.php +++ b/hamcrest/Hamcrest/Core/AnyOf.php @@ -5,6 +5,7 @@ Copyright (c) 2009 hamcrest.org */ use Hamcrest\Description; +use Hamcrest\Matcher; use Hamcrest\Util; /** @@ -15,17 +16,20 @@ class AnyOf extends ShortcutCombination { + /** + * @param array $matchers + */ public function __construct(array $matchers) { parent::__construct($matchers); } - public function matches($item) + public function matches($item): bool { return $this->matchesWithShortcut($item, true); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $this->describeToWithOperator($description, 'or'); } @@ -35,7 +39,7 @@ public function describeTo(Description $description) * * @factory ... */ - public static function anyOf(/* args... */) + public static function anyOf(/* args... */): self { $args = func_get_args(); @@ -47,7 +51,7 @@ public static function anyOf(/* args... */) * * @factory ... */ - public static function noneOf(/* args... */) + public static function noneOf(/* args... */): IsNot { $args = func_get_args(); diff --git a/hamcrest/Hamcrest/Core/CombinableMatcher.php b/hamcrest/Hamcrest/Core/CombinableMatcher.php index e3b4aa782..7a4574832 100644 --- a/hamcrest/Hamcrest/Core/CombinableMatcher.php +++ b/hamcrest/Hamcrest/Core/CombinableMatcher.php @@ -12,31 +12,31 @@ class CombinableMatcher extends BaseMatcher { - private $_matcher; + private Matcher $_matcher; public function __construct(Matcher $matcher) { $this->_matcher = $matcher; } - public function matches($item) + public function matches($item): bool { return $this->_matcher->matches($item); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendDescriptionOf($this->_matcher); } /** Diversion from Hamcrest-Java... Logical "and" not permitted */ - public function andAlso(Matcher $other) + public function andAlso(Matcher $other): self { return new self(new AllOf($this->_templatedListWith($other))); } /** Diversion from Hamcrest-Java... Logical "or" not permitted */ - public function orElse(Matcher $other) + public function orElse(Matcher $other): self { return new self(new AnyOf($this->_templatedListWith($other))); } @@ -50,7 +50,7 @@ public function orElse(Matcher $other) * * @factory */ - public static function both(Matcher $matcher) + public static function both(Matcher $matcher): self { return new self($matcher); } @@ -64,14 +64,17 @@ public static function both(Matcher $matcher) * * @factory */ - public static function either(Matcher $matcher) + public static function either(Matcher $matcher): self { return new self($matcher); } // -- Private Methods - private function _templatedListWith(Matcher $other) + /** + * @return list + */ + private function _templatedListWith(Matcher $other): array { return array($this->_matcher, $other); } diff --git a/hamcrest/Hamcrest/Core/DescribedAs.php b/hamcrest/Hamcrest/Core/DescribedAs.php index 5b2583fa7..5b6faca1d 100644 --- a/hamcrest/Hamcrest/Core/DescribedAs.php +++ b/hamcrest/Hamcrest/Core/DescribedAs.php @@ -14,25 +14,31 @@ class DescribedAs extends BaseMatcher { - private $_descriptionTemplate; - private $_matcher; - private $_values; + private string $_descriptionTemplate; + private Matcher $_matcher; + /** + * @var array + */ + private array $_values; - const ARG_PATTERN = '/%([0-9]+)/'; + private const ARG_PATTERN = '/%([0-9]+)/'; - public function __construct($descriptionTemplate, Matcher $matcher, array $values) + /** + * @param array $values + */ + public function __construct(string $descriptionTemplate, Matcher $matcher, array $values) { $this->_descriptionTemplate = $descriptionTemplate; $this->_matcher = $matcher; $this->_values = $values; } - public function matches($item) + public function matches($item): bool { return $this->_matcher->matches($item); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $textStart = 0; while (preg_match(self::ARG_PATTERN, $this->_descriptionTemplate, $matches, PREG_OFFSET_CAPTURE, $textStart)) { @@ -55,14 +61,10 @@ public function describeTo(Description $description) * Wraps an existing matcher and overrides the description when it fails. * * @factory ... + * @param mixed ...$values */ - public static function describedAs(/* $description, Hamcrest\Matcher $matcher, $values... */) + public static function describedAs(string $descriptionTemplate, \Hamcrest\Matcher $matcher, ...$values): self { - $args = func_get_args(); - $description = array_shift($args); - $matcher = array_shift($args); - $values = $args; - - return new self($description, $matcher, $values); + return new self($descriptionTemplate, $matcher, $values); } } diff --git a/hamcrest/Hamcrest/Core/Every.php b/hamcrest/Hamcrest/Core/Every.php index d686f8dac..fd202fa80 100644 --- a/hamcrest/Hamcrest/Core/Every.php +++ b/hamcrest/Hamcrest/Core/Every.php @@ -12,7 +12,7 @@ class Every extends TypeSafeDiagnosingMatcher { - private $_matcher; + private Matcher $_matcher; public function __construct(Matcher $matcher) { @@ -21,7 +21,7 @@ public function __construct(Matcher $matcher) $this->_matcher = $matcher; } - protected function matchesSafelyWithDiagnosticDescription($items, Description $mismatchDescription) + protected function matchesSafelyWithDiagnosticDescription($items, Description $mismatchDescription): bool { foreach ($items as $item) { if (!$this->_matcher->matches($item)) { @@ -35,7 +35,7 @@ protected function matchesSafelyWithDiagnosticDescription($items, Description $m return true; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('every item is ')->appendDescriptionOf($this->_matcher); } @@ -49,7 +49,7 @@ public function describeTo(Description $description) * * @factory */ - public static function everyItem(Matcher $itemMatcher) + public static function everyItem(Matcher $itemMatcher): self { return new self($itemMatcher); } diff --git a/hamcrest/Hamcrest/Core/HasToString.php b/hamcrest/Hamcrest/Core/HasToString.php index c2e4801ba..90ab0f827 100644 --- a/hamcrest/Hamcrest/Core/HasToString.php +++ b/hamcrest/Hamcrest/Core/HasToString.php @@ -26,7 +26,7 @@ public function __construct(Matcher $toStringMatcher) ); } - public function matchesSafelyWithDiagnosticDescription($actual, Description $mismatchDescription) + public function matchesSafelyWithDiagnosticDescription($actual, Description $mismatchDescription): bool { if (method_exists($actual, 'toString') || method_exists($actual, '__toString')) { return parent::matchesSafelyWithDiagnosticDescription($actual, $mismatchDescription); @@ -49,8 +49,9 @@ protected function featureValueOf($actual) * __toString() method returns a value equalTo the specified string. * * @factory + * @param mixed $matcher */ - public static function hasToString($matcher) + public static function hasToString($matcher): self { return new self(Util::wrapValueWithIsEqual($matcher)); } diff --git a/hamcrest/Hamcrest/Core/Is.php b/hamcrest/Hamcrest/Core/Is.php index 41266dc1f..fccfe1404 100644 --- a/hamcrest/Hamcrest/Core/Is.php +++ b/hamcrest/Hamcrest/Core/Is.php @@ -19,24 +19,24 @@ class Is extends BaseMatcher { - private $_matcher; + private Matcher $_matcher; public function __construct(Matcher $matcher) { $this->_matcher = $matcher; } - public function matches($arg) + public function matches($arg): bool { return $this->_matcher->matches($arg); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('is ')->appendDescriptionOf($this->_matcher); } - public function describeMismatch($item, Description $mismatchDescription) + public function describeMismatch($item, Description $mismatchDescription): void { $this->_matcher->describeMismatch($item, $mismatchDescription); } @@ -49,8 +49,9 @@ public function describeMismatch($item, Description $mismatchDescription) * vs. assertThat($cheese, is(equalTo($smelly))) * * @factory + * @param mixed $value */ - public static function is($value) + public static function is($value): self { return new self(Util::wrapValueWithIsEqual($value)); } diff --git a/hamcrest/Hamcrest/Core/IsAnything.php b/hamcrest/Hamcrest/Core/IsAnything.php index f20e6c0dc..2b9e19dc4 100644 --- a/hamcrest/Hamcrest/Core/IsAnything.php +++ b/hamcrest/Hamcrest/Core/IsAnything.php @@ -13,19 +13,19 @@ class IsAnything extends BaseMatcher { - private $_message; + private string $_message; - public function __construct($message = 'ANYTHING') + public function __construct(string $message = 'ANYTHING') { $this->_message = $message; } - public function matches($item) + public function matches($item): bool { return true; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText($this->_message); } @@ -38,7 +38,7 @@ public function describeTo(Description $description) * @return \Hamcrest\Core\IsAnything * @factory */ - public static function anything($description = 'ANYTHING') + public static function anything(string $description = 'ANYTHING') { return new self($description); } diff --git a/hamcrest/Hamcrest/Core/IsCollectionContaining.php b/hamcrest/Hamcrest/Core/IsCollectionContaining.php index 5e60426d1..a623a0397 100644 --- a/hamcrest/Hamcrest/Core/IsCollectionContaining.php +++ b/hamcrest/Hamcrest/Core/IsCollectionContaining.php @@ -15,7 +15,7 @@ class IsCollectionContaining extends TypeSafeMatcher { - private $_elementMatcher; + private Matcher $_elementMatcher; public function __construct(Matcher $elementMatcher) { @@ -24,7 +24,7 @@ public function __construct(Matcher $elementMatcher) $this->_elementMatcher = $elementMatcher; } - protected function matchesSafely($items) + protected function matchesSafely($items): bool { foreach ($items as $item) { if ($this->_elementMatcher->matches($item)) { @@ -35,12 +35,12 @@ protected function matchesSafely($items) return false; } - protected function describeMismatchSafely($items, Description $mismatchDescription) + protected function describeMismatchSafely($items, Description $mismatchDescription): void { $mismatchDescription->appendText('was ')->appendValue($items); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description ->appendText('a collection containing ') @@ -60,7 +60,7 @@ public function describeTo(Description $description) * * @factory ... */ - public static function hasItem() + public static function hasItem(): self { $args = func_get_args(); $firstArg = array_shift($args); @@ -79,7 +79,7 @@ public static function hasItem() * * @factory ... */ - public static function hasItems(/* args... */) + public static function hasItems(/* args... */): AllOf { $args = func_get_args(); $matchers = array(); diff --git a/hamcrest/Hamcrest/Core/IsEqual.php b/hamcrest/Hamcrest/Core/IsEqual.php index 523fba0b1..e37411b7a 100644 --- a/hamcrest/Hamcrest/Core/IsEqual.php +++ b/hamcrest/Hamcrest/Core/IsEqual.php @@ -13,20 +13,25 @@ */ class IsEqual extends BaseMatcher { - + /** + * @var mixed + */ private $_item; + /** + * @param mixed $item + */ public function __construct($item) { $this->_item = $item; } - public function matches($arg) + public function matches($arg): bool { return (($arg == $this->_item) && ($this->_item == $arg)); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendValue($this->_item); } @@ -36,8 +41,9 @@ public function describeTo(Description $description) * comparison operator? * * @factory + * @param mixed $item */ - public static function equalTo($item) + public static function equalTo($item): self { return new self($item); } diff --git a/hamcrest/Hamcrest/Core/IsIdentical.php b/hamcrest/Hamcrest/Core/IsIdentical.php index 28f7b36ea..6fad940a7 100644 --- a/hamcrest/Hamcrest/Core/IsIdentical.php +++ b/hamcrest/Hamcrest/Core/IsIdentical.php @@ -13,15 +13,21 @@ class IsIdentical extends IsSame { + /** + * @var mixed $_value + */ private $_value; + /** + * @param mixed $value + */ public function __construct($value) { parent::__construct($value); $this->_value = $value; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendValue($this->_value); } @@ -30,8 +36,9 @@ public function describeTo(Description $description) * Tests of the value is identical to $value as tested by the "===" operator. * * @factory + * @param mixed $value */ - public static function identicalTo($value) + public static function identicalTo($value): self { return new self($value); } diff --git a/hamcrest/Hamcrest/Core/IsInstanceOf.php b/hamcrest/Hamcrest/Core/IsInstanceOf.php index 7a5c92a6b..a3828372e 100644 --- a/hamcrest/Hamcrest/Core/IsInstanceOf.php +++ b/hamcrest/Hamcrest/Core/IsInstanceOf.php @@ -13,7 +13,7 @@ class IsInstanceOf extends DiagnosingMatcher { - private $_theClass; + private string $_theClass; /** * Creates a new instance of IsInstanceOf @@ -22,12 +22,12 @@ class IsInstanceOf extends DiagnosingMatcher * The predicate evaluates to true for instances of this class * or one of its subclasses. */ - public function __construct($theClass) + public function __construct(string $theClass) { $this->_theClass = $theClass; } - protected function matchesWithDiagnosticDescription($item, Description $mismatchDescription) + protected function matchesWithDiagnosticDescription($item, Description $mismatchDescription): bool { if (!is_object($item)) { $mismatchDescription->appendText('was ')->appendValue($item); @@ -45,7 +45,7 @@ protected function matchesWithDiagnosticDescription($item, Description $mismatch return true; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('an instance of ') ->appendText($this->_theClass) @@ -60,7 +60,7 @@ public function describeTo(Description $description) * * @factory any */ - public static function anInstanceOf($theClass) + public static function anInstanceOf(string $theClass): self { return new self($theClass); } diff --git a/hamcrest/Hamcrest/Core/IsNot.php b/hamcrest/Hamcrest/Core/IsNot.php index 167f0d063..1fb750f51 100644 --- a/hamcrest/Hamcrest/Core/IsNot.php +++ b/hamcrest/Hamcrest/Core/IsNot.php @@ -15,19 +15,19 @@ class IsNot extends BaseMatcher { - private $_matcher; + private Matcher $_matcher; public function __construct(Matcher $matcher) { $this->_matcher = $matcher; } - public function matches($arg) + public function matches($arg): bool { return !$this->_matcher->matches($arg); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('not ')->appendDescriptionOf($this->_matcher); } @@ -36,8 +36,9 @@ public function describeTo(Description $description) * Matches if value does not match $value. * * @factory + * @param mixed $value */ - public static function not($value) + public static function not($value): self { return new self(Util::wrapValueWithIsEqual($value)); } diff --git a/hamcrest/Hamcrest/Core/IsNull.php b/hamcrest/Hamcrest/Core/IsNull.php index 91a454c17..84686f744 100644 --- a/hamcrest/Hamcrest/Core/IsNull.php +++ b/hamcrest/Hamcrest/Core/IsNull.php @@ -4,8 +4,10 @@ /* Copyright (c) 2009 hamcrest.org */ + use Hamcrest\BaseMatcher; use Hamcrest\Description; +use Hamcrest\Matcher; /** * Is the value null? @@ -13,15 +15,15 @@ class IsNull extends BaseMatcher { - private static $_INSTANCE; - private static $_NOT_INSTANCE; + private static ?self $_INSTANCE = null; + private static ?IsNot $_NOT_INSTANCE = null; - public function matches($item) + public function matches($item): bool { return is_null($item); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('null'); } @@ -31,7 +33,7 @@ public function describeTo(Description $description) * * @factory */ - public static function nullValue() + public static function nullValue(): self { if (!self::$_INSTANCE) { self::$_INSTANCE = new self(); @@ -45,7 +47,7 @@ public static function nullValue() * * @factory */ - public static function notNullValue() + public static function notNullValue(): IsNot { if (!self::$_NOT_INSTANCE) { self::$_NOT_INSTANCE = IsNot::not(self::nullValue()); diff --git a/hamcrest/Hamcrest/Core/IsSame.php b/hamcrest/Hamcrest/Core/IsSame.php index 810787050..f7e4c32a3 100644 --- a/hamcrest/Hamcrest/Core/IsSame.php +++ b/hamcrest/Hamcrest/Core/IsSame.php @@ -14,19 +14,25 @@ class IsSame extends BaseMatcher { + /** + * @var mixed object + */ private $_object; + /** + * @param mixed $object + */ public function __construct($object) { $this->_object = $object; } - public function matches($object) + public function matches($object): bool { return ($object === $this->_object) && ($this->_object === $object); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('sameInstance(') ->appendValue($this->_object) @@ -44,7 +50,7 @@ public function describeTo(Description $description) * @return \Hamcrest\Core\IsSame * @factory */ - public static function sameInstance($object) + public static function sameInstance($object): self { return new self($object); } diff --git a/hamcrest/Hamcrest/Core/IsTypeOf.php b/hamcrest/Hamcrest/Core/IsTypeOf.php index d24f0f94c..9fa874ff0 100644 --- a/hamcrest/Hamcrest/Core/IsTypeOf.php +++ b/hamcrest/Hamcrest/Core/IsTypeOf.php @@ -13,7 +13,7 @@ class IsTypeOf extends BaseMatcher { - private $_theType; + private string $_theType; /** * Creates a new instance of IsTypeOf @@ -21,22 +21,22 @@ class IsTypeOf extends BaseMatcher * @param string $theType * The predicate evaluates to true for values with this built-in type. */ - public function __construct($theType) + public function __construct(string $theType) { $this->_theType = strtolower($theType); } - public function matches($item) + public function matches($item): bool { return strtolower(gettype($item)) == $this->_theType; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText(self::getTypeDescription($this->_theType)); } - public function describeMismatch($item, Description $description) + public function describeMismatch($item, Description $description): void { if ($item === null) { $description->appendText('was null'); @@ -49,7 +49,7 @@ public function describeMismatch($item, Description $description) } } - public static function getTypeDescription($type) + public static function getTypeDescription(string $type): string { if ($type == 'null') { return 'null'; @@ -63,8 +63,9 @@ public static function getTypeDescription($type) * Is the value a particular built-in type? * * @factory + * @param string $theType */ - public static function typeOf($theType) + public static function typeOf(string $theType): self { return new self($theType); } diff --git a/hamcrest/Hamcrest/Core/Set.php b/hamcrest/Hamcrest/Core/Set.php index cdc45d538..8da692b3f 100644 --- a/hamcrest/Hamcrest/Core/Set.php +++ b/hamcrest/Hamcrest/Core/Set.php @@ -22,16 +22,22 @@ class Set extends BaseMatcher { + /** + * @var mixed $_property + */ private $_property; - private $_not; + private bool $_not; - public function __construct($property, $not = false) + /** + * @param mixed $property + */ + public function __construct($property, bool $not = false) { $this->_property = $property; $this->_not = $not; } - public function matches($item) + public function matches($item): bool { if ($item === null) { return false; @@ -50,12 +56,12 @@ public function matches($item) return $this->_not ? !$result : $result; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText($this->_not ? 'unset property ' : 'set property ')->appendText($this->_property); } - public function describeMismatch($item, Description $description) + public function describeMismatch($item, Description $description): void { $value = ''; if (!$this->_not) { @@ -77,8 +83,9 @@ public function describeMismatch($item, Description $description) * Matches if value (class, object, or array) has named $property. * * @factory + * @param mixed $property */ - public static function set($property) + public static function set($property): self { return new self($property); } @@ -87,8 +94,9 @@ public static function set($property) * Matches if value (class, object, or array) does not have named $property. * * @factory + * @param mixed $property */ - public static function notSet($property) + public static function notSet($property): self { return new self($property, true); } diff --git a/hamcrest/Hamcrest/Core/ShortcutCombination.php b/hamcrest/Hamcrest/Core/ShortcutCombination.php index d93db74ff..8638a3949 100644 --- a/hamcrest/Hamcrest/Core/ShortcutCombination.php +++ b/hamcrest/Hamcrest/Core/ShortcutCombination.php @@ -7,6 +7,7 @@ use Hamcrest\BaseMatcher; use Hamcrest\Description; +use Hamcrest\Matcher; use Hamcrest\Util; abstract class ShortcutCombination extends BaseMatcher @@ -17,6 +18,9 @@ abstract class ShortcutCombination extends BaseMatcher */ private $_matchers; + /** + * @param array<\Hamcrest\Matcher> $matchers + */ public function __construct(array $matchers) { Util::checkAllAreMatchers($matchers); @@ -24,9 +28,11 @@ public function __construct(array $matchers) $this->_matchers = $matchers; } - protected function matchesWithShortcut($item, $shortcut) + /** + * @param mixed $item + */ + protected function matchesWithShortcut($item, bool $shortcut): bool { - /** @var $matcher \Hamcrest\Matcher */ foreach ($this->_matchers as $matcher) { if ($matcher->matches($item) == $shortcut) { return $shortcut; @@ -36,7 +42,7 @@ protected function matchesWithShortcut($item, $shortcut) return !$shortcut; } - public function describeToWithOperator(Description $description, $operator) + public function describeToWithOperator(Description $description, string $operator): void { $description->appendList('(', ' ' . $operator . ' ', ')', $this->_matchers); } diff --git a/hamcrest/Hamcrest/Description.php b/hamcrest/Hamcrest/Description.php index b09554b28..4fb573997 100644 --- a/hamcrest/Hamcrest/Description.php +++ b/hamcrest/Hamcrest/Description.php @@ -21,7 +21,7 @@ interface Description * * @return static */ - public function appendText($text); + public function appendText(string $text): self; /** * Appends the description of a {@link Hamcrest\SelfDescribing} value to @@ -31,7 +31,7 @@ public function appendText($text); * * @return static */ - public function appendDescriptionOf(SelfDescribing $value); + public function appendDescriptionOf(SelfDescribing $value): self; /** * Appends an arbitrary value to the description. @@ -40,7 +40,7 @@ public function appendDescriptionOf(SelfDescribing $value); * * @return static */ - public function appendValue($value); + public function appendValue($value): self; /** * Appends a list of values to the description. @@ -48,11 +48,11 @@ public function appendValue($value); * @param string $start * @param string $separator * @param string $end - * @param array|\IteratorAggregate|\Iterator $values + * @param iterable $values * * @return static */ - public function appendValueList($start, $separator, $end, $values); + public function appendValueList(string $start, string $separator, string $end, iterable $values): self; /** * Appends a list of {@link Hamcrest\SelfDescribing} objects to the @@ -61,10 +61,9 @@ public function appendValueList($start, $separator, $end, $values); * @param string $start * @param string $separator * @param string $end - * @param array|\\IteratorAggregate|\\Iterator $values - * must be instances of {@link Hamcrest\SelfDescribing} + * @param iterable $values * * @return static */ - public function appendList($start, $separator, $end, $values); + public function appendList(string $start, string $separator, string $end, iterable $values): self; } diff --git a/hamcrest/Hamcrest/DiagnosingMatcher.php b/hamcrest/Hamcrest/DiagnosingMatcher.php index 3e45395c3..4239fffad 100644 --- a/hamcrest/Hamcrest/DiagnosingMatcher.php +++ b/hamcrest/Hamcrest/DiagnosingMatcher.php @@ -11,15 +11,18 @@ abstract class DiagnosingMatcher extends BaseMatcher { - final public function matches($item) + final public function matches($item): bool { return $this->matchesWithDiagnosticDescription($item, new NullDescription()); } - public function describeMismatch($item, Description $mismatchDescription) + public function describeMismatch($item, Description $mismatchDescription): void { $this->matchesWithDiagnosticDescription($item, $mismatchDescription); } - abstract protected function matchesWithDiagnosticDescription($item, Description $mismatchDescription); + /** + * @param mixed $item + */ + abstract protected function matchesWithDiagnosticDescription($item, Description $mismatchDescription): bool; } diff --git a/hamcrest/Hamcrest/FeatureMatcher.php b/hamcrest/Hamcrest/FeatureMatcher.php index 59f6cc734..094ef38f9 100644 --- a/hamcrest/Hamcrest/FeatureMatcher.php +++ b/hamcrest/Hamcrest/FeatureMatcher.php @@ -13,20 +13,20 @@ abstract class FeatureMatcher extends TypeSafeDiagnosingMatcher { - private $_subMatcher; - private $_featureDescription; - private $_featureName; + private Matcher $_subMatcher; + private string $_featureDescription; + private string $_featureName; /** * Constructor. * - * @param string $type - * @param string $subtype + * @param self::TYPE_* $type + * @param ?string $subtype * @param \Hamcrest\Matcher $subMatcher The matcher to apply to the feature * @param string $featureDescription Descriptive text to use in describeTo * @param string $featureName Identifying text for mismatch message */ - public function __construct($type, $subtype, Matcher $subMatcher, $featureDescription, $featureName) + public function __construct(int $type, ?string $subtype, Matcher $subMatcher, string $featureDescription, string $featureName) { parent::__construct($type, $subtype); @@ -44,7 +44,7 @@ public function __construct($type, $subtype, Matcher $subMatcher, $featureDescri */ abstract protected function featureValueOf($actual); - public function matchesSafelyWithDiagnosticDescription($actual, Description $mismatchDescription) + public function matchesSafelyWithDiagnosticDescription($actual, Description $mismatchDescription): bool { $featureValue = $this->featureValueOf($actual); @@ -58,7 +58,7 @@ public function matchesSafelyWithDiagnosticDescription($actual, Description $mis return true; } - final public function describeTo(Description $description) + final public function describeTo(Description $description): void { $description->appendText($this->_featureDescription)->appendText(' ') ->appendDescriptionOf($this->_subMatcher) diff --git a/hamcrest/Hamcrest/Internal/SelfDescribingValue.php b/hamcrest/Hamcrest/Internal/SelfDescribingValue.php index 995da71de..cc362cdbe 100644 --- a/hamcrest/Hamcrest/Internal/SelfDescribingValue.php +++ b/hamcrest/Hamcrest/Internal/SelfDescribingValue.php @@ -12,15 +12,20 @@ */ class SelfDescribingValue implements SelfDescribing { - + /** + * @var mixed + */ private $_value; + /** + * @param mixed $value + */ public function __construct($value) { $this->_value = $value; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendValue($this->_value); } diff --git a/hamcrest/Hamcrest/Matcher.php b/hamcrest/Hamcrest/Matcher.php index e5dcf0939..2880a5bbe 100644 --- a/hamcrest/Hamcrest/Matcher.php +++ b/hamcrest/Hamcrest/Matcher.php @@ -33,7 +33,7 @@ interface Matcher extends SelfDescribing * * @see Hamcrest\BaseMatcher */ - public function matches($item); + public function matches($item): bool; /** * Generate a description of why the matcher has not accepted the item. @@ -44,7 +44,7 @@ public function matches($item); * * @param mixed $item The item that the Matcher has rejected. * @param Description $description - * @return + * @return void */ - public function describeMismatch($item, Description $description); + public function describeMismatch($item, Description $description): void; } diff --git a/hamcrest/Hamcrest/MatcherAssert.php b/hamcrest/Hamcrest/MatcherAssert.php index d546dbee6..c450ef1aa 100644 --- a/hamcrest/Hamcrest/MatcherAssert.php +++ b/hamcrest/Hamcrest/MatcherAssert.php @@ -13,7 +13,7 @@ class MatcherAssert * * @var int */ - private static $_count = 0; + private static int $_count = 0; /** * Make an assertion and throw {@link Hamcrest\AssertionError} if it fails. @@ -35,7 +35,7 @@ class MatcherAssert * assertThat($a > $b); * */ - public static function assertThat(/* $args ... */) + public static function assertThat(/* $args ... */): void { $args = func_get_args(); switch (count($args)) { @@ -74,7 +74,7 @@ public static function assertThat(/* $args ... */) * * @return int */ - public static function getCount() + public static function getCount(): int { return self::$_count; } @@ -82,7 +82,7 @@ public static function getCount() /** * Resets the number of assertions performed to zero. */ - public static function resetCount() + public static function resetCount(): void { self::$_count = 0; } @@ -99,7 +99,7 @@ public static function resetCount() * @param \Hamcrest\Matcher $matcher applied to $actual * @throws AssertionError */ - private static function doAssert($identifier, $actual, Matcher $matcher) + private static function doAssert($identifier, $actual, Matcher $matcher): void { if (!$matcher->matches($actual)) { $description = new StringDescription(); diff --git a/hamcrest/Hamcrest/Matchers.php b/hamcrest/Hamcrest/Matchers.php index 719d2f9e5..37db6eea1 100644 --- a/hamcrest/Hamcrest/Matchers.php +++ b/hamcrest/Hamcrest/Matchers.php @@ -8,6 +8,15 @@ namespace Hamcrest; +use Hamcrest\Arrays\IsArray; +use Hamcrest\Arrays\IsArrayContainingInAnyOrder; +use Hamcrest\Arrays\IsArrayContainingInOrder; +use Hamcrest\Core\AllOf; +use Hamcrest\Core\AnyOf; +use Hamcrest\Core\DescribedAs; +use Hamcrest\Core\IsCollectionContaining; +use Hamcrest\Text\StringContainsInOrder; + /** * A series of static factories for all hamcrest matchers. */ @@ -17,7 +26,7 @@ class Matchers /** * Evaluates to true only if each $matcher[$i] is satisfied by $array[$i]. */ - public static function anArray(/* args... */) + public static function anArray(/* args... */): IsArray { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArray', 'anArray'), $args); @@ -30,7 +39,7 @@ public static function anArray(/* args... */) * * @return \Hamcrest\Arrays\IsArrayContaining */ - public static function hasItemInArray($item) + public static function hasItemInArray($item): \Hamcrest\Arrays\IsArrayContaining { return \Hamcrest\Arrays\IsArrayContaining::hasItemInArray($item); } @@ -42,7 +51,7 @@ public static function hasItemInArray($item) * * @return \Hamcrest\Arrays\IsArrayContaining */ - public static function hasValue($item) + public static function hasValue($item): \Hamcrest\Arrays\IsArrayContaining { return \Hamcrest\Arrays\IsArrayContaining::hasItemInArray($item); } @@ -50,7 +59,7 @@ public static function hasValue($item) /** * An array with elements that match the given matchers. */ - public static function arrayContainingInAnyOrder(/* args... */) + public static function arrayContainingInAnyOrder(/* args... */): IsArrayContainingInAnyOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args); @@ -59,7 +68,7 @@ public static function arrayContainingInAnyOrder(/* args... */) /** * An array with elements that match the given matchers. */ - public static function containsInAnyOrder(/* args... */) + public static function containsInAnyOrder(/* args... */): IsArrayContainingInAnyOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args); @@ -68,7 +77,7 @@ public static function containsInAnyOrder(/* args... */) /** * An array with elements that match the given matchers in the same order. */ - public static function arrayContaining(/* args... */) + public static function arrayContaining(/* args... */): IsArrayContainingInOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args); @@ -77,7 +86,7 @@ public static function arrayContaining(/* args... */) /** * An array with elements that match the given matchers in the same order. */ - public static function contains(/* args... */) + public static function contains(/* args... */): IsArrayContainingInOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args); @@ -90,7 +99,7 @@ public static function contains(/* args... */) * * @return \Hamcrest\Arrays\IsArrayContainingKey */ - public static function hasKeyInArray($key) + public static function hasKeyInArray($key): \Hamcrest\Arrays\IsArrayContainingKey { return \Hamcrest\Arrays\IsArrayContainingKey::hasKeyInArray($key); } @@ -102,23 +111,27 @@ public static function hasKeyInArray($key) * * @return \Hamcrest\Arrays\IsArrayContainingKey */ - public static function hasKey($key) + public static function hasKey($key): \Hamcrest\Arrays\IsArrayContainingKey { return \Hamcrest\Arrays\IsArrayContainingKey::hasKeyInArray($key); } /** * Test if an array has both an key and value in parity with each other. + * @param mixed $key + * @param mixed $value */ - public static function hasKeyValuePair($key, $value) + public static function hasKeyValuePair($key, $value): \Hamcrest\Arrays\IsArrayContainingKeyValuePair { return \Hamcrest\Arrays\IsArrayContainingKeyValuePair::hasKeyValuePair($key, $value); } /** * Test if an array has both an key and value in parity with each other. + * @param mixed $key + * @param mixed $value */ - public static function hasEntry($key, $value) + public static function hasEntry($key, $value): \Hamcrest\Arrays\IsArrayContainingKeyValuePair { return \Hamcrest\Arrays\IsArrayContainingKeyValuePair::hasKeyValuePair($key, $value); } @@ -130,7 +143,7 @@ public static function hasEntry($key, $value) * * @return \Hamcrest\Arrays\IsArrayWithSize */ - public static function arrayWithSize($size) + public static function arrayWithSize($size): \Hamcrest\Arrays\IsArrayWithSize { return \Hamcrest\Arrays\IsArrayWithSize::arrayWithSize($size); } @@ -138,7 +151,7 @@ public static function arrayWithSize($size) /** * Matches an empty array. */ - public static function emptyArray() + public static function emptyArray(): \Hamcrest\Core\DescribedAs { return \Hamcrest\Arrays\IsArrayWithSize::emptyArray(); } @@ -146,7 +159,7 @@ public static function emptyArray() /** * Matches an empty array. */ - public static function nonEmptyArray() + public static function nonEmptyArray(): \Hamcrest\Core\DescribedAs { return \Hamcrest\Arrays\IsArrayWithSize::nonEmptyArray(); } @@ -154,7 +167,7 @@ public static function nonEmptyArray() /** * Returns true if traversable is empty. */ - public static function emptyTraversable() + public static function emptyTraversable(): \Hamcrest\Collection\IsEmptyTraversable { return \Hamcrest\Collection\IsEmptyTraversable::emptyTraversable(); } @@ -162,15 +175,16 @@ public static function emptyTraversable() /** * Returns true if traversable is not empty. */ - public static function nonEmptyTraversable() + public static function nonEmptyTraversable(): \Hamcrest\Collection\IsEmptyTraversable { return \Hamcrest\Collection\IsEmptyTraversable::nonEmptyTraversable(); } /** * Does traversable size satisfy a given matcher? + * @param mixed $size */ - public static function traversableWithSize($size) + public static function traversableWithSize($size): \Hamcrest\Collection\IsTraversableWithSize { return \Hamcrest\Collection\IsTraversableWithSize::traversableWithSize($size); } @@ -178,7 +192,7 @@ public static function traversableWithSize($size) /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ - public static function allOf(/* args... */) + public static function allOf(/* args... */): AllOf { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AllOf', 'allOf'), $args); @@ -187,7 +201,7 @@ public static function allOf(/* args... */) /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ - public static function anyOf(/* args... */) + public static function anyOf(/* args... */): AnyOf { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'anyOf'), $args); @@ -196,7 +210,7 @@ public static function anyOf(/* args... */) /** * Evaluates to false if ANY of the passed in matchers evaluate to true. */ - public static function noneOf(/* args... */) + public static function noneOf(/* args... */): AnyOf { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'noneOf'), $args); @@ -209,7 +223,7 @@ public static function noneOf(/* args... */) * assertThat($string, both(containsString("a"))->andAlso(containsString("b"))); * */ - public static function both(\Hamcrest\Matcher $matcher) + public static function both(\Hamcrest\Matcher $matcher): \Hamcrest\Core\CombinableMatcher { return \Hamcrest\Core\CombinableMatcher::both($matcher); } @@ -221,7 +235,7 @@ public static function both(\Hamcrest\Matcher $matcher) * assertThat($string, either(containsString("a"))->orElse(containsString("b"))); * */ - public static function either(\Hamcrest\Matcher $matcher) + public static function either(\Hamcrest\Matcher $matcher): \Hamcrest\Core\CombinableMatcher { return \Hamcrest\Core\CombinableMatcher::either($matcher); } @@ -229,7 +243,7 @@ public static function either(\Hamcrest\Matcher $matcher) /** * Wraps an existing matcher and overrides the description when it fails. */ - public static function describedAs(/* args... */) + public static function describedAs(/* args... */): DescribedAs { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\DescribedAs', 'describedAs'), $args); @@ -242,7 +256,7 @@ public static function describedAs(/* args... */) * @return \Hamcrest\Core\Every * Evaluates to TRUE for a collection in which every item matches $itemMatcher */ - public static function everyItem(\Hamcrest\Matcher $itemMatcher) + public static function everyItem(\Hamcrest\Matcher $itemMatcher): \Hamcrest\Core\Every { return \Hamcrest\Core\Every::everyItem($itemMatcher); } @@ -251,7 +265,7 @@ public static function everyItem(\Hamcrest\Matcher $itemMatcher) * Creates a matcher that matches any examined object whose toString or * __toString() method returns a value equalTo the specified string. */ - public static function hasToString($matcher) + public static function hasToString($matcher): \Hamcrest\Core\HasToString { return \Hamcrest\Core\HasToString::hasToString($matcher); } @@ -262,8 +276,9 @@ public static function hasToString($matcher) * * For example: assertThat($cheese, equalTo($smelly)) * vs. assertThat($cheese, is(equalTo($smelly))) + * @param mixed $value */ - public static function is($value) + public static function is($value): \Hamcrest\Core\Is { return \Hamcrest\Core\Is::is($value); } @@ -275,7 +290,7 @@ public static function is($value) * * @return \Hamcrest\Core\IsAnything */ - public static function anything($description = 'ANYTHING') + public static function anything(string $description = 'ANYTHING'): \Hamcrest\Core\IsAnything { return \Hamcrest\Core\IsAnything::anything($description); } @@ -290,7 +305,7 @@ public static function anything($description = 'ANYTHING') * assertThat(array('a', 'b'), hasItem('b')); * */ - public static function hasItem(/* args... */) + public static function hasItem(/* args... */): IsCollectionContaining { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItem'), $args); @@ -305,7 +320,7 @@ public static function hasItem(/* args... */) * assertThat(array('a', 'b', 'c'), hasItems(equalTo('a'), equalTo('b'))); * */ - public static function hasItems(/* args... */) + public static function hasItems(/* args... */): IsCollectionContaining { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItems'), $args); @@ -314,16 +329,18 @@ public static function hasItems(/* args... */) /** * Is the value equal to another value, as tested by the use of the "==" * comparison operator? + * @param mixed $item */ - public static function equalTo($item) + public static function equalTo($item): \Hamcrest\Core\IsEqual { return \Hamcrest\Core\IsEqual::equalTo($item); } /** * Tests of the value is identical to $value as tested by the "===" operator. + * @param mixed $value */ - public static function identicalTo($value) + public static function identicalTo($value): \Hamcrest\Core\IsIdentical { return \Hamcrest\Core\IsIdentical::identicalTo($value); } @@ -334,7 +351,7 @@ public static function identicalTo($value) * the signature of the method that sets it up, for example in * assertThat($anObject, anInstanceOf('Thing')); */ - public static function anInstanceOf($theClass) + public static function anInstanceOf(string $theClass): \Hamcrest\Core\IsInstanceOf { return \Hamcrest\Core\IsInstanceOf::anInstanceOf($theClass); } @@ -345,15 +362,16 @@ public static function anInstanceOf($theClass) * the signature of the method that sets it up, for example in * assertThat($anObject, anInstanceOf('Thing')); */ - public static function any($theClass) + public static function any(string $theClass): \Hamcrest\Core\IsInstanceOf { return \Hamcrest\Core\IsInstanceOf::anInstanceOf($theClass); } /** * Matches if value does not match $value. + * @param mixed $value */ - public static function not($value) + public static function not($value): \Hamcrest\Core\IsNot { return \Hamcrest\Core\IsNot::not($value); } @@ -361,7 +379,7 @@ public static function not($value) /** * Matches if value is null. */ - public static function nullValue() + public static function nullValue(): \Hamcrest\Core\IsNull { return \Hamcrest\Core\IsNull::nullValue(); } @@ -369,7 +387,7 @@ public static function nullValue() /** * Matches if value is not null. */ - public static function notNullValue() + public static function notNullValue(): Matcher { return \Hamcrest\Core\IsNull::notNullValue(); } @@ -383,7 +401,7 @@ public static function notNullValue() * * @return \Hamcrest\Core\IsSame */ - public static function sameInstance($object) + public static function sameInstance($object): \Hamcrest\Core\IsSame { return \Hamcrest\Core\IsSame::sameInstance($object); } @@ -391,23 +409,25 @@ public static function sameInstance($object) /** * Is the value a particular built-in type? */ - public static function typeOf($theType) + public static function typeOf(string $theType): \Hamcrest\Core\IsTypeOf { return \Hamcrest\Core\IsTypeOf::typeOf($theType); } /** * Matches if value (class, object, or array) has named $property. + * @param mixed $property */ - public static function set($property) + public static function set($property): \Hamcrest\Core\Set { return \Hamcrest\Core\Set::set($property); } /** * Matches if value (class, object, or array) does not have named $property. + * @param mixed $property */ - public static function notSet($property) + public static function notSet($property): \Hamcrest\Core\Set { return \Hamcrest\Core\Set::notSet($property); } @@ -415,64 +435,73 @@ public static function notSet($property) /** * Matches if value is a number equal to $value within some range of * acceptable error $delta. + * @param mixed $value + * @param mixed $delta */ - public static function closeTo($value, $delta) + public static function closeTo($value, $delta): \Hamcrest\Number\IsCloseTo { return \Hamcrest\Number\IsCloseTo::closeTo($value, $delta); } /** * The value is not > $value, nor < $value. + * @param mixed $value */ - public static function comparesEqualTo($value) + public static function comparesEqualTo($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::comparesEqualTo($value); } /** * The value is > $value. + * @param mixed $value */ - public static function greaterThan($value) + public static function greaterThan($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::greaterThan($value); } /** * The value is >= $value. + * @param mixed $value */ - public static function greaterThanOrEqualTo($value) + public static function greaterThanOrEqualTo($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::greaterThanOrEqualTo($value); } /** * The value is >= $value. + * @param mixed $value */ - public static function atLeast($value) + public static function atLeast($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::greaterThanOrEqualTo($value); } /** * The value is < $value. + * @param mixed $value */ - public static function lessThan($value) + public static function lessThan($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::lessThan($value); } /** * The value is <= $value. + * @param mixed $value */ - public static function lessThanOrEqualTo($value) + public static function lessThanOrEqualTo($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::lessThanOrEqualTo($value); } /** * The value is <= $value. + * @param mixed $value */ - public static function atMost($value) + public static function atMost($value): \Hamcrest\Number\OrderingComparison { return \Hamcrest\Number\OrderingComparison::lessThanOrEqualTo($value); } @@ -480,7 +509,7 @@ public static function atMost($value) /** * Matches if value is a zero-length string. */ - public static function isEmptyString() + public static function isEmptyString(): \Hamcrest\Text\IsEmptyString { return \Hamcrest\Text\IsEmptyString::isEmptyString(); } @@ -488,7 +517,7 @@ public static function isEmptyString() /** * Matches if value is a zero-length string. */ - public static function emptyString() + public static function emptyString(): \Hamcrest\Text\IsEmptyString { return \Hamcrest\Text\IsEmptyString::isEmptyString(); } @@ -496,7 +525,7 @@ public static function emptyString() /** * Matches if value is null or a zero-length string. */ - public static function isEmptyOrNullString() + public static function isEmptyOrNullString(): Matcher { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } @@ -504,7 +533,7 @@ public static function isEmptyOrNullString() /** * Matches if value is null or a zero-length string. */ - public static function nullOrEmptyString() + public static function nullOrEmptyString(): Matcher { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } @@ -512,7 +541,7 @@ public static function nullOrEmptyString() /** * Matches if value is a non-zero-length string. */ - public static function isNonEmptyString() + public static function isNonEmptyString(): \Hamcrest\Text\IsEmptyString { return \Hamcrest\Text\IsEmptyString::isNonEmptyString(); } @@ -520,47 +549,52 @@ public static function isNonEmptyString() /** * Matches if value is a non-zero-length string. */ - public static function nonEmptyString() + public static function nonEmptyString(): \Hamcrest\Text\IsEmptyString { return \Hamcrest\Text\IsEmptyString::isNonEmptyString(); } /** * Matches if value is a string equal to $string, regardless of the case. + * @param mixed $string */ - public static function equalToIgnoringCase($string) + public static function equalToIgnoringCase($string): \Hamcrest\Text\IsEqualIgnoringCase { return \Hamcrest\Text\IsEqualIgnoringCase::equalToIgnoringCase($string); } /** * Matches if value is a string equal to $string, regardless of whitespace. + * @param mixed $string */ - public static function equalToIgnoringWhiteSpace($string) + public static function equalToIgnoringWhiteSpace($string): \Hamcrest\Text\IsEqualIgnoringWhiteSpace { return \Hamcrest\Text\IsEqualIgnoringWhiteSpace::equalToIgnoringWhiteSpace($string); } /** * Matches if value is a string that matches regular expression $pattern. + * @param mixed $pattern */ - public static function matchesPattern($pattern) + public static function matchesPattern($pattern): \Hamcrest\Text\MatchesPattern { return \Hamcrest\Text\MatchesPattern::matchesPattern($pattern); } /** * Matches if value is a string that contains $substring. + * @param mixed $substring */ - public static function containsString($substring) + public static function containsString($substring): \Hamcrest\Text\StringContains { return \Hamcrest\Text\StringContains::containsString($substring); } /** * Matches if value is a string that contains $substring regardless of the case. + * @param mixed $substring */ - public static function containsStringIgnoringCase($substring) + public static function containsStringIgnoringCase($substring): \Hamcrest\Text\StringContainsIgnoringCase { return \Hamcrest\Text\StringContainsIgnoringCase::containsStringIgnoringCase($substring); } @@ -568,7 +602,7 @@ public static function containsStringIgnoringCase($substring) /** * Matches if value contains $substrings in a constrained order. */ - public static function stringContainsInOrder(/* args... */) + public static function stringContainsInOrder(/* args... */): StringContainsInOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Text\StringContainsInOrder', 'stringContainsInOrder'), $args); @@ -576,16 +610,18 @@ public static function stringContainsInOrder(/* args... */) /** * Matches if value is a string that ends with $substring. + * @param mixed $substring */ - public static function endsWith($substring) + public static function endsWith($substring): \Hamcrest\Text\StringEndsWith { return \Hamcrest\Text\StringEndsWith::endsWith($substring); } /** * Matches if value is a string that starts with $substring. + * @param mixed $substring */ - public static function startsWith($substring) + public static function startsWith($substring): \Hamcrest\Text\StringStartsWith { return \Hamcrest\Text\StringStartsWith::startsWith($substring); } @@ -593,7 +629,7 @@ public static function startsWith($substring) /** * Is the value an array? */ - public static function arrayValue() + public static function arrayValue(): \Hamcrest\Type\IsArray { return \Hamcrest\Type\IsArray::arrayValue(); } @@ -601,7 +637,7 @@ public static function arrayValue() /** * Is the value a boolean? */ - public static function booleanValue() + public static function booleanValue(): \Hamcrest\Type\IsBoolean { return \Hamcrest\Type\IsBoolean::booleanValue(); } @@ -609,7 +645,7 @@ public static function booleanValue() /** * Is the value a boolean? */ - public static function boolValue() + public static function boolValue(): \Hamcrest\Type\IsBoolean { return \Hamcrest\Type\IsBoolean::booleanValue(); } @@ -617,7 +653,7 @@ public static function boolValue() /** * Is the value callable? */ - public static function callableValue() + public static function callableValue(): \Hamcrest\Type\IsCallable { return \Hamcrest\Type\IsCallable::callableValue(); } @@ -625,7 +661,7 @@ public static function callableValue() /** * Is the value a float/double? */ - public static function doubleValue() + public static function doubleValue(): \Hamcrest\Type\IsDouble { return \Hamcrest\Type\IsDouble::doubleValue(); } @@ -633,7 +669,7 @@ public static function doubleValue() /** * Is the value a float/double? */ - public static function floatValue() + public static function floatValue(): \Hamcrest\Type\IsDouble { return \Hamcrest\Type\IsDouble::doubleValue(); } @@ -641,7 +677,7 @@ public static function floatValue() /** * Is the value an integer? */ - public static function integerValue() + public static function integerValue(): \Hamcrest\Type\IsInteger { return \Hamcrest\Type\IsInteger::integerValue(); } @@ -649,7 +685,7 @@ public static function integerValue() /** * Is the value an integer? */ - public static function intValue() + public static function intValue(): \Hamcrest\Type\IsInteger { return \Hamcrest\Type\IsInteger::integerValue(); } @@ -657,7 +693,7 @@ public static function intValue() /** * Is the value a numeric? */ - public static function numericValue() + public static function numericValue(): \Hamcrest\Type\IsNumeric { return \Hamcrest\Type\IsNumeric::numericValue(); } @@ -665,7 +701,7 @@ public static function numericValue() /** * Is the value an object? */ - public static function objectValue() + public static function objectValue(): \Hamcrest\Type\IsObject { return \Hamcrest\Type\IsObject::objectValue(); } @@ -673,7 +709,7 @@ public static function objectValue() /** * Is the value an object? */ - public static function anObject() + public static function anObject(): \Hamcrest\Type\IsObject { return \Hamcrest\Type\IsObject::objectValue(); } @@ -681,7 +717,7 @@ public static function anObject() /** * Is the value a resource? */ - public static function resourceValue() + public static function resourceValue(): \Hamcrest\Type\IsResource { return \Hamcrest\Type\IsResource::resourceValue(); } @@ -689,7 +725,7 @@ public static function resourceValue() /** * Is the value a scalar (boolean, integer, double, or string)? */ - public static function scalarValue() + public static function scalarValue(): \Hamcrest\Type\IsScalar { return \Hamcrest\Type\IsScalar::scalarValue(); } @@ -697,7 +733,7 @@ public static function scalarValue() /** * Is the value a string? */ - public static function stringValue() + public static function stringValue(): \Hamcrest\Type\IsString { return \Hamcrest\Type\IsString::stringValue(); } @@ -706,8 +742,9 @@ public static function stringValue() * Wraps $matcher with {@link Hamcrest\Core\IsEqual) * if it's not a matcher and the XPath in count() * if it's an integer. + * @param null|Matcher|int|mixed $matcher */ - public static function hasXPath($xpath, $matcher = null) + public static function hasXPath(string $xpath, $matcher = null): \Hamcrest\Xml\HasXPath { return \Hamcrest\Xml\HasXPath::hasXPath($xpath, $matcher); } diff --git a/hamcrest/Hamcrest/NullDescription.php b/hamcrest/Hamcrest/NullDescription.php index aae8e4616..1d86da479 100644 --- a/hamcrest/Hamcrest/NullDescription.php +++ b/hamcrest/Hamcrest/NullDescription.php @@ -11,27 +11,27 @@ class NullDescription implements Description { - public function appendText($text) + public function appendText(string $text): self { return $this; } - public function appendDescriptionOf(SelfDescribing $value) + public function appendDescriptionOf(SelfDescribing $value): self { return $this; } - public function appendValue($value) + public function appendValue($value): self { return $this; } - public function appendValueList($start, $separator, $end, $values) + public function appendValueList(string $start, string $separator, string $end, $values): self { return $this; } - public function appendList($start, $separator, $end, $values) + public function appendList(string $start, string $separator, string $end, $values): self { return $this; } diff --git a/hamcrest/Hamcrest/Number/IsCloseTo.php b/hamcrest/Hamcrest/Number/IsCloseTo.php index 15453e526..748419df3 100644 --- a/hamcrest/Hamcrest/Number/IsCloseTo.php +++ b/hamcrest/Hamcrest/Number/IsCloseTo.php @@ -14,9 +14,19 @@ class IsCloseTo extends TypeSafeMatcher { + /** + * @var mixed + */ private $_value; + /** + * @var mixed + */ private $_delta; + /** + * @param mixed $value + * @param mixed $delta + */ public function __construct($value, $delta) { parent::__construct(self::TYPE_NUMERIC); @@ -25,12 +35,12 @@ public function __construct($value, $delta) $this->_delta = $delta; } - protected function matchesSafely($item) + protected function matchesSafely($item): bool { return $this->_actualDelta($item) <= 0.0; } - protected function describeMismatchSafely($item, Description $mismatchDescription) + protected function describeMismatchSafely($item, Description $mismatchDescription): void { $mismatchDescription->appendValue($item) ->appendText(' differed by ') @@ -38,7 +48,7 @@ protected function describeMismatchSafely($item, Description $mismatchDescriptio ; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('a numeric value within ') ->appendValue($this->_delta) @@ -52,14 +62,20 @@ public function describeTo(Description $description) * acceptable error $delta. * * @factory + * @param mixed $value + * @param mixed $delta */ - public static function closeTo($value, $delta) + public static function closeTo($value, $delta): self { return new self($value, $delta); } // -- Private Methods + /** + * @param mixed $item + * @return int|float + */ private function _actualDelta($item) { return (abs(($item - $this->_value)) - $this->_delta); diff --git a/hamcrest/Hamcrest/Number/OrderingComparison.php b/hamcrest/Hamcrest/Number/OrderingComparison.php index 369d0cfa5..1eb1713d2 100644 --- a/hamcrest/Hamcrest/Number/OrderingComparison.php +++ b/hamcrest/Hamcrest/Number/OrderingComparison.php @@ -11,10 +11,24 @@ class OrderingComparison extends TypeSafeMatcher { + /** + * @var mixed + */ private $_value; + /** + * @var mixed + */ private $_minCompare; + /** + * @var mixed + */ private $_maxCompare; + /** + * @param mixed $value + * @param mixed $maxCompare + * @param mixed $minCompare + */ public function __construct($value, $minCompare, $maxCompare) { parent::__construct(self::TYPE_NUMERIC); @@ -24,14 +38,14 @@ public function __construct($value, $minCompare, $maxCompare) $this->_maxCompare = $maxCompare; } - protected function matchesSafely($other) + protected function matchesSafely($other): bool { $compare = $this->_compare($this->_value, $other); return ($this->_minCompare <= $compare) && ($compare <= $this->_maxCompare); } - protected function describeMismatchSafely($item, Description $mismatchDescription) + protected function describeMismatchSafely($item, Description $mismatchDescription): void { $mismatchDescription ->appendValue($item)->appendText(' was ') @@ -40,7 +54,7 @@ protected function describeMismatchSafely($item, Description $mismatchDescriptio ; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('a value ') ->appendText($this->_comparison($this->_minCompare)) @@ -57,8 +71,9 @@ public function describeTo(Description $description) * The value is not > $value, nor < $value. * * @factory + * @param mixed $value */ - public static function comparesEqualTo($value) + public static function comparesEqualTo($value): self { return new self($value, 0, 0); } @@ -67,8 +82,9 @@ public static function comparesEqualTo($value) * The value is > $value. * * @factory + * @param mixed $value */ - public static function greaterThan($value) + public static function greaterThan($value): self { return new self($value, -1, -1); } @@ -77,8 +93,9 @@ public static function greaterThan($value) * The value is >= $value. * * @factory atLeast + * @param mixed $value */ - public static function greaterThanOrEqualTo($value) + public static function greaterThanOrEqualTo($value): self { return new self($value, -1, 0); } @@ -87,8 +104,9 @@ public static function greaterThanOrEqualTo($value) * The value is < $value. * * @factory + * @param mixed $value */ - public static function lessThan($value) + public static function lessThan($value): self { return new self($value, 1, 1); } @@ -97,15 +115,20 @@ public static function lessThan($value) * The value is <= $value. * * @factory atMost + * @param mixed $value */ - public static function lessThanOrEqualTo($value) + public static function lessThanOrEqualTo($value): self { return new self($value, 0, 1); } // -- Private Methods - private function _compare($left, $right) + /** + * @param mixed $left + * @param mixed $right + */ + private function _compare($left, $right): int { $a = $left; $b = $right; @@ -119,7 +142,10 @@ private function _compare($left, $right) } } - private function _comparison($compare) + /** + * @param mixed $compare + */ + private function _comparison($compare): string { if ($compare > 0) { return 'less than'; diff --git a/hamcrest/Hamcrest/SelfDescribing.php b/hamcrest/Hamcrest/SelfDescribing.php index 872fdf9c5..6712a02ef 100644 --- a/hamcrest/Hamcrest/SelfDescribing.php +++ b/hamcrest/Hamcrest/SelfDescribing.php @@ -19,5 +19,5 @@ interface SelfDescribing * @param \Hamcrest\Description $description * The description to be built or appended to. */ - public function describeTo(Description $description); + public function describeTo(Description $description): void; } diff --git a/hamcrest/Hamcrest/StringDescription.php b/hamcrest/Hamcrest/StringDescription.php index 4b36fa2d1..766501252 100644 --- a/hamcrest/Hamcrest/StringDescription.php +++ b/hamcrest/Hamcrest/StringDescription.php @@ -11,8 +11,11 @@ class StringDescription extends BaseDescription { - private $_out; + private string $_out; + /** + * @param mixed $out + */ public function __construct($out = '') { $this->_out = (string) $out; @@ -33,7 +36,7 @@ public function __toString() * @return string * The description of the object. */ - public static function toString(SelfDescribing $selfDescribing) + public static function toString(SelfDescribing $selfDescribing): string { $self = new self(); @@ -43,14 +46,14 @@ public static function toString(SelfDescribing $selfDescribing) /** * Alias for {@link toString()}. */ - public static function asString(SelfDescribing $selfDescribing) + public static function asString(SelfDescribing $selfDescribing): string { return self::toString($selfDescribing); } // -- Protected Methods - protected function append($str) + protected function append($str): void { $this->_out .= $str; } diff --git a/hamcrest/Hamcrest/Text/IsEmptyString.php b/hamcrest/Hamcrest/Text/IsEmptyString.php index 2ae61b96c..947a2c6de 100644 --- a/hamcrest/Hamcrest/Text/IsEmptyString.php +++ b/hamcrest/Hamcrest/Text/IsEmptyString.php @@ -15,25 +15,25 @@ class IsEmptyString extends BaseMatcher { - private static $_INSTANCE; - private static $_NULL_OR_EMPTY_INSTANCE; - private static $_NOT_INSTANCE; + private static ?self $_INSTANCE = null; + private static ?AnyOf $_NULL_OR_EMPTY_INSTANCE = null; + private static ?self $_NOT_INSTANCE = null; - private $_empty; + private bool $_empty; - public function __construct($empty = true) + public function __construct(bool $empty = true) { $this->_empty = $empty; } - public function matches($item) + public function matches($item): bool { return $this->_empty ? ($item === '') : is_string($item) && $item !== ''; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText($this->_empty ? 'an empty string' : 'a non-empty string'); } @@ -43,7 +43,7 @@ public function describeTo(Description $description) * * @factory emptyString */ - public static function isEmptyString() + public static function isEmptyString(): self { if (!self::$_INSTANCE) { self::$_INSTANCE = new self(true); @@ -57,7 +57,7 @@ public static function isEmptyString() * * @factory nullOrEmptyString */ - public static function isEmptyOrNullString() + public static function isEmptyOrNullString(): AnyOf { if (!self::$_NULL_OR_EMPTY_INSTANCE) { self::$_NULL_OR_EMPTY_INSTANCE = AnyOf::anyOf( @@ -74,7 +74,7 @@ public static function isEmptyOrNullString() * * @factory nonEmptyString */ - public static function isNonEmptyString() + public static function isNonEmptyString(): self { if (!self::$_NOT_INSTANCE) { self::$_NOT_INSTANCE = new self(false); diff --git a/hamcrest/Hamcrest/Text/IsEqualIgnoringCase.php b/hamcrest/Hamcrest/Text/IsEqualIgnoringCase.php index 3836a8c37..027923f8d 100644 --- a/hamcrest/Hamcrest/Text/IsEqualIgnoringCase.php +++ b/hamcrest/Hamcrest/Text/IsEqualIgnoringCase.php @@ -12,9 +12,14 @@ */ class IsEqualIgnoringCase extends TypeSafeMatcher { - + /** + * @var mixed + */ private $_string; + /** + * @param mixed $string + */ public function __construct($string) { parent::__construct(self::TYPE_STRING); @@ -22,17 +27,17 @@ public function __construct($string) $this->_string = $string; } - protected function matchesSafely($item) + protected function matchesSafely($item): bool { return strtolower($this->_string) === strtolower($item); } - protected function describeMismatchSafely($item, Description $mismatchDescription) + protected function describeMismatchSafely($item, Description $mismatchDescription): void { $mismatchDescription->appendText('was ')->appendText($item); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('equalToIgnoringCase(') ->appendValue($this->_string) @@ -44,8 +49,9 @@ public function describeTo(Description $description) * Matches if value is a string equal to $string, regardless of the case. * * @factory + * @param mixed $string */ - public static function equalToIgnoringCase($string) + public static function equalToIgnoringCase($string): self { return new self($string); } diff --git a/hamcrest/Hamcrest/Text/IsEqualIgnoringWhiteSpace.php b/hamcrest/Hamcrest/Text/IsEqualIgnoringWhiteSpace.php index 853692b03..3127552e4 100644 --- a/hamcrest/Hamcrest/Text/IsEqualIgnoringWhiteSpace.php +++ b/hamcrest/Hamcrest/Text/IsEqualIgnoringWhiteSpace.php @@ -13,9 +13,14 @@ */ class IsEqualIgnoringWhiteSpace extends TypeSafeMatcher { - + /** + * @var mixed + */ private $_string; + /** + * @param mixed $string + */ public function __construct($string) { parent::__construct(self::TYPE_STRING); @@ -23,18 +28,18 @@ public function __construct($string) $this->_string = $string; } - protected function matchesSafely($item) + protected function matchesSafely($item): bool { return (strtolower($this->_stripSpace($item)) === strtolower($this->_stripSpace($this->_string))); } - protected function describeMismatchSafely($item, Description $mismatchDescription) + protected function describeMismatchSafely($item, Description $mismatchDescription): void { $mismatchDescription->appendText('was ')->appendText($item); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('equalToIgnoringWhiteSpace(') ->appendValue($this->_string) @@ -46,15 +51,16 @@ public function describeTo(Description $description) * Matches if value is a string equal to $string, regardless of whitespace. * * @factory + * @param mixed $string */ - public static function equalToIgnoringWhiteSpace($string) + public static function equalToIgnoringWhiteSpace($string): self { return new self($string); } // -- Private Methods - private function _stripSpace($string) + private function _stripSpace(string $string): string { $parts = preg_split("/[\r\n\t ]+/", $string); foreach ($parts as $i => $part) { diff --git a/hamcrest/Hamcrest/Text/MatchesPattern.php b/hamcrest/Hamcrest/Text/MatchesPattern.php index fa0d68eea..639759408 100644 --- a/hamcrest/Hamcrest/Text/MatchesPattern.php +++ b/hamcrest/Hamcrest/Text/MatchesPattern.php @@ -10,7 +10,9 @@ */ class MatchesPattern extends SubstringMatcher { - + /** + * @param mixed $pattern + */ public function __construct($pattern) { parent::__construct($pattern); @@ -20,20 +22,21 @@ public function __construct($pattern) * Matches if value is a string that matches regular expression $pattern. * * @factory + * @param mixed $pattern */ - public static function matchesPattern($pattern) + public static function matchesPattern($pattern): self { return new self($pattern); } // -- Protected Methods - protected function evalSubstringOf($item) + protected function evalSubstringOf(string $item): bool { return preg_match($this->_substring, (string) $item) >= 1; } - protected function relationship() + protected function relationship(): string { return 'matching'; } diff --git a/hamcrest/Hamcrest/Text/StringContains.php b/hamcrest/Hamcrest/Text/StringContains.php index b92786b60..65284dbe0 100644 --- a/hamcrest/Hamcrest/Text/StringContains.php +++ b/hamcrest/Hamcrest/Text/StringContains.php @@ -10,13 +10,15 @@ */ class StringContains extends SubstringMatcher { - + /** + * @param mixed $substring + */ public function __construct($substring) { parent::__construct($substring); } - public function ignoringCase() + public function ignoringCase(): StringContainsIgnoringCase { return new StringContainsIgnoringCase($this->_substring); } @@ -25,20 +27,21 @@ public function ignoringCase() * Matches if value is a string that contains $substring. * * @factory + * @param mixed $substring */ - public static function containsString($substring) + public static function containsString($substring): self { return new self($substring); } // -- Protected Methods - protected function evalSubstringOf($item) + protected function evalSubstringOf(string $item): bool { return (false !== strpos((string) $item, $this->_substring)); } - protected function relationship() + protected function relationship(): string { return 'containing'; } diff --git a/hamcrest/Hamcrest/Text/StringContainsIgnoringCase.php b/hamcrest/Hamcrest/Text/StringContainsIgnoringCase.php index 69f37c258..53d55eecb 100644 --- a/hamcrest/Hamcrest/Text/StringContainsIgnoringCase.php +++ b/hamcrest/Hamcrest/Text/StringContainsIgnoringCase.php @@ -11,6 +11,9 @@ class StringContainsIgnoringCase extends SubstringMatcher { + /** + * @param mixed $substring + */ public function __construct($substring) { parent::__construct($substring); @@ -20,20 +23,21 @@ public function __construct($substring) * Matches if value is a string that contains $substring regardless of the case. * * @factory + * @param mixed $substring */ - public static function containsStringIgnoringCase($substring) + public static function containsStringIgnoringCase($substring): self { return new self($substring); } // -- Protected Methods - protected function evalSubstringOf($item) + protected function evalSubstringOf(string $item): bool { return (false !== stripos((string) $item, $this->_substring)); } - protected function relationship() + protected function relationship(): string { return 'containing in any case'; } diff --git a/hamcrest/Hamcrest/Text/StringContainsInOrder.php b/hamcrest/Hamcrest/Text/StringContainsInOrder.php index e75de65d2..33b3ab638 100644 --- a/hamcrest/Hamcrest/Text/StringContainsInOrder.php +++ b/hamcrest/Hamcrest/Text/StringContainsInOrder.php @@ -12,9 +12,14 @@ */ class StringContainsInOrder extends TypeSafeMatcher { + /** + * @var array + */ + private array $_substrings; - private $_substrings; - + /** + * @param array $substrings + */ public function __construct(array $substrings) { parent::__construct(self::TYPE_STRING); @@ -22,7 +27,7 @@ public function __construct(array $substrings) $this->_substrings = $substrings; } - protected function matchesSafely($item) + protected function matchesSafely($item): bool { $fromIndex = 0; @@ -35,12 +40,12 @@ protected function matchesSafely($item) return true; } - protected function describeMismatchSafely($item, Description $mismatchDescription) + protected function describeMismatchSafely($item, Description $mismatchDescription): void { $mismatchDescription->appendText('was ')->appendText($item); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('a string containing ') ->appendValueList('', ', ', '', $this->_substrings) @@ -53,7 +58,7 @@ public function describeTo(Description $description) * * @factory ... */ - public static function stringContainsInOrder(/* args... */) + public static function stringContainsInOrder(/* args... */): self { $args = func_get_args(); diff --git a/hamcrest/Hamcrest/Text/StringEndsWith.php b/hamcrest/Hamcrest/Text/StringEndsWith.php index f802ee4d1..2684a9bce 100644 --- a/hamcrest/Hamcrest/Text/StringEndsWith.php +++ b/hamcrest/Hamcrest/Text/StringEndsWith.php @@ -11,6 +11,9 @@ class StringEndsWith extends SubstringMatcher { + /** + * @param mixed $substring + */ public function __construct($substring) { parent::__construct($substring); @@ -20,20 +23,22 @@ public function __construct($substring) * Matches if value is a string that ends with $substring. * * @factory + * @param mixed $substring + * @return StringEndsWith */ - public static function endsWith($substring) + public static function endsWith($substring): self { return new self($substring); } // -- Protected Methods - protected function evalSubstringOf($string) + protected function evalSubstringOf(string $string): bool { return (substr($string, (-1 * strlen($this->_substring))) === $this->_substring); } - protected function relationship() + protected function relationship(): string { return 'ending with'; } diff --git a/hamcrest/Hamcrest/Text/StringStartsWith.php b/hamcrest/Hamcrest/Text/StringStartsWith.php index 79c95656a..e1c67c0ff 100644 --- a/hamcrest/Hamcrest/Text/StringStartsWith.php +++ b/hamcrest/Hamcrest/Text/StringStartsWith.php @@ -11,6 +11,9 @@ class StringStartsWith extends SubstringMatcher { + /** + * @param mixed $substring + */ public function __construct($substring) { parent::__construct($substring); @@ -20,20 +23,21 @@ public function __construct($substring) * Matches if value is a string that starts with $substring. * * @factory + * @param mixed $substring */ - public static function startsWith($substring) + public static function startsWith($substring): self { return new self($substring); } // -- Protected Methods - protected function evalSubstringOf($string) + protected function evalSubstringOf(string $string): bool { return (substr($string, 0, strlen($this->_substring)) === $this->_substring); } - protected function relationship() + protected function relationship(): string { return 'starting with'; } diff --git a/hamcrest/Hamcrest/Text/SubstringMatcher.php b/hamcrest/Hamcrest/Text/SubstringMatcher.php index e560ad627..02747736b 100644 --- a/hamcrest/Hamcrest/Text/SubstringMatcher.php +++ b/hamcrest/Hamcrest/Text/SubstringMatcher.php @@ -11,8 +11,14 @@ abstract class SubstringMatcher extends TypeSafeMatcher { + /** + * @var mixed + */ protected $_substring; + /** + * @param mixed $substring + */ public function __construct($substring) { parent::__construct(self::TYPE_STRING); @@ -20,17 +26,17 @@ public function __construct($substring) $this->_substring = $substring; } - protected function matchesSafely($item) + protected function matchesSafely($item): bool { return $this->evalSubstringOf($item); } - protected function describeMismatchSafely($item, Description $mismatchDescription) + protected function describeMismatchSafely($item, Description $mismatchDescription): void { $mismatchDescription->appendText('was "')->appendText($item)->appendText('"'); } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('a string ') ->appendText($this->relationship()) @@ -39,7 +45,7 @@ public function describeTo(Description $description) ; } - abstract protected function evalSubstringOf($string); + abstract protected function evalSubstringOf(string $string): bool; - abstract protected function relationship(); + abstract protected function relationship(): string; } diff --git a/hamcrest/Hamcrest/Type/IsArray.php b/hamcrest/Hamcrest/Type/IsArray.php index 9179102ff..19c6e2ea5 100644 --- a/hamcrest/Hamcrest/Type/IsArray.php +++ b/hamcrest/Hamcrest/Type/IsArray.php @@ -25,7 +25,7 @@ public function __construct() * * @factory */ - public static function arrayValue() + public static function arrayValue(): self { return new self; } diff --git a/hamcrest/Hamcrest/Type/IsBoolean.php b/hamcrest/Hamcrest/Type/IsBoolean.php index 35b617cf4..d9fbddd91 100644 --- a/hamcrest/Hamcrest/Type/IsBoolean.php +++ b/hamcrest/Hamcrest/Type/IsBoolean.php @@ -25,7 +25,7 @@ public function __construct() * * @factory boolValue */ - public static function booleanValue() + public static function booleanValue(): self { return new self; } diff --git a/hamcrest/Hamcrest/Type/IsCallable.php b/hamcrest/Hamcrest/Type/IsCallable.php index f2bcd35ba..ef930d7cd 100644 --- a/hamcrest/Hamcrest/Type/IsCallable.php +++ b/hamcrest/Hamcrest/Type/IsCallable.php @@ -20,7 +20,7 @@ public function __construct() parent::__construct('callable'); } - public function matches($item) + public function matches($item): bool { return is_callable($item); } @@ -30,7 +30,7 @@ public function matches($item) * * @factory */ - public static function callableValue() + public static function callableValue(): self { return new self; } diff --git a/hamcrest/Hamcrest/Type/IsDouble.php b/hamcrest/Hamcrest/Type/IsDouble.php index 3ddd8e852..0dffc8443 100644 --- a/hamcrest/Hamcrest/Type/IsDouble.php +++ b/hamcrest/Hamcrest/Type/IsDouble.php @@ -27,7 +27,7 @@ public function __construct() * * @factory floatValue */ - public static function doubleValue() + public static function doubleValue(): self { return new self; } diff --git a/hamcrest/Hamcrest/Type/IsInteger.php b/hamcrest/Hamcrest/Type/IsInteger.php index 47c86bd68..f26997ec6 100644 --- a/hamcrest/Hamcrest/Type/IsInteger.php +++ b/hamcrest/Hamcrest/Type/IsInteger.php @@ -25,7 +25,7 @@ public function __construct() * * @factory intValue */ - public static function integerValue() + public static function integerValue(): self { return new self; } diff --git a/hamcrest/Hamcrest/Type/IsNumeric.php b/hamcrest/Hamcrest/Type/IsNumeric.php index bc7440547..bf60cec24 100644 --- a/hamcrest/Hamcrest/Type/IsNumeric.php +++ b/hamcrest/Hamcrest/Type/IsNumeric.php @@ -17,7 +17,7 @@ public function __construct() parent::__construct('number'); } - public function matches($item) + public function matches($item): bool { if ($this->isHexadecimal($item)) { return true; @@ -47,7 +47,7 @@ private function isHexadecimal($item) * * @factory */ - public static function numericValue() + public static function numericValue(): self { return new self; } diff --git a/hamcrest/Hamcrest/Type/IsObject.php b/hamcrest/Hamcrest/Type/IsObject.php index 65918fcf3..4edab887d 100644 --- a/hamcrest/Hamcrest/Type/IsObject.php +++ b/hamcrest/Hamcrest/Type/IsObject.php @@ -25,7 +25,7 @@ public function __construct() * * @factory anObject */ - public static function objectValue() + public static function objectValue(): self { return new self; } diff --git a/hamcrest/Hamcrest/Type/IsResource.php b/hamcrest/Hamcrest/Type/IsResource.php index 426cf77c9..fd3250efe 100644 --- a/hamcrest/Hamcrest/Type/IsResource.php +++ b/hamcrest/Hamcrest/Type/IsResource.php @@ -25,7 +25,7 @@ public function __construct() * * @factory */ - public static function resourceValue() + public static function resourceValue(): self { return new self; } diff --git a/hamcrest/Hamcrest/Type/IsScalar.php b/hamcrest/Hamcrest/Type/IsScalar.php index 3f3b427fa..5670c5f5d 100644 --- a/hamcrest/Hamcrest/Type/IsScalar.php +++ b/hamcrest/Hamcrest/Type/IsScalar.php @@ -17,7 +17,7 @@ public function __construct() parent::__construct('scalar'); } - public function matches($item) + public function matches($item): bool { return is_scalar($item); } @@ -27,7 +27,7 @@ public function matches($item) * * @factory */ - public static function scalarValue() + public static function scalarValue(): self { return new self; } diff --git a/hamcrest/Hamcrest/Type/IsString.php b/hamcrest/Hamcrest/Type/IsString.php index d96d7db38..c29a7084b 100644 --- a/hamcrest/Hamcrest/Type/IsString.php +++ b/hamcrest/Hamcrest/Type/IsString.php @@ -25,7 +25,7 @@ public function __construct() * * @factory */ - public static function stringValue() + public static function stringValue(): self { return new self; } diff --git a/hamcrest/Hamcrest/TypeSafeDiagnosingMatcher.php b/hamcrest/Hamcrest/TypeSafeDiagnosingMatcher.php index af934e8ac..1fd8dd8b7 100644 --- a/hamcrest/Hamcrest/TypeSafeDiagnosingMatcher.php +++ b/hamcrest/Hamcrest/TypeSafeDiagnosingMatcher.php @@ -9,14 +9,14 @@ abstract class TypeSafeDiagnosingMatcher extends TypeSafeMatcher { - final public function matchesSafely($item) + final public function matchesSafely($actual): bool { - return $this->matchesSafelyWithDiagnosticDescription($item, new NullDescription()); + return $this->matchesSafelyWithDiagnosticDescription($actual, new NullDescription()); } - final public function describeMismatchSafely($item, Description $mismatchDescription) + final public function describeMismatchSafely($actual, Description $mismatchDescription): void { - $this->matchesSafelyWithDiagnosticDescription($item, $mismatchDescription); + $this->matchesSafelyWithDiagnosticDescription($actual, $mismatchDescription); } // -- Protected Methods @@ -24,6 +24,7 @@ final public function describeMismatchSafely($item, Description $mismatchDescrip /** * Subclasses should implement these. The item will already have been checked for * the specific type. + * @param mixed $actual */ - abstract protected function matchesSafelyWithDiagnosticDescription($item, Description $mismatchDescription); + abstract protected function matchesSafelyWithDiagnosticDescription($actual, Description $mismatchDescription): bool; } diff --git a/hamcrest/Hamcrest/TypeSafeMatcher.php b/hamcrest/Hamcrest/TypeSafeMatcher.php index 56e299a9a..adb5d1215 100644 --- a/hamcrest/Hamcrest/TypeSafeMatcher.php +++ b/hamcrest/Hamcrest/TypeSafeMatcher.php @@ -14,40 +14,44 @@ abstract class TypeSafeMatcher extends BaseMatcher { /* Types that PHP can compare against */ - const TYPE_ANY = 0; - const TYPE_STRING = 1; - const TYPE_NUMERIC = 2; - const TYPE_ARRAY = 3; - const TYPE_OBJECT = 4; - const TYPE_RESOURCE = 5; - const TYPE_BOOLEAN = 6; + protected const TYPE_ANY = 0; + protected const TYPE_STRING = 1; + protected const TYPE_NUMERIC = 2; + protected const TYPE_ARRAY = 3; + protected const TYPE_OBJECT = 4; + protected const TYPE_RESOURCE = 5; + protected const TYPE_BOOLEAN = 6; /** * The type that is required for a safe comparison * * @var int */ - private $_expectedType; + private int $_expectedType; /** * The subtype (e.g. class for objects) that is required * * @var string */ - private $_expectedSubtype; + private ?string $_expectedSubtype; - public function __construct($expectedType, $expectedSubtype = null) + /** + * @param self::TYPE_* $expectedType + * @param string|null $expectedSubtype + */ + public function __construct(int $expectedType, ?string $expectedSubtype = null) { $this->_expectedType = $expectedType; $this->_expectedSubtype = $expectedSubtype; } - final public function matches($item) + final public function matches($item): bool { return $this->_isSafeType($item) && $this->matchesSafely($item); } - final public function describeMismatch($item, Description $mismatchDescription) + final public function describeMismatch($item, Description $mismatchDescription): void { if (!$this->_isSafeType($item)) { parent::describeMismatch($item, $mismatchDescription); @@ -60,17 +64,22 @@ final public function describeMismatch($item, Description $mismatchDescription) /** * The item will already have been checked for the specific type and subtype. + * @param mixed $item */ - abstract protected function matchesSafely($item); + abstract protected function matchesSafely($item): bool; /** * The item will already have been checked for the specific type and subtype. + * @param mixed $item */ - abstract protected function describeMismatchSafely($item, Description $mismatchDescription); + abstract protected function describeMismatchSafely($item, Description $mismatchDescription): void; // -- Private Methods - private function _isSafeType($value) + /** + * @param mixed $value + */ + private function _isSafeType($value): bool { switch ($this->_expectedType) { diff --git a/hamcrest/Hamcrest/Util.php b/hamcrest/Hamcrest/Util.php index 169b03663..aedf1e32a 100644 --- a/hamcrest/Hamcrest/Util.php +++ b/hamcrest/Hamcrest/Util.php @@ -12,7 +12,7 @@ */ class Util { - public static function registerGlobalFunctions() + public static function registerGlobalFunctions(): void { require_once __DIR__.'/../Hamcrest.php'; } @@ -34,10 +34,10 @@ public static function wrapValueWithIsEqual($item) /** * Throws an exception if any item in $matchers is not a Hamcrest\Matcher. * - * @param array $matchers expected to contain only matchers + * @param array $matchers expected to contain only matchers * @throws \InvalidArgumentException if any item is not a matcher */ - public static function checkAllAreMatchers(array $matchers) + public static function checkAllAreMatchers(array $matchers): void { foreach ($matchers as $m) { if (!($m instanceof Matcher)) { @@ -54,8 +54,8 @@ public static function checkAllAreMatchers(array $matchers) * is an array, it is used as the $items array to support the old style * of passing an array as the sole argument to a matcher. * - * @param array $items contains items and matchers - * @return array all items are + * @param array $items contains items and matchers + * @return array all items are */ public static function createMatcherArray(array $items) { diff --git a/hamcrest/Hamcrest/Xml/HasXPath.php b/hamcrest/Hamcrest/Xml/HasXPath.php index bedf9694a..2529f7270 100644 --- a/hamcrest/Hamcrest/Xml/HasXPath.php +++ b/hamcrest/Hamcrest/Xml/HasXPath.php @@ -22,17 +22,20 @@ class HasXPath extends DiagnosingMatcher * * @var string */ - private $_xpath; + private string $_xpath; /** * Optional matcher to apply to the XPath expression result * or the content of the returned nodes. * - * @var Matcher + * @var ?Matcher */ - private $_matcher; + private ?Matcher $_matcher; - public function __construct($xpath, ?Matcher $matcher = null) + /** + * @param string $xpath + */ + public function __construct(string $xpath, ?Matcher $matcher = null) { $this->_xpath = $xpath; $this->_matcher = $matcher; @@ -45,11 +48,11 @@ public function __construct($xpath, ?Matcher $matcher = null) * @param Description $mismatchDescription * @return bool */ - protected function matchesWithDiagnosticDescription($actual, Description $mismatchDescription) + protected function matchesWithDiagnosticDescription($actual, Description $mismatchDescription): bool { if (is_string($actual)) { $actual = $this->createDocument($actual); - } elseif (!$actual instanceof \DOMNode) { + } elseif (!$actual instanceof \DOMNode) { // @phpstan-ignore instanceof.alwaysTrue (unless actual is a native union type, we want to check this) $mismatchDescription->appendText('was ')->appendValue($actual); return false; @@ -114,7 +117,7 @@ protected function evaluate(\DOMNode $node) * @param Description $mismatchDescription * @return bool */ - protected function matchesContent(\DOMNodeList $nodes, Description $mismatchDescription) + protected function matchesContent(\DOMNodeList $nodes, Description $mismatchDescription): bool { if ($nodes->length == 0) { $mismatchDescription->appendText('XPath returned no results'); @@ -145,7 +148,7 @@ protected function matchesContent(\DOMNodeList $nodes, Description $mismatchDesc * @param Description $mismatchDescription * @return bool */ - protected function matchesExpression($result, Description $mismatchDescription) + protected function matchesExpression($result, Description $mismatchDescription): bool { if ($this->_matcher === null) { if ($result) { @@ -164,7 +167,7 @@ protected function matchesExpression($result, Description $mismatchDescription) return false; } - public function describeTo(Description $description) + public function describeTo(Description $description): void { $description->appendText('XML or HTML document with XPath "') ->appendText($this->_xpath) @@ -181,8 +184,10 @@ public function describeTo(Description $description) * if it's an integer. * * @factory + * @param string $xpath + * @param null|Matcher|int|mixed $matcher */ - public static function hasXPath($xpath, $matcher = null) + public static function hasXPath(string $xpath, $matcher = null): self { if ($matcher === null || $matcher instanceof Matcher) { return new self($xpath, $matcher); diff --git a/tests/Hamcrest/BaseMatcherTest.php b/tests/Hamcrest/BaseMatcherTest.php index 833e2c3ec..f915f8641 100644 --- a/tests/Hamcrest/BaseMatcherTest.php +++ b/tests/Hamcrest/BaseMatcherTest.php @@ -5,12 +5,12 @@ class BaseMatcherTest extends \Hamcrest\BaseMatcher { - public function matches($item) + public function matches($item): bool { throw new \RuntimeException(); } - public function describeTo(\Hamcrest\Description $description) + public function describeTo(\Hamcrest\Description $description): void { $description->appendText('SOME DESCRIPTION'); } diff --git a/tests/Hamcrest/Core/IsInstanceOfTest.php b/tests/Hamcrest/Core/IsInstanceOfTest.php index 795b43012..5a8fb5e84 100644 --- a/tests/Hamcrest/Core/IsInstanceOfTest.php +++ b/tests/Hamcrest/Core/IsInstanceOfTest.php @@ -18,7 +18,7 @@ protected function setUpTest() $this->_subClassInstance = new \Hamcrest\Core\SampleSubClass('good'); } - protected function createMatcher() + protected function createMatcher(): IsInstanceOf { return \Hamcrest\Core\IsInstanceOf::anInstanceOf('stdClass'); } diff --git a/tests/Hamcrest/InvokedMatcherTest.php b/tests/Hamcrest/InvokedMatcherTest.php index dfa770061..6731acdf9 100644 --- a/tests/Hamcrest/InvokedMatcherTest.php +++ b/tests/Hamcrest/InvokedMatcherTest.php @@ -12,7 +12,7 @@ public function __construct($matchAgainst) $this->matchAgainst = $matchAgainst; } - public function matches($item) + public function matches($item): bool { return $item == $this->matchAgainst; } diff --git a/tests/Hamcrest/StringDescriptionTest.php b/tests/Hamcrest/StringDescriptionTest.php index 4a403e994..537ae7d61 100644 --- a/tests/Hamcrest/StringDescriptionTest.php +++ b/tests/Hamcrest/StringDescriptionTest.php @@ -12,7 +12,7 @@ public function __construct($text) $this->_text = $text; } - public function describeTo(\Hamcrest\Description $description) + public function describeTo(\Hamcrest\Description $description): void { $description->appendText($this->_text); } From f75c291f481d219ac35a18f86b3ae2fe7aba578b Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Wed, 25 Jun 2025 15:58:30 +0200 Subject: [PATCH 04/15] cleanup gitignore and justfile --- .gitignore | 3 +-- Justfile | 32 -------------------------------- 2 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 Justfile diff --git a/.gitignore b/.gitignore index 73f9b899d..acf2ac9a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ composer.lock tests/.phpunit.result.cache +tests/phpunit.xml vendor -/.phpunit.result.cache -/tests/phpunit.xml diff --git a/Justfile b/Justfile deleted file mode 100644 index d6d915053..000000000 --- a/Justfile +++ /dev/null @@ -1,32 +0,0 @@ -set dotenv-load := false -set positional-arguments - -export COLUMNS := '550' - -default: - @just --list - -php := "/usr/bin/php7.4" -composer := "/usr/bin/php7.4 /usr/local/bin/composer" - -cli *args='': - {{ php }} bin/console "$@" - -phpstan *args='': - {{ php }} vendor/bin/phpstan "${@}" - -watch-phpstan *args='': - find hamcrest/ tests/ -name '*.php' | entr {{ php }} vendor/bin/phpstan "${@}" - -phpunit *args='': - {{ php }} vendor/bin/phpunit --config=tests/phpunit.xml "${@}" - -composer *args='': - {{ composer }} "${@}" - -phpstan-generate-baseline: - just phpstan analyse --generate-baseline=tests/phpstan-baseline.neon - -prep: - just phpstan - just phpunit From 8c6d2a383673a4229d8694e6ace34383ba56d902 Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Wed, 25 Jun 2025 16:19:23 +0200 Subject: [PATCH 05/15] codestyling --- hamcrest/Hamcrest/Core/IsNull.php | 2 -- hamcrest/Hamcrest/Core/ShortcutCombination.php | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/hamcrest/Hamcrest/Core/IsNull.php b/hamcrest/Hamcrest/Core/IsNull.php index 84686f744..26f79025c 100644 --- a/hamcrest/Hamcrest/Core/IsNull.php +++ b/hamcrest/Hamcrest/Core/IsNull.php @@ -4,10 +4,8 @@ /* Copyright (c) 2009 hamcrest.org */ - use Hamcrest\BaseMatcher; use Hamcrest\Description; -use Hamcrest\Matcher; /** * Is the value null? diff --git a/hamcrest/Hamcrest/Core/ShortcutCombination.php b/hamcrest/Hamcrest/Core/ShortcutCombination.php index 8638a3949..076ffd4a4 100644 --- a/hamcrest/Hamcrest/Core/ShortcutCombination.php +++ b/hamcrest/Hamcrest/Core/ShortcutCombination.php @@ -4,7 +4,6 @@ /* Copyright (c) 2009 hamcrest.org */ - use Hamcrest\BaseMatcher; use Hamcrest\Description; use Hamcrest\Matcher; @@ -14,12 +13,12 @@ abstract class ShortcutCombination extends BaseMatcher { /** - * @var array<\Hamcrest\Matcher> + * @var array */ private $_matchers; /** - * @param array<\Hamcrest\Matcher> $matchers + * @param array $matchers */ public function __construct(array $matchers) { From 3603c584172aa0fd693bce803fda3647f87b4f44 Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Wed, 25 Jun 2025 16:42:28 +0200 Subject: [PATCH 06/15] Generate the files instead of modifying them and fix the code generator to do so --- generator/FactoryFile.php | 7 ++++++- generator/parts/functions_header.txt | 2 +- hamcrest/Hamcrest/Core/DescribedAs.php | 10 +++++++--- hamcrest/Hamcrest/Core/Every.php | 2 +- hamcrest/Hamcrest/Text/StringEndsWith.php | 1 - 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/generator/FactoryFile.php b/generator/FactoryFile.php index dd6109b1f..dfffe3806 100644 --- a/generator/FactoryFile.php +++ b/generator/FactoryFile.php @@ -65,7 +65,7 @@ public function generateDeclaration($name, FactoryMethod $method) $code = $this->indent . $this->getDeclarationModifiers() . 'function ' . $name . '(' . $this->generateDeclarationArguments($method) - . ')' . "\n" . $this->indent . '{' . "\n"; + . '): ' . $this->generateReturnType($method) . "\n" . $this->indent . '{' . "\n"; return $code; } @@ -83,6 +83,11 @@ public function generateDeclarationArguments(FactoryMethod $method) } } + public function generateReturnType(FactoryMethod $method): string + { + return '\Hamcrest\Matcher'; + } + public function generateImport(FactoryMethod $method) { return $this->indent . self::INDENT . "require_once '" . $method->getClass()->getFile() . "';" . "\n"; diff --git a/generator/parts/functions_header.txt b/generator/parts/functions_header.txt index 50d23df8f..8cb9b3090 100644 --- a/generator/parts/functions_header.txt +++ b/generator/parts/functions_header.txt @@ -13,7 +13,7 @@ if (!function_exists('assertThat')) { * assertThat("some error", $a > $b); * */ - function assertThat() + function assertThat(): void { $args = func_get_args(); call_user_func_array( diff --git a/hamcrest/Hamcrest/Core/DescribedAs.php b/hamcrest/Hamcrest/Core/DescribedAs.php index 5b6faca1d..28fc867f4 100644 --- a/hamcrest/Hamcrest/Core/DescribedAs.php +++ b/hamcrest/Hamcrest/Core/DescribedAs.php @@ -61,10 +61,14 @@ public function describeTo(Description $description): void * Wraps an existing matcher and overrides the description when it fails. * * @factory ... - * @param mixed ...$values */ - public static function describedAs(string $descriptionTemplate, \Hamcrest\Matcher $matcher, ...$values): self + public static function describedAs(/* $description, Hamcrest\Matcher $matcher, $values... */): self { - return new self($descriptionTemplate, $matcher, $values); + $args = func_get_args(); + $description = array_shift($args); + $matcher = array_shift($args); + $values = $args; + + return new self($description, $matcher, $values); } } diff --git a/hamcrest/Hamcrest/Core/Every.php b/hamcrest/Hamcrest/Core/Every.php index fd202fa80..76a447b49 100644 --- a/hamcrest/Hamcrest/Core/Every.php +++ b/hamcrest/Hamcrest/Core/Every.php @@ -41,7 +41,7 @@ public function describeTo(Description $description): void } /** - * @param Matcher $itemMatcher + * @param \Hamcrest\Matcher $itemMatcher * A matcher to apply to every element in an array. * * @return \Hamcrest\Core\Every diff --git a/hamcrest/Hamcrest/Text/StringEndsWith.php b/hamcrest/Hamcrest/Text/StringEndsWith.php index 2684a9bce..d3468f3cf 100644 --- a/hamcrest/Hamcrest/Text/StringEndsWith.php +++ b/hamcrest/Hamcrest/Text/StringEndsWith.php @@ -24,7 +24,6 @@ public function __construct($substring) * * @factory * @param mixed $substring - * @return StringEndsWith */ public static function endsWith($substring): self { From ef3183e2efec9a23dce5f7af3e05f87fba07ac41 Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Wed, 25 Jun 2025 17:10:20 +0200 Subject: [PATCH 07/15] fix the return type of the Description interface to be static instead of self --- hamcrest/Hamcrest/BaseDescription.php | 2 +- hamcrest/Hamcrest/Description.php | 2 +- tests/phpstan-baseline.neon | 6 ------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/hamcrest/Hamcrest/BaseDescription.php b/hamcrest/Hamcrest/BaseDescription.php index 4f0fce55f..4805443e6 100644 --- a/hamcrest/Hamcrest/BaseDescription.php +++ b/hamcrest/Hamcrest/BaseDescription.php @@ -19,7 +19,7 @@ public function appendText(string $text): self return $this; } - public function appendDescriptionOf(SelfDescribing $value): self + public function appendDescriptionOf(SelfDescribing $value) { $value->describeTo($this); diff --git a/hamcrest/Hamcrest/Description.php b/hamcrest/Hamcrest/Description.php index 4fb573997..780a4e78f 100644 --- a/hamcrest/Hamcrest/Description.php +++ b/hamcrest/Hamcrest/Description.php @@ -31,7 +31,7 @@ public function appendText(string $text): self; * * @return static */ - public function appendDescriptionOf(SelfDescribing $value): self; + public function appendDescriptionOf(SelfDescribing $value); /** * Appends an arbitrary value to the description. diff --git a/tests/phpstan-baseline.neon b/tests/phpstan-baseline.neon index 48e69f310..86f54f27a 100644 --- a/tests/phpstan-baseline.neon +++ b/tests/phpstan-baseline.neon @@ -18,12 +18,6 @@ parameters: count: 1 path: ../hamcrest/Hamcrest/Core/HasToString.php - - - message: '#^Cannot cast Hamcrest\\BaseDescription to string\.$#' - identifier: cast.string - count: 1 - path: ../hamcrest/Hamcrest/StringDescription.php - - message: '#^Argument of an invalid type list\\|false supplied for foreach, only iterables are supported\.$#' identifier: foreach.nonIterable From 39afaffcf6055b7d7fb516a372c0c59b1adf2dcf Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Wed, 25 Jun 2025 20:32:49 +0200 Subject: [PATCH 08/15] Can use native Matcher typehints for the privates in IsArrayContainingKeyValuePair --- .../Hamcrest/Arrays/IsArrayContainingKeyValuePair.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/hamcrest/Hamcrest/Arrays/IsArrayContainingKeyValuePair.php b/hamcrest/Hamcrest/Arrays/IsArrayContainingKeyValuePair.php index 627466dd8..5aa736805 100644 --- a/hamcrest/Hamcrest/Arrays/IsArrayContainingKeyValuePair.php +++ b/hamcrest/Hamcrest/Arrays/IsArrayContainingKeyValuePair.php @@ -15,14 +15,8 @@ class IsArrayContainingKeyValuePair extends TypeSafeMatcher { - /** - * @var mixed $_keyMatcher - */ - private $_keyMatcher; - /** - * @var mixed $_valueMatcher - */ - private $_valueMatcher; + private Matcher $_keyMatcher; + private Matcher $_valueMatcher; public function __construct(Matcher $keyMatcher, Matcher $valueMatcher) { From 2564fbaf8508e593260c5bee02157e6959ce7fda Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Sat, 26 Jul 2025 11:02:37 +0200 Subject: [PATCH 09/15] return the return type of the called method when generating factory methods and calls --- composer.json | 3 ++- generator/FactoryFile.php | 14 +++++++++++++- generator/FactoryMethod.php | 15 +++++++++++++++ hamcrest/Hamcrest/Core/IsAnything.php | 3 +-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 4a08fda8b..32ee93606 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "phpunit/php-file-iterator": "^1.4 || ^2.0 || ^3.0", "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0", "phpstan/phpstan": "^2.1", - "phpstan/phpstan-phpunit": "^2.0" + "phpstan/phpstan-phpunit": "^2.0", + "symfony/var-dumper": "^5.4" }, "replace": { diff --git a/generator/FactoryFile.php b/generator/FactoryFile.php index dfffe3806..2df96a686 100644 --- a/generator/FactoryFile.php +++ b/generator/FactoryFile.php @@ -85,7 +85,19 @@ public function generateDeclarationArguments(FactoryMethod $method) public function generateReturnType(FactoryMethod $method): string { - return '\Hamcrest\Matcher'; + $call = $method->getCalls()[0]; + if (!$call instanceof FactoryCall) { + throw new Exception('The first call in the FactoryMethod cannot be used to determine the return type. Method: '.$method->getName()); + } + + $returnType = $call->getMethod()->getReturnType(); + + if (!$returnType) { + dump($method); + throw new \Exception('The first calls FactoryMethod cannot be used to determine the return type. Method: '.$method->getName()); + } + + return sprintf('\\%s', $returnType); } public function generateImport(FactoryMethod $method) diff --git a/generator/FactoryMethod.php b/generator/FactoryMethod.php index 8a05371be..d3a04187f 100644 --- a/generator/FactoryMethod.php +++ b/generator/FactoryMethod.php @@ -214,6 +214,21 @@ public function getFullName() return $this->getClassName() . '::' . $this->getName(); } + public function getReturnType(): ?string + { + if (!$this->reflector->hasReturnType()) { + return null; + } + + $returnType = $this->reflector->getReturnType()->getName(); + + if ($returnType === 'self') { + return $this->reflector->getDeclaringClass()->getName(); + } + + return $returnType; + } + public function getCommentText() { return implode("\n", $this->comment); diff --git a/hamcrest/Hamcrest/Core/IsAnything.php b/hamcrest/Hamcrest/Core/IsAnything.php index 2b9e19dc4..0ec9d9f04 100644 --- a/hamcrest/Hamcrest/Core/IsAnything.php +++ b/hamcrest/Hamcrest/Core/IsAnything.php @@ -35,10 +35,9 @@ public function describeTo(Description $description): void * * @param string $description A meaningful string used when describing itself. * - * @return \Hamcrest\Core\IsAnything * @factory */ - public static function anything(string $description = 'ANYTHING') + public static function anything(string $description = 'ANYTHING'): self { return new self($description); } From cbdee96eeb4eaeb2f1ab2f17643cdb2afb14c217 Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Sat, 26 Jul 2025 11:11:44 +0200 Subject: [PATCH 10/15] regenerate Matchers and Hamcrest to resolve conflicts --- hamcrest/Hamcrest.php | 37 ++++++++++++++--- hamcrest/Hamcrest/Matchers.php | 73 +++++++++++++++++++++------------- 2 files changed, 77 insertions(+), 33 deletions(-) diff --git a/hamcrest/Hamcrest.php b/hamcrest/Hamcrest.php index 5612c0987..2fb541a2b 100644 --- a/hamcrest/Hamcrest.php +++ b/hamcrest/Hamcrest.php @@ -6,8 +6,6 @@ // This file is generated from the static method @factory doctags. -use Hamcrest\Matcher; - if (!function_exists('assertThat')) { /** * Make an assertion and throw {@link Hamcrest_AssertionError} if it fails. @@ -146,6 +144,7 @@ function hasKey($key): \Hamcrest\Arrays\IsArrayContainingKey if (!function_exists('hasKeyValuePair')) { /** * Test if an array has both an key and value in parity with each other. + * * @param mixed $key * @param mixed $value */ @@ -158,6 +157,7 @@ function hasKeyValuePair($key, $value): \Hamcrest\Arrays\IsArrayContainingKeyVal if (!function_exists('hasEntry')) { /** * Test if an array has both an key and value in parity with each other. + * * @param mixed $key * @param mixed $value */ @@ -224,6 +224,7 @@ function nonEmptyTraversable(): \Hamcrest\Collection\IsEmptyTraversable if (!function_exists('traversableWithSize')) { /** * Does traversable size satisfy a given matcher? + * * @param mixed $size */ function traversableWithSize($size): \Hamcrest\Collection\IsTraversableWithSize @@ -306,7 +307,7 @@ function describedAs(/* args... */): \Hamcrest\Core\DescribedAs if (!function_exists('everyItem')) { /** - * @param Matcher $itemMatcher + * @param \Hamcrest\Matcher $itemMatcher * A matcher to apply to every element in an array. * * @return \Hamcrest\Core\Every @@ -322,6 +323,8 @@ function everyItem(\Hamcrest\Matcher $itemMatcher): \Hamcrest\Core\Every /** * Creates a matcher that matches any examined object whose toString or * __toString() method returns a value equalTo the specified string. + * + * @param mixed $matcher */ function hasToString($matcher): \Hamcrest\Core\HasToString { @@ -336,6 +339,7 @@ function hasToString($matcher): \Hamcrest\Core\HasToString * * For example: assertThat($cheese, equalTo($smelly)) * vs. assertThat($cheese, is(equalTo($smelly))) + * * @param mixed $value */ function is($value): \Hamcrest\Core\Is @@ -349,8 +353,6 @@ function is($value): \Hamcrest\Core\Is * This matcher always evaluates to true. * * @param string $description A meaningful string used when describing itself. - * - * @return \Hamcrest\Core\IsAnything */ function anything(string $description = 'ANYTHING'): \Hamcrest\Core\IsAnything { @@ -397,6 +399,7 @@ function hasItems(/* args... */): \Hamcrest\Core\AllOf /** * Is the value equal to another value, as tested by the use of the "==" * comparison operator? + * * @param mixed $item */ function equalTo($item): \Hamcrest\Core\IsEqual @@ -408,6 +411,7 @@ function equalTo($item): \Hamcrest\Core\IsEqual if (!function_exists('identicalTo')) { /** * Tests of the value is identical to $value as tested by the "===" operator. + * * @param mixed $value */ function identicalTo($value): \Hamcrest\Core\IsIdentical @@ -445,6 +449,7 @@ function any(string $theClass): \Hamcrest\Core\IsInstanceOf if (!function_exists('not')) { /** * Matches if value does not match $value. + * * @param mixed $value */ function not($value): \Hamcrest\Core\IsNot @@ -492,6 +497,8 @@ function sameInstance($object): \Hamcrest\Core\IsSame if (!function_exists('typeOf')) { /** * Is the value a particular built-in type? + * + * @param string $theType */ function typeOf(string $theType): \Hamcrest\Core\IsTypeOf { @@ -502,6 +509,7 @@ function typeOf(string $theType): \Hamcrest\Core\IsTypeOf if (!function_exists('set')) { /** * Matches if value (class, object, or array) has named $property. + * * @param mixed $property */ function set($property): \Hamcrest\Core\Set @@ -513,6 +521,7 @@ function set($property): \Hamcrest\Core\Set if (!function_exists('notSet')) { /** * Matches if value (class, object, or array) does not have named $property. + * * @param mixed $property */ function notSet($property): \Hamcrest\Core\Set @@ -525,6 +534,7 @@ function notSet($property): \Hamcrest\Core\Set /** * Matches if value is a number equal to $value within some range of * acceptable error $delta. + * * @param mixed $value * @param mixed $delta */ @@ -537,6 +547,7 @@ function closeTo($value, $delta): \Hamcrest\Number\IsCloseTo if (!function_exists('comparesEqualTo')) { /** * The value is not > $value, nor < $value. + * * @param mixed $value */ function comparesEqualTo($value): \Hamcrest\Number\OrderingComparison @@ -548,6 +559,7 @@ function comparesEqualTo($value): \Hamcrest\Number\OrderingComparison if (!function_exists('greaterThan')) { /** * The value is > $value. + * * @param mixed $value */ function greaterThan($value): \Hamcrest\Number\OrderingComparison @@ -559,6 +571,7 @@ function greaterThan($value): \Hamcrest\Number\OrderingComparison if (!function_exists('greaterThanOrEqualTo')) { /** * The value is >= $value. + * * @param mixed $value */ function greaterThanOrEqualTo($value): \Hamcrest\Number\OrderingComparison @@ -570,6 +583,7 @@ function greaterThanOrEqualTo($value): \Hamcrest\Number\OrderingComparison if (!function_exists('atLeast')) { /** * The value is >= $value. + * * @param mixed $value */ function atLeast($value): \Hamcrest\Number\OrderingComparison @@ -581,6 +595,7 @@ function atLeast($value): \Hamcrest\Number\OrderingComparison if (!function_exists('lessThan')) { /** * The value is < $value. + * * @param mixed $value */ function lessThan($value): \Hamcrest\Number\OrderingComparison @@ -592,6 +607,7 @@ function lessThan($value): \Hamcrest\Number\OrderingComparison if (!function_exists('lessThanOrEqualTo')) { /** * The value is <= $value. + * * @param mixed $value */ function lessThanOrEqualTo($value): \Hamcrest\Number\OrderingComparison @@ -603,6 +619,7 @@ function lessThanOrEqualTo($value): \Hamcrest\Number\OrderingComparison if (!function_exists('atMost')) { /** * The value is <= $value. + * * @param mixed $value */ function atMost($value): \Hamcrest\Number\OrderingComparison @@ -674,6 +691,7 @@ function nonEmptyString(): \Hamcrest\Text\IsEmptyString if (!function_exists('equalToIgnoringCase')) { /** * Matches if value is a string equal to $string, regardless of the case. + * * @param mixed $string */ function equalToIgnoringCase($string): \Hamcrest\Text\IsEqualIgnoringCase @@ -685,6 +703,7 @@ function equalToIgnoringCase($string): \Hamcrest\Text\IsEqualIgnoringCase if (!function_exists('equalToIgnoringWhiteSpace')) { /** * Matches if value is a string equal to $string, regardless of whitespace. + * * @param mixed $string */ function equalToIgnoringWhiteSpace($string): \Hamcrest\Text\IsEqualIgnoringWhiteSpace @@ -696,6 +715,7 @@ function equalToIgnoringWhiteSpace($string): \Hamcrest\Text\IsEqualIgnoringWhite if (!function_exists('matchesPattern')) { /** * Matches if value is a string that matches regular expression $pattern. + * * @param mixed $pattern */ function matchesPattern($pattern): \Hamcrest\Text\MatchesPattern @@ -707,6 +727,7 @@ function matchesPattern($pattern): \Hamcrest\Text\MatchesPattern if (!function_exists('containsString')) { /** * Matches if value is a string that contains $substring. + * * @param mixed $substring */ function containsString($substring): \Hamcrest\Text\StringContains @@ -718,6 +739,7 @@ function containsString($substring): \Hamcrest\Text\StringContains if (!function_exists('containsStringIgnoringCase')) { /** * Matches if value is a string that contains $substring regardless of the case. + * * @param mixed $substring */ function containsStringIgnoringCase($substring): \Hamcrest\Text\StringContainsIgnoringCase @@ -740,6 +762,7 @@ function stringContainsInOrder(/* args... */): \Hamcrest\Text\StringContainsInOr if (!function_exists('endsWith')) { /** * Matches if value is a string that ends with $substring. + * * @param mixed $substring */ function endsWith($substring): \Hamcrest\Text\StringEndsWith @@ -751,6 +774,7 @@ function endsWith($substring): \Hamcrest\Text\StringEndsWith if (!function_exists('startsWith')) { /** * Matches if value is a string that starts with $substring. + * * @param mixed $substring */ function startsWith($substring): \Hamcrest\Text\StringStartsWith @@ -904,10 +928,11 @@ function stringValue(): \Hamcrest\Type\IsString * Wraps $matcher with {@link Hamcrest\Core\IsEqual) * if it's not a matcher and the XPath in count() * if it's an integer. + * * @param string $xpath * @param null|Matcher|int|mixed $matcher */ - function hasXPath($xpath, $matcher = null): \Hamcrest\Xml\HasXPath + function hasXPath(string $xpath, $matcher = null): \Hamcrest\Xml\HasXPath { return \Hamcrest\Xml\HasXPath::hasXPath($xpath, $matcher); } diff --git a/hamcrest/Hamcrest/Matchers.php b/hamcrest/Hamcrest/Matchers.php index 37db6eea1..b7e62a1cb 100644 --- a/hamcrest/Hamcrest/Matchers.php +++ b/hamcrest/Hamcrest/Matchers.php @@ -8,15 +8,6 @@ namespace Hamcrest; -use Hamcrest\Arrays\IsArray; -use Hamcrest\Arrays\IsArrayContainingInAnyOrder; -use Hamcrest\Arrays\IsArrayContainingInOrder; -use Hamcrest\Core\AllOf; -use Hamcrest\Core\AnyOf; -use Hamcrest\Core\DescribedAs; -use Hamcrest\Core\IsCollectionContaining; -use Hamcrest\Text\StringContainsInOrder; - /** * A series of static factories for all hamcrest matchers. */ @@ -26,7 +17,7 @@ class Matchers /** * Evaluates to true only if each $matcher[$i] is satisfied by $array[$i]. */ - public static function anArray(/* args... */): IsArray + public static function anArray(/* args... */): \Hamcrest\Arrays\IsArray { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArray', 'anArray'), $args); @@ -59,7 +50,7 @@ public static function hasValue($item): \Hamcrest\Arrays\IsArrayContaining /** * An array with elements that match the given matchers. */ - public static function arrayContainingInAnyOrder(/* args... */): IsArrayContainingInAnyOrder + public static function arrayContainingInAnyOrder(/* args... */): \Hamcrest\Arrays\IsArrayContainingInAnyOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args); @@ -68,7 +59,7 @@ public static function arrayContainingInAnyOrder(/* args... */): IsArrayContaini /** * An array with elements that match the given matchers. */ - public static function containsInAnyOrder(/* args... */): IsArrayContainingInAnyOrder + public static function containsInAnyOrder(/* args... */): \Hamcrest\Arrays\IsArrayContainingInAnyOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args); @@ -77,7 +68,7 @@ public static function containsInAnyOrder(/* args... */): IsArrayContainingInAny /** * An array with elements that match the given matchers in the same order. */ - public static function arrayContaining(/* args... */): IsArrayContainingInOrder + public static function arrayContaining(/* args... */): \Hamcrest\Arrays\IsArrayContainingInOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args); @@ -86,7 +77,7 @@ public static function arrayContaining(/* args... */): IsArrayContainingInOrder /** * An array with elements that match the given matchers in the same order. */ - public static function contains(/* args... */): IsArrayContainingInOrder + public static function contains(/* args... */): \Hamcrest\Arrays\IsArrayContainingInOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args); @@ -118,6 +109,7 @@ public static function hasKey($key): \Hamcrest\Arrays\IsArrayContainingKey /** * Test if an array has both an key and value in parity with each other. + * * @param mixed $key * @param mixed $value */ @@ -128,6 +120,7 @@ public static function hasKeyValuePair($key, $value): \Hamcrest\Arrays\IsArrayCo /** * Test if an array has both an key and value in parity with each other. + * * @param mixed $key * @param mixed $value */ @@ -182,6 +175,7 @@ public static function nonEmptyTraversable(): \Hamcrest\Collection\IsEmptyTraver /** * Does traversable size satisfy a given matcher? + * * @param mixed $size */ public static function traversableWithSize($size): \Hamcrest\Collection\IsTraversableWithSize @@ -192,7 +186,7 @@ public static function traversableWithSize($size): \Hamcrest\Collection\IsTraver /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ - public static function allOf(/* args... */): AllOf + public static function allOf(/* args... */): \Hamcrest\Core\AllOf { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AllOf', 'allOf'), $args); @@ -201,7 +195,7 @@ public static function allOf(/* args... */): AllOf /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ - public static function anyOf(/* args... */): AnyOf + public static function anyOf(/* args... */): \Hamcrest\Core\AnyOf { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'anyOf'), $args); @@ -210,7 +204,7 @@ public static function anyOf(/* args... */): AnyOf /** * Evaluates to false if ANY of the passed in matchers evaluate to true. */ - public static function noneOf(/* args... */): AnyOf + public static function noneOf(/* args... */): \Hamcrest\Core\IsNot { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'noneOf'), $args); @@ -243,14 +237,14 @@ public static function either(\Hamcrest\Matcher $matcher): \Hamcrest\Core\Combin /** * Wraps an existing matcher and overrides the description when it fails. */ - public static function describedAs(/* args... */): DescribedAs + public static function describedAs(/* args... */): \Hamcrest\Core\DescribedAs { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\DescribedAs', 'describedAs'), $args); } /** - * @param Matcher $itemMatcher + * @param \Hamcrest\Matcher $itemMatcher * A matcher to apply to every element in an array. * * @return \Hamcrest\Core\Every @@ -264,6 +258,8 @@ public static function everyItem(\Hamcrest\Matcher $itemMatcher): \Hamcrest\Core /** * Creates a matcher that matches any examined object whose toString or * __toString() method returns a value equalTo the specified string. + * + * @param mixed $matcher */ public static function hasToString($matcher): \Hamcrest\Core\HasToString { @@ -276,6 +272,7 @@ public static function hasToString($matcher): \Hamcrest\Core\HasToString * * For example: assertThat($cheese, equalTo($smelly)) * vs. assertThat($cheese, is(equalTo($smelly))) + * * @param mixed $value */ public static function is($value): \Hamcrest\Core\Is @@ -287,8 +284,6 @@ public static function is($value): \Hamcrest\Core\Is * This matcher always evaluates to true. * * @param string $description A meaningful string used when describing itself. - * - * @return \Hamcrest\Core\IsAnything */ public static function anything(string $description = 'ANYTHING'): \Hamcrest\Core\IsAnything { @@ -305,7 +300,7 @@ public static function anything(string $description = 'ANYTHING'): \Hamcrest\Cor * assertThat(array('a', 'b'), hasItem('b')); * */ - public static function hasItem(/* args... */): IsCollectionContaining + public static function hasItem(/* args... */): \Hamcrest\Core\IsCollectionContaining { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItem'), $args); @@ -320,7 +315,7 @@ public static function hasItem(/* args... */): IsCollectionContaining * assertThat(array('a', 'b', 'c'), hasItems(equalTo('a'), equalTo('b'))); * */ - public static function hasItems(/* args... */): IsCollectionContaining + public static function hasItems(/* args... */): \Hamcrest\Core\AllOf { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItems'), $args); @@ -329,6 +324,7 @@ public static function hasItems(/* args... */): IsCollectionContaining /** * Is the value equal to another value, as tested by the use of the "==" * comparison operator? + * * @param mixed $item */ public static function equalTo($item): \Hamcrest\Core\IsEqual @@ -338,6 +334,7 @@ public static function equalTo($item): \Hamcrest\Core\IsEqual /** * Tests of the value is identical to $value as tested by the "===" operator. + * * @param mixed $value */ public static function identicalTo($value): \Hamcrest\Core\IsIdentical @@ -369,6 +366,7 @@ public static function any(string $theClass): \Hamcrest\Core\IsInstanceOf /** * Matches if value does not match $value. + * * @param mixed $value */ public static function not($value): \Hamcrest\Core\IsNot @@ -387,7 +385,7 @@ public static function nullValue(): \Hamcrest\Core\IsNull /** * Matches if value is not null. */ - public static function notNullValue(): Matcher + public static function notNullValue(): \Hamcrest\Core\IsNot { return \Hamcrest\Core\IsNull::notNullValue(); } @@ -408,6 +406,8 @@ public static function sameInstance($object): \Hamcrest\Core\IsSame /** * Is the value a particular built-in type? + * + * @param string $theType */ public static function typeOf(string $theType): \Hamcrest\Core\IsTypeOf { @@ -416,6 +416,7 @@ public static function typeOf(string $theType): \Hamcrest\Core\IsTypeOf /** * Matches if value (class, object, or array) has named $property. + * * @param mixed $property */ public static function set($property): \Hamcrest\Core\Set @@ -425,6 +426,7 @@ public static function set($property): \Hamcrest\Core\Set /** * Matches if value (class, object, or array) does not have named $property. + * * @param mixed $property */ public static function notSet($property): \Hamcrest\Core\Set @@ -435,6 +437,7 @@ public static function notSet($property): \Hamcrest\Core\Set /** * Matches if value is a number equal to $value within some range of * acceptable error $delta. + * * @param mixed $value * @param mixed $delta */ @@ -445,6 +448,7 @@ public static function closeTo($value, $delta): \Hamcrest\Number\IsCloseTo /** * The value is not > $value, nor < $value. + * * @param mixed $value */ public static function comparesEqualTo($value): \Hamcrest\Number\OrderingComparison @@ -454,6 +458,7 @@ public static function comparesEqualTo($value): \Hamcrest\Number\OrderingCompari /** * The value is > $value. + * * @param mixed $value */ public static function greaterThan($value): \Hamcrest\Number\OrderingComparison @@ -463,6 +468,7 @@ public static function greaterThan($value): \Hamcrest\Number\OrderingComparison /** * The value is >= $value. + * * @param mixed $value */ public static function greaterThanOrEqualTo($value): \Hamcrest\Number\OrderingComparison @@ -472,6 +478,7 @@ public static function greaterThanOrEqualTo($value): \Hamcrest\Number\OrderingCo /** * The value is >= $value. + * * @param mixed $value */ public static function atLeast($value): \Hamcrest\Number\OrderingComparison @@ -481,6 +488,7 @@ public static function atLeast($value): \Hamcrest\Number\OrderingComparison /** * The value is < $value. + * * @param mixed $value */ public static function lessThan($value): \Hamcrest\Number\OrderingComparison @@ -490,6 +498,7 @@ public static function lessThan($value): \Hamcrest\Number\OrderingComparison /** * The value is <= $value. + * * @param mixed $value */ public static function lessThanOrEqualTo($value): \Hamcrest\Number\OrderingComparison @@ -499,6 +508,7 @@ public static function lessThanOrEqualTo($value): \Hamcrest\Number\OrderingCompa /** * The value is <= $value. + * * @param mixed $value */ public static function atMost($value): \Hamcrest\Number\OrderingComparison @@ -525,7 +535,7 @@ public static function emptyString(): \Hamcrest\Text\IsEmptyString /** * Matches if value is null or a zero-length string. */ - public static function isEmptyOrNullString(): Matcher + public static function isEmptyOrNullString(): \Hamcrest\Core\AnyOf { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } @@ -533,7 +543,7 @@ public static function isEmptyOrNullString(): Matcher /** * Matches if value is null or a zero-length string. */ - public static function nullOrEmptyString(): Matcher + public static function nullOrEmptyString(): \Hamcrest\Core\AnyOf { return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString(); } @@ -556,6 +566,7 @@ public static function nonEmptyString(): \Hamcrest\Text\IsEmptyString /** * Matches if value is a string equal to $string, regardless of the case. + * * @param mixed $string */ public static function equalToIgnoringCase($string): \Hamcrest\Text\IsEqualIgnoringCase @@ -565,6 +576,7 @@ public static function equalToIgnoringCase($string): \Hamcrest\Text\IsEqualIgnor /** * Matches if value is a string equal to $string, regardless of whitespace. + * * @param mixed $string */ public static function equalToIgnoringWhiteSpace($string): \Hamcrest\Text\IsEqualIgnoringWhiteSpace @@ -574,6 +586,7 @@ public static function equalToIgnoringWhiteSpace($string): \Hamcrest\Text\IsEqua /** * Matches if value is a string that matches regular expression $pattern. + * * @param mixed $pattern */ public static function matchesPattern($pattern): \Hamcrest\Text\MatchesPattern @@ -583,6 +596,7 @@ public static function matchesPattern($pattern): \Hamcrest\Text\MatchesPattern /** * Matches if value is a string that contains $substring. + * * @param mixed $substring */ public static function containsString($substring): \Hamcrest\Text\StringContains @@ -592,6 +606,7 @@ public static function containsString($substring): \Hamcrest\Text\StringContains /** * Matches if value is a string that contains $substring regardless of the case. + * * @param mixed $substring */ public static function containsStringIgnoringCase($substring): \Hamcrest\Text\StringContainsIgnoringCase @@ -602,7 +617,7 @@ public static function containsStringIgnoringCase($substring): \Hamcrest\Text\St /** * Matches if value contains $substrings in a constrained order. */ - public static function stringContainsInOrder(/* args... */): StringContainsInOrder + public static function stringContainsInOrder(/* args... */): \Hamcrest\Text\StringContainsInOrder { $args = func_get_args(); return call_user_func_array(array('\Hamcrest\Text\StringContainsInOrder', 'stringContainsInOrder'), $args); @@ -610,6 +625,7 @@ public static function stringContainsInOrder(/* args... */): StringContainsInOrd /** * Matches if value is a string that ends with $substring. + * * @param mixed $substring */ public static function endsWith($substring): \Hamcrest\Text\StringEndsWith @@ -619,6 +635,7 @@ public static function endsWith($substring): \Hamcrest\Text\StringEndsWith /** * Matches if value is a string that starts with $substring. + * * @param mixed $substring */ public static function startsWith($substring): \Hamcrest\Text\StringStartsWith @@ -742,6 +759,8 @@ public static function stringValue(): \Hamcrest\Type\IsString * Wraps $matcher with {@link Hamcrest\Core\IsEqual) * if it's not a matcher and the XPath in count() * if it's an integer. + * + * @param string $xpath * @param null|Matcher|int|mixed $matcher */ public static function hasXPath(string $xpath, $matcher = null): \Hamcrest\Xml\HasXPath From fb89dbcfba2b6fd3b3d68154f60e735c9c2ae231 Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Sat, 26 Jul 2025 11:32:25 +0200 Subject: [PATCH 11/15] remove the dump --- generator/FactoryFile.php | 1 - 1 file changed, 1 deletion(-) diff --git a/generator/FactoryFile.php b/generator/FactoryFile.php index 2df96a686..79d6a54ec 100644 --- a/generator/FactoryFile.php +++ b/generator/FactoryFile.php @@ -93,7 +93,6 @@ public function generateReturnType(FactoryMethod $method): string $returnType = $call->getMethod()->getReturnType(); if (!$returnType) { - dump($method); throw new \Exception('The first calls FactoryMethod cannot be used to determine the return type. Method: '.$method->getName()); } From 7e813dd0185f4edad17d07348071dd51297360a6 Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Tue, 29 Jul 2025 16:07:57 +0200 Subject: [PATCH 12/15] revert wrong change in composer.json --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 32ee93606..4a08fda8b 100644 --- a/composer.json +++ b/composer.json @@ -24,8 +24,7 @@ "phpunit/php-file-iterator": "^1.4 || ^2.0 || ^3.0", "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0", "phpstan/phpstan": "^2.1", - "phpstan/phpstan-phpunit": "^2.0", - "symfony/var-dumper": "^5.4" + "phpstan/phpstan-phpunit": "^2.0" }, "replace": { From a95717143523565579f28988fa7e3f7f1cf4a33e Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Wed, 30 Jul 2025 12:29:12 +0200 Subject: [PATCH 13/15] add PHPStan to the CI in GitHub Actions --- .github/workflows/static-analysis.yml | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/static-analysis.yml diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 000000000..3cd877239 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,39 @@ +name: static-analysis + +on: + push: + pull_request: + +jobs: + static_analysis: + + runs-on: ubuntu-latest + strategy: + matrix: + php: + - '7.4' + - '8.0' + - '8.1' + - '8.2' + - '8.3' + - '8.4' + + name: PHP ${{ matrix.php }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: curl + tools: composer:v2 + coverage: none + + - name: Install PHP dependencies + run: composer update --prefer-dist --no-interaction --no-progress + + - name: Run PHPStan + run: vendor/bin/phpstan analyze \ No newline at end of file From 27146b1129254260f0a74608b2842afaaea00ed7 Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Thu, 31 Jul 2025 06:41:34 +0200 Subject: [PATCH 14/15] run only on php 8.0 --- .github/workflows/static-analysis.yml | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 3cd877239..c1efd9ceb 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -8,17 +8,6 @@ jobs: static_analysis: runs-on: ubuntu-latest - strategy: - matrix: - php: - - '7.4' - - '8.0' - - '8.1' - - '8.2' - - '8.3' - - '8.4' - - name: PHP ${{ matrix.php }} steps: - name: Checkout code @@ -27,7 +16,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php }} + php-version: '8.0' extensions: curl tools: composer:v2 coverage: none @@ -36,4 +25,4 @@ jobs: run: composer update --prefer-dist --no-interaction --no-progress - name: Run PHPStan - run: vendor/bin/phpstan analyze \ No newline at end of file + run: vendor/bin/phpstan analyze From 96a6a10d373b4b45488a889a1f06252be1e15087 Mon Sep 17 00:00:00 2001 From: Philipp Scheit Date: Thu, 31 Jul 2025 10:57:33 +0200 Subject: [PATCH 15/15] move CI configuration into one file and add the static analysis there --- .github/workflows/{tests.yml => ci.yml} | 28 +++++++++++++++++++++---- .github/workflows/static-analysis.yml | 28 ------------------------- 2 files changed, 24 insertions(+), 32 deletions(-) rename .github/workflows/{tests.yml => ci.yml} (55%) delete mode 100644 .github/workflows/static-analysis.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/ci.yml similarity index 55% rename from .github/workflows/tests.yml rename to .github/workflows/ci.yml index 90e806713..0d64c5f58 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,34 @@ -name: tests +name: ci on: push: pull_request: jobs: - tests: + static_analysis: + name: Static analysis + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + extensions: curl + tools: composer:v2 + coverage: none + + - name: Install PHP dependencies + run: composer update --prefer-dist --no-interaction --no-progress + + - name: Run PHPStan + run: vendor/bin/phpstan analyze + + tests: + name: Tests ${{ matrix.php }} runs-on: ubuntu-latest strategy: matrix: @@ -18,8 +40,6 @@ jobs: - '8.3' - '8.4' - name: PHP ${{ matrix.php }} - steps: - name: Checkout code uses: actions/checkout@v2 diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml deleted file mode 100644 index c1efd9ceb..000000000 --- a/.github/workflows/static-analysis.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: static-analysis - -on: - push: - pull_request: - -jobs: - static_analysis: - - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - extensions: curl - tools: composer:v2 - coverage: none - - - name: Install PHP dependencies - run: composer update --prefer-dist --no-interaction --no-progress - - - name: Run PHPStan - run: vendor/bin/phpstan analyze