Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php8 compatible #909

Open
wants to merge 4 commits into
base: 1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bitcoin
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"pleonasm/merkle-tree": "1.0.0",
"composer/semver": "^1.4.0|^3.2.0",
"lastguest/murmurhash": "v2.0.0",
"mdanter/ecc": "^0.5.0",
"mdanter/ecc": ">0.5.0",
"bitwasp/buffertools": "^0.5.0",
"bitwasp/bech32": "^0.0.1"
},
Expand Down
98 changes: 34 additions & 64 deletions src/Transaction/Mutator/AbstractCollectionMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,117 +3,87 @@
declare(strict_types=1);

namespace BitWasp\Bitcoin\Transaction\Mutator;
use ArrayAccess;
use Countable;
use Iterator;
use SplFixedArray;

abstract class AbstractCollectionMutator implements \Iterator, \ArrayAccess, \Countable
abstract class AbstractCollectionMutator implements Iterator, ArrayAccess, Countable
{
/**
* @var \SplFixedArray
*/
protected $set;
private $position;

public function __construct(int $size)
{
$this->set = new SplFixedArray($size);
$this->position = 0;
}

/**
* @return array
*/
public function all(): array
{
return $this->set->toArray();
}

/**
* @return bool
*/
public function isNull(): bool
{
return count($this->set) === 0;
}

/**
* @return int
*/
public function count(): int
{
return $this->set->count();
}

/**
*
*/
public function rewind()
{
$this->set->rewind();
$this->position = 0;
}

/**
* @return mixed
*/
public function current()
{
return $this->set->current();
return $this->set[$this->position];
}

/**
* @return int
*/
public function key()
{
return $this->set->key();
return $this->position;
}

/**
*
*/
public function next()
{
$this->set->next();
$this->position++;
}

/**
* @return bool
*/
public function valid()
{
return $this->set->valid();
return isset($this->set[$this->position]);
}

/**
* @param int $offset
* @return bool
*/
public function offsetExists($offset)
{
return $this->set->offsetExists($offset);
return isset($this->set[$offset]);
}

/**
* @param int $offset
*/
public function offsetUnset($offset)
public function offsetGet($offset)
{
if (!$this->offsetExists($offset)) {
throw new \InvalidArgumentException('Offset does not exist');
}

$this->set->offsetUnset($offset);
return $this->set[$offset];
}

/**
* @param int $offset
* @return mixed
*/
public function offsetGet($offset)
public function offsetSet($offset, $value)
{
if (!$this->set->offsetExists($offset)) {
throw new \OutOfRangeException('Nothing found at this offset');
}
return $this->set->offsetGet($offset);

$this->set[$offset] = $value;
}

/**
* @param int $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
public function offsetUnset($offset)
{
$this->set->offsetSet($offset, $value);
if (!$this->offsetExists($offset)) {
throw new \InvalidArgumentException('Offset does not exist');
}

unset($this->set[$offset]);
}

public function count()
{
return $this->set->count();
}
}
8 changes: 0 additions & 8 deletions src/Transaction/Mutator/InputCollectionMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ public function __construct(array $inputs)
$this->set = \SplFixedArray::fromArray($set, false);
}

/**
* @return InputMutator
*/
public function current(): InputMutator
{
return $this->set->current();
}

/**
* @param int $offset
* @return InputMutator
Expand Down