diff --git a/library/Mockery/Matcher/AndAnyOtherArgs.php b/library/Mockery/Matcher/AndAnyOtherArgs.php index b2b074821..f4a698e26 100644 --- a/library/Mockery/Matcher/AndAnyOtherArgs.php +++ b/library/Mockery/Matcher/AndAnyOtherArgs.php @@ -4,8 +4,8 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; @@ -13,23 +13,26 @@ class AndAnyOtherArgs extends MatcherAbstract { /** - * Check if the actual value matches the expected. + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - return true; + return ''; } /** - * Return a string representation of this Matcher + * Check if the actual value matches the expected. * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + return true; } } diff --git a/library/Mockery/Matcher/Any.php b/library/Mockery/Matcher/Any.php index 2607a0e5b..5bb4b2f04 100644 --- a/library/Mockery/Matcher/Any.php +++ b/library/Mockery/Matcher/Any.php @@ -4,8 +4,8 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; @@ -13,23 +13,26 @@ class Any extends MatcherAbstract { /** - * Check if the actual value matches the expected. + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - return true; + return ''; } /** - * Return a string representation of this Matcher + * Check if the actual value matches the expected. * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + return true; } } diff --git a/library/Mockery/Matcher/AnyArgs.php b/library/Mockery/Matcher/AnyArgs.php index 7dc665ecd..0e1ce8c6a 100644 --- a/library/Mockery/Matcher/AnyArgs.php +++ b/library/Mockery/Matcher/AnyArgs.php @@ -4,27 +4,28 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; class AnyArgs extends MatcherAbstract implements ArgumentListMatcher { - /** - * @inheritdoc - */ - public function match(&$actual) + public function __toString() { - return true; + return ''; } /** - * @inheritdoc + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + return true; } } diff --git a/library/Mockery/Matcher/AnyOf.php b/library/Mockery/Matcher/AnyOf.php index aafcec99a..425dcae3f 100644 --- a/library/Mockery/Matcher/AnyOf.php +++ b/library/Mockery/Matcher/AnyOf.php @@ -4,33 +4,38 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use function in_array; + class AnyOf extends MatcherAbstract { /** - * Check if the actual value does not match the expected (in this - * case it's specifically NOT expected). + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - return in_array($actual, $this->_expected, true); + return ''; } /** - * Return a string representation of this Matcher + * Check if the actual value does not match the expected (in this + * case it's specifically NOT expected). * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + return in_array($actual, $this->_expected, true); } } diff --git a/library/Mockery/Matcher/ArgumentListMatcher.php b/library/Mockery/Matcher/ArgumentListMatcher.php index b00e5d08f..56e58f693 100644 --- a/library/Mockery/Matcher/ArgumentListMatcher.php +++ b/library/Mockery/Matcher/ArgumentListMatcher.php @@ -4,8 +4,8 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; diff --git a/library/Mockery/Matcher/Closure.php b/library/Mockery/Matcher/Closure.php index 4f50c9ebb..46c834cd5 100644 --- a/library/Mockery/Matcher/Closure.php +++ b/library/Mockery/Matcher/Closure.php @@ -4,8 +4,8 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; @@ -13,25 +13,26 @@ class Closure extends MatcherAbstract { /** - * Check if the actual value matches the expected. + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - $closure = $this->_expected; - $result = $closure($actual); - return $result === true; + return ''; } /** - * Return a string representation of this Matcher + * Check if the actual value matches the expected. * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + return ($this->_expected)($actual) === true; } } diff --git a/library/Mockery/Matcher/Contains.php b/library/Mockery/Matcher/Contains.php index a252515d7..0741487b6 100644 --- a/library/Mockery/Matcher/Contains.php +++ b/library/Mockery/Matcher/Contains.php @@ -4,18 +4,40 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use function array_values; +use function implode; + class Contains extends MatcherAbstract { + /** + * Return a string representation of this Matcher + * + * @return string + */ + public function __toString() + { + $return = '_expected as $v) { + $elements[] = (string) $v; + } + $return .= implode(', ', $elements) . ']>'; + return $return; + } + /** * Check if the actual value matches the expected. * - * @param mixed $actual + * @template TMixed + * + * @param TMixed $actual + * * @return bool */ public function match(&$actual) @@ -35,20 +57,4 @@ public function match(&$actual) } return true; } - - /** - * Return a string representation of this Matcher - * - * @return string - */ - public function __toString() - { - $return = '_expected as $v) { - $elements[] = (string) $v; - } - $return .= implode(', ', $elements) . ']>'; - return $return; - } } diff --git a/library/Mockery/Matcher/Ducktype.php b/library/Mockery/Matcher/Ducktype.php index 560741773..90f5947be 100644 --- a/library/Mockery/Matcher/Ducktype.php +++ b/library/Mockery/Matcher/Ducktype.php @@ -4,40 +4,47 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use function implode; +use function is_object; +use function method_exists; + class Ducktype extends MatcherAbstract { + /** + * Return a string representation of this Matcher + * + * @return string + */ + public function __toString() + { + return '_expected) . ']>'; + } + /** * Check if the actual value matches the expected. * - * @param mixed $actual + * @template TMixed + * + * @param TMixed $actual + * * @return bool */ public function match(&$actual) { - if (!is_object($actual)) { + if (! is_object($actual)) { return false; } foreach ($this->_expected as $method) { - if (!method_exists($actual, $method)) { + if (! method_exists($actual, $method)) { return false; } } return true; } - - /** - * Return a string representation of this Matcher - * - * @return string - */ - public function __toString() - { - return '_expected) . ']>'; - } } diff --git a/library/Mockery/Matcher/HasKey.php b/library/Mockery/Matcher/HasKey.php index bb7e08d4f..2a278a378 100644 --- a/library/Mockery/Matcher/HasKey.php +++ b/library/Mockery/Matcher/HasKey.php @@ -4,36 +4,44 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use ArrayAccess; + +use function array_key_exists; +use function is_array; + class HasKey extends MatcherAbstract { /** - * Check if the actual value matches the expected. + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - if (!is_array($actual) && !$actual instanceof \ArrayAccess) { - return false; - } - - return array_key_exists($this->_expected, (array)$actual); + return "_expected}]>"; } /** - * Return a string representation of this Matcher + * Check if the actual value matches the expected. * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return "_expected]>"; + if (! is_array($actual) && ! $actual instanceof ArrayAccess) { + return false; + } + + return array_key_exists($this->_expected, (array) $actual); } } diff --git a/library/Mockery/Matcher/HasValue.php b/library/Mockery/Matcher/HasValue.php index 98537f2eb..8d37a5f74 100644 --- a/library/Mockery/Matcher/HasValue.php +++ b/library/Mockery/Matcher/HasValue.php @@ -4,36 +4,44 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use ArrayAccess; + +use function in_array; +use function is_array; + class HasValue extends MatcherAbstract { /** - * Check if the actual value matches the expected. + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - if (!is_array($actual) && !$actual instanceof \ArrayAccess) { - return false; - } - - return in_array($this->_expected, (array)$actual); + return '_expected . ']>'; } /** - * Return a string representation of this Matcher + * Check if the actual value matches the expected. * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return '_expected . ']>'; + if (! is_array($actual) && ! $actual instanceof ArrayAccess) { + return false; + } + + return in_array($this->_expected, (array) $actual, true); } } diff --git a/library/Mockery/Matcher/IsEqual.php b/library/Mockery/Matcher/IsEqual.php index d4c19a2b8..72d1a02f2 100644 --- a/library/Mockery/Matcher/IsEqual.php +++ b/library/Mockery/Matcher/IsEqual.php @@ -4,8 +4,8 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; @@ -13,23 +13,26 @@ class IsEqual extends MatcherAbstract { /** - * Check if the actual value matches the expected. + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - return $this->_expected == $actual; + return ''; } /** - * Return a string representation of this Matcher + * Check if the actual value matches the expected. * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + return $this->_expected == $actual; } } diff --git a/library/Mockery/Matcher/IsSame.php b/library/Mockery/Matcher/IsSame.php index 70d452fb4..7671448e4 100644 --- a/library/Mockery/Matcher/IsSame.php +++ b/library/Mockery/Matcher/IsSame.php @@ -4,8 +4,8 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; @@ -13,23 +13,26 @@ class IsSame extends MatcherAbstract { /** - * Check if the actual value matches the expected. + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - return $this->_expected === $actual; + return ''; } /** - * Return a string representation of this Matcher + * Check if the actual value matches the expected. * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + return $this->_expected === $actual; } } diff --git a/library/Mockery/Matcher/MatcherAbstract.php b/library/Mockery/Matcher/MatcherAbstract.php index dea9dc907..813950a5d 100644 --- a/library/Mockery/Matcher/MatcherAbstract.php +++ b/library/Mockery/Matcher/MatcherAbstract.php @@ -4,8 +4,8 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; @@ -19,14 +19,18 @@ abstract class MatcherAbstract implements MatcherInterface /** * The expected value (or part thereof) * - * @var mixed + * @template TExpected + * + * @var TExpected */ protected $_expected = null; /** * Set the expected value * - * @param mixed $expected + * @template TExpected + * + * @param TExpected $expected */ public function __construct($expected = null) { diff --git a/library/Mockery/Matcher/MatcherInterface.php b/library/Mockery/Matcher/MatcherInterface.php index 5de77759d..19154eab2 100644 --- a/library/Mockery/Matcher/MatcherInterface.php +++ b/library/Mockery/Matcher/MatcherInterface.php @@ -6,28 +6,31 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; interface MatcherInterface { + /** + * Return a string representation of this Matcher + * + * @return string + */ + public function __toString(); + /** * Check if the actual value matches the expected. * Actual passed by reference to preserve reference trail (where applicable) * back to the original method parameter. * - * @param mixed $actual + * @template TMixed + * + * @param TMixed $actual + * * @return bool */ public function match(&$actual); - - /** - * Return a string representation of this Matcher - * - * @return string - */ - public function __toString(); } diff --git a/library/Mockery/Matcher/MultiArgumentClosure.php b/library/Mockery/Matcher/MultiArgumentClosure.php index d20c4be0a..f2ed6ed47 100644 --- a/library/Mockery/Matcher/MultiArgumentClosure.php +++ b/library/Mockery/Matcher/MultiArgumentClosure.php @@ -4,35 +4,40 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use function call_user_func_array; + class MultiArgumentClosure extends MatcherAbstract implements ArgumentListMatcher { /** - * Check if the actual value matches the expected. - * Actual passed by reference to preserve reference trail (where applicable) - * back to the original method parameter. + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - $closure = $this->_expected; - return true === call_user_func_array($closure, $actual); + return ''; } /** - * Return a string representation of this Matcher + * Check if the actual value matches the expected. + * Actual passed by reference to preserve reference trail (where applicable) + * back to the original method parameter. * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + $closure = $this->_expected; + return call_user_func_array($closure, $actual) === true; } } diff --git a/library/Mockery/Matcher/MustBe.php b/library/Mockery/Matcher/MustBe.php index 89ed523d2..d365bc70a 100644 --- a/library/Mockery/Matcher/MustBe.php +++ b/library/Mockery/Matcher/MustBe.php @@ -4,39 +4,44 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use function is_object; + /** * @deprecated 2.0 Due to ambiguity, use PHPUnit equivalents */ class MustBe extends MatcherAbstract { + /** + * Return a string representation of this Matcher + * + * @return string + */ + public function __toString() + { + return ''; + } + /** * Check if the actual value matches the expected. * - * @param mixed $actual + * @template TMixed + * + * @param TMixed $actual + * * @return bool */ public function match(&$actual) { - if (!is_object($actual)) { + if (! is_object($actual)) { return $this->_expected === $actual; } return $this->_expected == $actual; } - - /** - * Return a string representation of this Matcher - * - * @return string - */ - public function __toString() - { - return ''; - } } diff --git a/library/Mockery/Matcher/NoArgs.php b/library/Mockery/Matcher/NoArgs.php index 4b6554095..37438f13b 100644 --- a/library/Mockery/Matcher/NoArgs.php +++ b/library/Mockery/Matcher/NoArgs.php @@ -4,27 +4,30 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use function count; + class NoArgs extends MatcherAbstract implements ArgumentListMatcher { - /** - * @inheritdoc - */ - public function match(&$actual) + public function __toString() { - return count($actual) == 0; + return ''; } /** - * @inheritdoc + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + return count($actual) === 0; } } diff --git a/library/Mockery/Matcher/Not.php b/library/Mockery/Matcher/Not.php index 8149165ed..133007eb0 100644 --- a/library/Mockery/Matcher/Not.php +++ b/library/Mockery/Matcher/Not.php @@ -4,8 +4,8 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; @@ -13,24 +13,27 @@ class Not extends MatcherAbstract { /** - * Check if the actual value does not match the expected (in this - * case it's specifically NOT expected). + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - return $actual !== $this->_expected; + return ''; } /** - * Return a string representation of this Matcher + * Check if the actual value does not match the expected (in this + * case it's specifically NOT expected). * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + return $actual !== $this->_expected; } } diff --git a/library/Mockery/Matcher/NotAnyOf.php b/library/Mockery/Matcher/NotAnyOf.php index a9ffb08fb..274ed39bb 100644 --- a/library/Mockery/Matcher/NotAnyOf.php +++ b/library/Mockery/Matcher/NotAnyOf.php @@ -4,19 +4,32 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; class NotAnyOf extends MatcherAbstract { + /** + * Return a string representation of this Matcher + * + * @return string + */ + public function __toString() + { + return ''; + } + /** * Check if the actual value does not match the expected (in this * case it's specifically NOT expected). * - * @param mixed $actual + * @template TMixed + * + * @param TMixed $actual + * * @return bool */ public function match(&$actual) @@ -28,14 +41,4 @@ public function match(&$actual) } return true; } - - /** - * Return a string representation of this Matcher - * - * @return string - */ - public function __toString() - { - return ''; - } } diff --git a/library/Mockery/Matcher/Pattern.php b/library/Mockery/Matcher/Pattern.php index 864cbe213..b2e84dfaa 100644 --- a/library/Mockery/Matcher/Pattern.php +++ b/library/Mockery/Matcher/Pattern.php @@ -4,32 +4,37 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use function preg_match; + class Pattern extends MatcherAbstract { /** - * Check if the actual value matches the expected pattern. + * Return a string representation of this Matcher * - * @param mixed $actual - * @return bool + * @return string */ - public function match(&$actual) + public function __toString() { - return preg_match($this->_expected, (string) $actual) >= 1; + return ''; } /** - * Return a string representation of this Matcher + * Check if the actual value matches the expected pattern. * - * @return string + * @template TMixed + * + * @param TMixed $actual + * + * @return bool */ - public function __toString() + public function match(&$actual) { - return ''; + return preg_match($this->_expected, (string) $actual) >= 1; } } diff --git a/library/Mockery/Matcher/Subset.php b/library/Mockery/Matcher/Subset.php index 3a705c5f0..4f0164375 100644 --- a/library/Mockery/Matcher/Subset.php +++ b/library/Mockery/Matcher/Subset.php @@ -4,15 +4,20 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use function array_replace_recursive; +use function implode; +use function is_array; + class Subset extends MatcherAbstract { private $expected; + private $strict = true; /** @@ -26,34 +31,27 @@ public function __construct(array $expected, $strict = true) } /** - * @param array $expected Expected subset of data - * - * @return Subset - */ - public static function strict(array $expected) - { - return new static($expected, true); - } - - /** - * @param array $expected Expected subset of data + * Return a string representation of this Matcher * - * @return Subset + * @return string */ - public static function loose(array $expected) + public function __toString() { - return new static($expected, false); + return 'formatArray($this->expected) . '>'; } /** * Check if the actual value matches the expected. * - * @param mixed $actual + * @template TMixed + * + * @param TMixed $actual + * * @return bool */ public function match(&$actual) { - if (!is_array($actual)) { + if (! is_array($actual)) { return false; } @@ -64,20 +62,9 @@ public function match(&$actual) return $actual == array_replace_recursive($actual, $this->expected); } - /** - * Return a string representation of this Matcher - * - * @return string - */ - public function __toString() - { - return 'formatArray($this->expected) . ">"; - } - /** * Recursively format an array into the string representation for this matcher * - * @param array $array * @return string */ protected function formatArray(array $array) @@ -86,6 +73,26 @@ protected function formatArray(array $array) foreach ($array as $k => $v) { $elements[] = $k . '=' . (is_array($v) ? $this->formatArray($v) : (string) $v); } - return "[" . implode(", ", $elements) . "]"; + return '[' . implode(', ', $elements) . ']'; + } + + /** + * @param array $expected Expected subset of data + * + * @return Subset + */ + public static function loose(array $expected) + { + return new static($expected, false); + } + + /** + * @param array $expected Expected subset of data + * + * @return Subset + */ + public static function strict(array $expected) + { + return new static($expected, true); } } diff --git a/library/Mockery/Matcher/Type.php b/library/Mockery/Matcher/Type.php index d445bab8e..7d2f796b9 100644 --- a/library/Mockery/Matcher/Type.php +++ b/library/Mockery/Matcher/Type.php @@ -4,43 +4,60 @@ * Mockery (https://docs.mockery.io/) * * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md - * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License - * @link https://github.com/mockery/mockery for the canonical source repository + * @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License + * @link https://github.com/mockery/mockery for the canonical source repository */ namespace Mockery\Matcher; +use function class_exists; +use function function_exists; +use function interface_exists; +use function is_string; +use function strtolower; +use function ucfirst; + class Type extends MatcherAbstract { + /** + * Return a string representation of this Matcher + * + * @return string + */ + public function __toString() + { + return '<' . ucfirst($this->_expected) . '>'; + } + /** * Check if the actual value matches the expected. * - * @param mixed $actual + * @template TMixed + * + * @param TMixed $actual + * * @return bool */ public function match(&$actual) { - if ($this->_expected == 'real') { + if ($this->_expected === 'real') { $function = 'is_float'; } else { $function = 'is_' . strtolower($this->_expected); } + if (function_exists($function)) { return $function($actual); - } elseif (is_string($this->_expected) - && (class_exists($this->_expected) || interface_exists($this->_expected))) { + } + + if (! is_string($this->_expected)) { + return false; + } + + if (class_exists($this->_expected) || interface_exists($this->_expected)) { return $actual instanceof $this->_expected; } - return false; - } - /** - * Return a string representation of this Matcher - * - * @return string - */ - public function __toString() - { - return '<' . ucfirst($this->_expected) . '>'; + return false; } }