From 7404563ddbe44fd9b2f11d5906af942efb5d87bc Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 3 Jan 2014 15:50:10 -0600 Subject: [PATCH 1/2] [zendframework/zf2#5364] Incorporate feedback --- src/Guard/ArrayOrTraversableGuardTrait.php | 4 +++- src/Guard/GuardUtils.php | 6 ++++-- src/Guard/NullGuardTrait.php | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Guard/ArrayOrTraversableGuardTrait.php b/src/Guard/ArrayOrTraversableGuardTrait.php index be08883b2..86e9f8bbf 100644 --- a/src/Guard/ArrayOrTraversableGuardTrait.php +++ b/src/Guard/ArrayOrTraversableGuardTrait.php @@ -9,6 +9,8 @@ namespace Zend\Stdlib\Guard; +use Traversable; + /** * Provide a guard method for array or Traversable data */ @@ -28,7 +30,7 @@ protected function guardForArrayOrTraversable( $dataName = 'Argument', $exceptionClass = 'Zend\Stdlib\Exception\InvalidArgumentException' ) { - if (!is_array($data) && !($data instanceof \Traversable)) { + if (!is_array($data) && !($data instanceof Traversable)) { $message = sprintf( "%s must be an array or Traversable, [%s] given", $dataName, diff --git a/src/Guard/GuardUtils.php b/src/Guard/GuardUtils.php index 2ffc819b2..243dd8bc8 100644 --- a/src/Guard/GuardUtils.php +++ b/src/Guard/GuardUtils.php @@ -9,6 +9,8 @@ namespace Zend\Stdlib\Guard; +use Traversable; + /** * Static guard helper class * @@ -35,7 +37,7 @@ public static function guardForArrayOrTraversable( $dataName = 'Argument', $exceptionClass = self::DEFAULT_EXCEPTION_CLASS ) { - if (!is_array($data) && !($data instanceof \Traversable)) { + if (!is_array($data) && !($data instanceof Traversable)) { $message = sprintf( '%s must be an array or Traversable, [%s] given', $dataName, @@ -77,7 +79,7 @@ public static function guardAgainstNull( $dataName = 'Argument', $exceptionClass = self::DEFAULT_EXCEPTION_CLASS ) { - if (is_null($data)) { + if (null === $data) { $message = sprintf('%s cannot be null', $dataName); throw new $exceptionClass($message); } diff --git a/src/Guard/NullGuardTrait.php b/src/Guard/NullGuardTrait.php index 882c5a0f1..dcd326e96 100644 --- a/src/Guard/NullGuardTrait.php +++ b/src/Guard/NullGuardTrait.php @@ -28,7 +28,7 @@ protected function guardAgainstNull( $dataName = 'Argument', $exceptionClass = 'Zend\Stdlib\Exception\InvalidArgumentException' ) { - if (is_null($data)) { + if (null === $data) { $message = sprintf('%s cannot be null', $dataName); throw new $exceptionClass($message); } From 1962fd44b73cdcc1447c2bfd014e573967dbb8f6 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 3 Jan 2014 15:53:45 -0600 Subject: [PATCH 2/2] [zendframework/zf2#5364] CS fixes - Updated copyright year - Removed unneeded annotations - Removed empty lines at start and finish of classes --- src/Guard/AllGuardsTrait.php | 4 +--- src/Guard/ArrayOrTraversableGuardTrait.php | 4 +--- src/Guard/EmptyGuardTrait.php | 4 +--- src/Guard/GuardUtils.php | 5 +---- src/Guard/NullGuardTrait.php | 4 +--- test/Guard/ArrayOrTraversableGuardTraitTest.php | 5 +---- test/Guard/EmptyGuardTraitTest.php | 5 +---- test/Guard/GuardUtilsTest.php | 5 +---- test/Guard/NullGuardTraitTest.php | 5 +---- test/TestAsset/GuardedObject.php | 7 +------ 10 files changed, 10 insertions(+), 38 deletions(-) diff --git a/src/Guard/AllGuardsTrait.php b/src/Guard/AllGuardsTrait.php index f2f62b8b8..60b341288 100644 --- a/src/Guard/AllGuardsTrait.php +++ b/src/Guard/AllGuardsTrait.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,9 +14,7 @@ */ trait AllGuardsTrait { - use ArrayOrTraversableGuardTrait; use EmptyGuardTrait; use NullGuardTrait; - } diff --git a/src/Guard/ArrayOrTraversableGuardTrait.php b/src/Guard/ArrayOrTraversableGuardTrait.php index 86e9f8bbf..84e846ea3 100644 --- a/src/Guard/ArrayOrTraversableGuardTrait.php +++ b/src/Guard/ArrayOrTraversableGuardTrait.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -16,7 +16,6 @@ */ trait ArrayOrTraversableGuardTrait { - /** * Verifies that the data is an array or Traversable * @@ -39,5 +38,4 @@ protected function guardForArrayOrTraversable( throw new $exceptionClass($message); } } - } diff --git a/src/Guard/EmptyGuardTrait.php b/src/Guard/EmptyGuardTrait.php index 53117a259..72f5b3459 100644 --- a/src/Guard/EmptyGuardTrait.php +++ b/src/Guard/EmptyGuardTrait.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,7 +14,6 @@ */ trait EmptyGuardTrait { - /** * Verify that the data is not empty * @@ -33,5 +32,4 @@ protected function guardAgainstEmpty( throw new $exceptionClass($message); } } - } diff --git a/src/Guard/GuardUtils.php b/src/Guard/GuardUtils.php index 243dd8bc8..31c446410 100644 --- a/src/Guard/GuardUtils.php +++ b/src/Guard/GuardUtils.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -20,10 +20,8 @@ */ abstract class GuardUtils { - const DEFAULT_EXCEPTION_CLASS = 'Zend\Stdlib\Exception\InvalidArgumentException'; - /** * Verifies that the data is an array or Traversable * @@ -84,5 +82,4 @@ public static function guardAgainstNull( throw new $exceptionClass($message); } } - } diff --git a/src/Guard/NullGuardTrait.php b/src/Guard/NullGuardTrait.php index dcd326e96..e7aadb150 100644 --- a/src/Guard/NullGuardTrait.php +++ b/src/Guard/NullGuardTrait.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,7 +14,6 @@ */ trait NullGuardTrait { - /** * Verify that the data is not null * @@ -33,5 +32,4 @@ protected function guardAgainstNull( throw new $exceptionClass($message); } } - } diff --git a/test/Guard/ArrayOrTraversableGuardTraitTest.php b/test/Guard/ArrayOrTraversableGuardTraitTest.php index c06fb4add..599a1f02a 100644 --- a/test/Guard/ArrayOrTraversableGuardTraitTest.php +++ b/test/Guard/ArrayOrTraversableGuardTraitTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -15,12 +15,10 @@ /** * @requires PHP 5.4 - * @group Zend_StdLib_Guard * @covers Zend\Stdlib\Guard\ArrayOrTraversableGuardTrait */ class ArrayOrTraversableGuardTraitTest extends TestCase { - public function setUp() { if (version_compare(PHP_VERSION, '5.4.0', '<')) { @@ -50,5 +48,4 @@ public function testGuardForArrayOrTraversableAllowsTraversable() $traversable = new ArrayObject; $this->assertNull($object->setArrayOrTraversable($traversable)); } - } diff --git a/test/Guard/EmptyGuardTraitTest.php b/test/Guard/EmptyGuardTraitTest.php index 9e5a5cb36..618075480 100644 --- a/test/Guard/EmptyGuardTraitTest.php +++ b/test/Guard/EmptyGuardTraitTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,12 +14,10 @@ /** * @requires PHP 5.4 - * @group Zend_StdLib_Guard * @covers Zend\Stdlib\Guard\EmptyGuardTrait */ class EmptyGuardTraitTest extends TestCase { - public function setUp() { if (version_compare(PHP_VERSION, '5.4.0', '<')) { @@ -42,5 +40,4 @@ public function testGuardAgainstEmptyAllowsNonEmptyString() $object = new GuardedObject; $this->assertNull($object->setNotEmpty('foo')); } - } diff --git a/test/Guard/GuardUtilsTest.php b/test/Guard/GuardUtilsTest.php index 6d36c708e..7d381707c 100644 --- a/test/Guard/GuardUtilsTest.php +++ b/test/Guard/GuardUtilsTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,12 +14,10 @@ use Zend\Stdlib\ArrayObject; /** - * @group Zend_StdLib_Guard * @covers Zend\Stdlib\Guard\GuardUtils */ class GuardUtilsTest extends TestCase { - public function testGuardForArrayOrTraversableThrowsException() { $this->setExpectedException( @@ -67,5 +65,4 @@ public function testGuardAgainstNullAllowsNonNull() { $this->assertNull(GuardUtils::guardAgainstNull('foo')); } - } diff --git a/test/Guard/NullGuardTraitTest.php b/test/Guard/NullGuardTraitTest.php index 555ceaf5e..658bbe19c 100644 --- a/test/Guard/NullGuardTraitTest.php +++ b/test/Guard/NullGuardTraitTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,12 +14,10 @@ /** * @requires PHP 5.4 - * @group Zend_StdLib_Guard * @covers Zend\Stdlib\Guard\NullGuardTrait */ class NullGuardTraitTest extends TestCase { - public function setUp() { if (version_compare(PHP_VERSION, '5.4.0', '<')) { @@ -42,5 +40,4 @@ public function testGuardAgainstNullAllowsNonNull() $object = new GuardedObject; $this->assertNull($object->setNotNull('foo')); } - } diff --git a/test/TestAsset/GuardedObject.php b/test/TestAsset/GuardedObject.php index 485df2bca..4eeddf115 100644 --- a/test/TestAsset/GuardedObject.php +++ b/test/TestAsset/GuardedObject.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -11,12 +11,8 @@ use Zend\Stdlib\Guard\AllGuardsTrait; -/** - * @group Zend_Stdlib_Guard - */ class GuardedObject { - use AllGuardsTrait; public function setArrayOrTraversable($value) @@ -33,5 +29,4 @@ public function setNotNull($value) { $this->guardAgainstNull($value); } - }