Skip to content

Commit

Permalink
Add readonly where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Feb 24, 2022
1 parent 3f7d84e commit c21db4d
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/ConcurrentArrayIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
final class ConcurrentArrayIterator implements ConcurrentIterator
{
private int $position = 0;
private int $size;
private readonly int $size;

private array $values;
private readonly array $values;

private FiberLocal $currentPosition;
private readonly FiberLocal $currentPosition;

private ?DisposedException $disposed = null;

public function __construct(array $values)
{
$this->values = \PHP_VERSION_ID >= 80100 && \array_is_list($values) ? $values : \array_values($values);
$this->values = \array_is_list($values) ? $values : \array_values($values);
$this->size = \count($values);
$this->currentPosition = new FiberLocal(fn () => throw new \Error('Call continue() before calling get()'));
}
Expand Down
4 changes: 2 additions & 2 deletions src/ConcurrentChainedIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
final class ConcurrentChainedIterator implements ConcurrentIterator
{
/** @var ConcurrentIterator<T>[] */
private array $iterators;
private readonly array $iterators;

/** @var FiberLocal<int|null> */
private FiberLocal $position;
private readonly FiberLocal $position;

/**
* @param ConcurrentIterator<T>[] $iterators
Expand Down
2 changes: 1 addition & 1 deletion src/ConcurrentIterableIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
final class ConcurrentIterableIterator implements ConcurrentIterator
{
/** @var ConcurrentIterator<T> */
private ConcurrentIterator $iterator;
private readonly ConcurrentIterator $iterator;

/**
* @param iterable<array-key, T> $iterable
Expand Down
10 changes: 5 additions & 5 deletions src/Internal/ConcurrentClosureIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
final class ConcurrentClosureIterator implements ConcurrentIterator
{
private \Closure $supplier;
private readonly \Closure $supplier;

private \SplQueue $sources;
private readonly \SplQueue $sources;

private QueueState $queue;
private readonly QueueState $queue;

private Sequence $sequence;
private readonly Sequence $sequence;

private DeferredCancellation $deferredCancellation;
private readonly DeferredCancellation $deferredCancellation;

private int $cancellations = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/Internal/ConcurrentFlatMapIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final class ConcurrentFlatMapIterator implements ConcurrentIterator
{
/** @var ConcurrentIterator<T> */
private ConcurrentIterator $iterator;
private readonly ConcurrentIterator $iterator;

/**
* @template R
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/ConcurrentQueueIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/** @internal */
final class ConcurrentQueueIterator implements ConcurrentIterator
{
private QueueState $state;
private readonly QueueState $state;

public function __construct(QueueState $state)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Internal/FlatMapOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public static function getStopMarker(): object
return $marker ??= new \stdClass;
}

private int $concurrency;
private readonly int $concurrency;

private bool $ordered;
private readonly bool $ordered;

/** @var \Closure(T, int):iterable<R> */
private \Closure $flatMap;
private readonly \Closure $flatMap;

/**
* @param \Closure(T, int):iterable<R> $flatMap
Expand Down
4 changes: 2 additions & 2 deletions src/Internal/QueueState.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ final class QueueState implements \IteratorAggregate
private int $positionOffset = 0;

/** @var FiberLocal<int|null> */
private FiberLocal $currentPosition;
private readonly FiberLocal $currentPosition;

/** @var FiberLocal<T|null> */
private FiberLocal $currentValue;
private readonly FiberLocal $currentValue;

public function __construct(int $bufferSize = 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/SortOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/** @internal */
final class SortOperation implements IntermediateOperation
{
private \Closure $compare;
private readonly \Closure $compare;

public function __construct(\Closure $compare)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static function concat(array $pipelines): self
));
}

private ConcurrentIterator $source;
private readonly ConcurrentIterator $source;

private int $concurrency = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
final class Queue
{
/** @var Internal\QueueState<T> Has public emit, complete, and fail methods. */
private Internal\QueueState $state;
private readonly Internal\QueueState $state;

/**
* @param int $bufferSize Allowed number of items to internally buffer before awaiting backpressure from the
Expand Down

0 comments on commit c21db4d

Please sign in to comment.