From 904cafffc5ac033c67d8f9a63c4ce8ef8cff6e79 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Thu, 8 Mar 2018 18:39:10 +0200 Subject: [PATCH] Drop PHP 7.1 support --- .travis.yml | 3 +- README.md | 2 +- composer.json | 4 +- src/Bucket.php | 8 +++- src/ObjectBiMap.php | 20 ++------- src/ObjectMap.php | 27 ++++-------- src/ObjectMapInterface.php | 8 ++-- src/ObjectTypeHintTrait.php | 29 ------------- tests/AbstractObjectMapInterfaceTest.php | 55 ------------------------ 9 files changed, 27 insertions(+), 129 deletions(-) delete mode 100644 src/ObjectTypeHintTrait.php diff --git a/.travis.yml b/.travis.yml index 707dd29..b1a3dad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ sudo: false language: php php: - - 7.1 - 7.2 - nightly @@ -17,7 +16,7 @@ matrix: env: - PHP_REF_VERSION=master - - PHP_REF_VERSION=v0.5.0 + - PHP_REF_VERSION=v0.6.0 before_install: - sh install_php_ref_ext.sh ${PHP_REF_VERSION} diff --git a/README.md b/README.md index 9671607..49fb900 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ If you like my work and want to show your appreciation, please consider supporti ## Requirements - - PHP >= 7.1 + - PHP >= 7.2 - (optional, required only for maps weak behavior) [php-ref][php-ref-ext] extension diff --git a/composer.json b/composer.json index f2aa96a..478ac7e 100644 --- a/composer.json +++ b/composer.json @@ -19,14 +19,14 @@ } ], "require": { - "php": "~7.0" + "php": "~7.2" }, "suggest": { "ext-ref": "Needed to support weak map variations" }, "require-dev": { "phpunit/phpunit": "^6.4", - "pinepain/php-ref-stubs": "~0.4.1" + "pinepain/php-ref-stubs": "~0.6.0" }, "autoload": { "psr-4": { diff --git a/src/Bucket.php b/src/Bucket.php index 7d6b1c4..82d7ed8 100644 --- a/src/Bucket.php +++ b/src/Bucket.php @@ -19,14 +19,20 @@ */ final class Bucket { + /** + * @var object + */ public $key; + /** + * @var object + */ public $value; /** * @param object $key * @param object $value */ - public function __construct($key, $value) + public function __construct(object $key, object $value) { $this->key = $key; $this->value = $value; diff --git a/src/ObjectBiMap.php b/src/ObjectBiMap.php index c4f4ae1..fe428dc 100644 --- a/src/ObjectBiMap.php +++ b/src/ObjectBiMap.php @@ -21,8 +21,6 @@ class ObjectBiMap implements ObjectBiMapInterface { - use ObjectTypeHintTrait; - protected $behavior = self::DEFAULT; /** @@ -84,16 +82,12 @@ public function values(): ObjectBiMapInterface /** * {@inheritdoc} */ - public function put($key, $value) + public function put(object $key, object $value) { - $this->assertObject($key, 'Key'); - if ($this->keys->has($key)) { throw new OverflowException('Value with such key already exists'); } - $this->assertObject($value, 'Value'); - if ($this->values->has($value)) { // UNEXPECTED throw new OverflowException('Key with such value already exists'); @@ -106,10 +100,8 @@ public function put($key, $value) /** * {@inheritdoc} */ - public function get($key) + public function get(object $key) { - $this->assertObject($key, 'Key'); - return $this->keys->get($key); } @@ -117,20 +109,16 @@ public function get($key) * {@inheritdoc} */ - public function has($key): bool + public function has(object $key): bool { - $this->assertObject($key, 'Key'); - return $this->keys->has($key); } /** * {@inheritdoc} */ - public function remove($key) + public function remove(object $key) { - $this->assertObject($key, 'Key'); - if (!$this->keys->has($key)) { throw new OutOfBoundsException('Value with such key not found'); } diff --git a/src/ObjectMap.php b/src/ObjectMap.php index 519c548..ec9d0a2 100644 --- a/src/ObjectMap.php +++ b/src/ObjectMap.php @@ -23,8 +23,6 @@ class ObjectMap implements ObjectMapInterface { - use ObjectTypeHintTrait; - protected $behavior = self::DEFAULT; /** @@ -43,11 +41,8 @@ public function __construct(int $behavior = self::DEFAULT) /** * {@inheritdoc} */ - public function put($key, $value) + public function put(object $key, object $value) { - $this->assertObject($key, 'Key'); - $this->assertObject($value, 'Value'); // while we may associate non-object value, for interface compatibility we don't do that - $hash = $this->getHash($key); if (isset($this->keys[$hash])) { @@ -62,10 +57,8 @@ public function put($key, $value) /** * {@inheritdoc} */ - public function get($key) + public function get(object $key) { - $this->assertObject($key, 'Key'); - $hash = $this->getHash($key); if (!isset($this->keys[$hash])) { @@ -80,10 +73,8 @@ public function get($key) /** * {@inheritdoc} */ - public function has($key): bool + public function has(object $key): bool { - $this->assertObject($key, 'Key'); - $hash = $this->getHash($key); return isset($this->keys[$hash]); @@ -92,10 +83,8 @@ public function has($key): bool /** * {@inheritdoc} */ - public function remove($key) + public function remove(object $key) { - $this->assertObject($key, 'Key'); - $hash = $this->getHash($key); if (!isset($this->keys[$hash])) { @@ -130,7 +119,7 @@ public function clear() * * @return string */ - protected function getHash($value) + protected function getHash(object $value) { return spl_object_hash($value); } @@ -152,7 +141,7 @@ protected function doRemove(string $hash) * * @return Bucket */ - protected function createBucket($key, $value, string $hash): Bucket + protected function createBucket(object $key, object $value, string $hash): Bucket { if ($this->behavior & self::WEAK_KEY) { $key = $this->createReference($key, $hash); @@ -182,12 +171,12 @@ protected function fetchBucketValue(Bucket $bucket) } /** - * @param $obj + * @param object $obj * @param string $hash * * @return WeakReference */ - protected function createReference($obj, string $hash): WeakReference + protected function createReference(object $obj, string $hash): WeakReference { return new WeakReference($obj, function () use ($hash) { $this->doRemove($hash); diff --git a/src/ObjectMapInterface.php b/src/ObjectMapInterface.php index be7f937..2072ea4 100644 --- a/src/ObjectMapInterface.php +++ b/src/ObjectMapInterface.php @@ -33,7 +33,7 @@ interface ObjectMapInterface extends Countable * @throws OverflowException * @return void */ - public function put($key, $value); + public function put(object $key, object $value); /** * @param object $key @@ -42,14 +42,14 @@ public function put($key, $value); * * @return object */ - public function get($key); + public function get(object $key); /** * @param object $key * * @return bool */ - public function has($key): bool; + public function has(object $key): bool; /** * @param object $key @@ -58,7 +58,7 @@ public function has($key): bool; * * @return object */ - public function remove($key); + public function remove(object $key); /** * @return void diff --git a/src/ObjectTypeHintTrait.php b/src/ObjectTypeHintTrait.php deleted file mode 100644 index 6ba3a56..0000000 --- a/src/ObjectTypeHintTrait.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code or visit http://opensource.org/licenses/MIT - */ - -namespace Pinepain\ObjectMaps; - - -use function is_object; -use Pinepain\ObjectMaps\Exceptions\UnexpectedValueException; - - -trait ObjectTypeHintTrait -{ - protected function assertObject($value, string $name) - { - if (!is_object($value)) { - throw new UnexpectedValueException("{$name} is not an object"); - } - } -} diff --git a/tests/AbstractObjectMapInterfaceTest.php b/tests/AbstractObjectMapInterfaceTest.php index 426c392..5c8a5a5 100644 --- a/tests/AbstractObjectMapInterfaceTest.php +++ b/tests/AbstractObjectMapInterfaceTest.php @@ -122,28 +122,6 @@ public function testPutAndGet() $this->assertSame($value, $map->get($key)); } - /** - * @expectedException \Pinepain\ObjectMaps\Exceptions\UnexpectedValueException - * @expectedExceptionMessage Key is not an object - */ - public function testPutKeyNotAnObjectFails() - { - $map = $this->buildMap(); - - $map->put('foo', 'bar'); - } - - /** - * @expectedException \Pinepain\ObjectMaps\Exceptions\UnexpectedValueException - * @expectedExceptionMessage Value is not an object - */ - public function testPutValueNotAnObjectFails() - { - $map = $this->buildMap(); - - $map->put(new stdClass(), 'bar'); - } - /** * @expectedException \Pinepain\ObjectMaps\Exceptions\OverflowException * @expectedExceptionMessage Value with such key already exists @@ -159,17 +137,6 @@ public function testPutExistentKeyFails() $map->put($key, $value); } - /** - * @expectedException \Pinepain\ObjectMaps\Exceptions\UnexpectedValueException - * @expectedExceptionMessage Key is not an object - */ - public function testGetByNonObjectFails() - { - $map = $this->buildMap(); - - $map->get('test'); - } - /** * @expectedException \Pinepain\ObjectMaps\Exceptions\OutOfBoundsException * @expectedExceptionMessage Value with such key not found @@ -181,17 +148,6 @@ public function testGetNonexistentKeyFails() $map->get(new stdClass()); } - /** - * @expectedException \Pinepain\ObjectMaps\Exceptions\UnexpectedValueException - * @expectedExceptionMessage Key is not an object - */ - public function testHasByNonObjectFails() - { - $map = $this->buildMap(); - - $map->has('test'); - } - public function testHasNonexistentKey() { $map = $this->buildMap(); @@ -209,17 +165,6 @@ public function testHasExistentKey() $this->assertTrue($map->has($key)); } - /** - * @expectedException \Pinepain\ObjectMaps\Exceptions\UnexpectedValueException - * @expectedExceptionMessage Key is not an object - */ - public function testRemoveByNonObjectFails() - { - $map = $this->buildMap(); - - $map->remove('test'); - } - /** * @expectedException \Pinepain\ObjectMaps\Exceptions\OutOfBoundsException * @expectedExceptionMessage Value with such key not found