Skip to content

Commit

Permalink
Fix code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
MortalFlesh committed May 14, 2024
1 parent 6f5fe07 commit eee13f0
Show file tree
Hide file tree
Showing 32 changed files with 315 additions and 354 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
],
"analyze": [
"@cs",
"vendor/bin/ecs check-markdown README.md --ansi",
"@phpstan"
],
"cs": "vendor/bin/ecs check --ansi",
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/BadMethodCallException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace MF\Collection\Exception;

class BadMethodCallException extends \BadMethodCallException implements CollectionExceptionInterface
{
}
class BadMethodCallException extends \BadMethodCallException implements CollectionExceptionInterface {}
4 changes: 1 addition & 3 deletions src/Exception/CollectionExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace MF\Collection\Exception;

interface CollectionExceptionInterface extends \Throwable
{
}
interface CollectionExceptionInterface extends \Throwable {}
24 changes: 12 additions & 12 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

class InvalidArgumentException extends \InvalidArgumentException implements CollectionExceptionInterface, AssertionFailedException
{
/** @phpstan-param mixed[] $constraints */
public function __construct(
string $message,
?int $code = null,
private ?string $propertyPath = null,
private mixed $value = null,
private array $constraints = [],
?\Throwable $previous = null,
) {
parent::__construct($message, (int) $code, $previous);
}

public static function forFailedAssertion(AssertionFailedException $e): self
{
return new static(
Expand All @@ -18,18 +30,6 @@ public static function forFailedAssertion(AssertionFailedException $e): self
);
}

/** @phpstan-param mixed[] $constraints */
public function __construct(
string $message,
int $code = null,
private ?string $propertyPath = null,
private mixed $value = null,
private array $constraints = [],
\Throwable $previous = null,
) {
parent::__construct($message, (int) $code, $previous);
}

public function getPropertyPath(): ?string
{
return $this->propertyPath;
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/LogicException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace MF\Collection\Exception;

class LogicException extends \LogicException implements CollectionExceptionInterface
{
}
class LogicException extends \LogicException implements CollectionExceptionInterface {}
4 changes: 1 addition & 3 deletions src/Exception/OutOfBoundsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace MF\Collection\Exception;

class OutOfBoundsException extends \OutOfBoundsException implements CollectionExceptionInterface
{
}
class OutOfBoundsException extends \OutOfBoundsException implements CollectionExceptionInterface {}
4 changes: 1 addition & 3 deletions src/Exception/OutOfRangeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace MF\Collection\Exception;

class OutOfRangeException extends \OutOfRangeException implements CollectionExceptionInterface
{
}
class OutOfRangeException extends \OutOfRangeException implements CollectionExceptionInterface {}
4 changes: 1 addition & 3 deletions src/Exception/TupleException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace MF\Collection\Exception;

class TupleException extends InvalidArgumentException implements TupleExceptionInterface
{
}
class TupleException extends InvalidArgumentException implements TupleExceptionInterface {}
4 changes: 1 addition & 3 deletions src/Exception/TupleExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace MF\Collection\Exception;

interface TupleExceptionInterface extends CollectionExceptionInterface
{
}
interface TupleExceptionInterface extends CollectionExceptionInterface {}
4 changes: 1 addition & 3 deletions src/Exception/TupleParseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace MF\Collection\Exception;

class TupleParseException extends TupleException
{
}
class TupleParseException extends TupleException {}
2 changes: 1 addition & 1 deletion src/Helper/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function curry(callable $callback): callable
$all = $ref->getNumberOfParameters();
$required = $ref->getNumberOfRequiredParameters();

return fn (...$args) => $callback(...self::prepareArgs($all, $required, $args));
return fn(...$args) => $callback(...self::prepareArgs($all, $required, $args));
}

/** @see https://stackoverflow.com/questions/13071186/how-to-get-the-number-of-parameters-of-a-run-time-determined-callable */
Expand Down
16 changes: 7 additions & 9 deletions src/Immutable/Generic/KVPair.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
*/
readonly class KVPair
{
/**
* @phpstan-param TKey $key
* @phpstan-param TValue $value
*/
public function __construct(private int|string $key, private mixed $value) {}

/**
* @phpstan-param self<TKey, TValue> $pair
* @phpstan-return TKey
Expand All @@ -34,14 +40,6 @@ public static function fromTuple(ITuple $tuple): static
return new static($tuple->first(), $tuple->second());
}

/**
* @phpstan-param TKey $key
* @phpstan-param TValue $value
*/
public function __construct(private int|string $key, private mixed $value)
{
}

/** @phpstan-return TKey */
public function getKey(): int|string
{
Expand All @@ -54,7 +52,7 @@ public function getValue(): mixed
return $this->value;
}

public function asTuple(): ITUple
public function asTuple(): ITuple
{
return Tuple::of($this->key, $this->value);
}
Expand Down
18 changes: 8 additions & 10 deletions src/Immutable/Generic/ListCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
readonly class ListCollection implements IList
{
/** @phpstan-param array<TIndex, TValue> $listArray */
public function __construct(private array $listArray = []) {}

/**
* @phpstan-template T
* @phpstan-param IList<T|iterable<T>> $list
Expand Down Expand Up @@ -79,11 +82,6 @@ public static function create(iterable $source, callable $creator): IList
return new static($listArray);
}

/** @phpstan-param array<TIndex, TValue> $listArray */
public function __construct(private array $listArray = [])
{
}

public function count(): int
{
return count($this->listArray);
Expand Down Expand Up @@ -249,7 +247,7 @@ private function removeIndex(int $index): IList
*/
public function removeAll(mixed $value): IList
{
return $this->filter(fn (mixed $val): bool => $value !== $val);
return $this->filter(fn(mixed $val): bool => $value !== $val);
}

/**
Expand Down Expand Up @@ -374,7 +372,7 @@ public function sortBy(callable $callback): IList

usort(
$sorted,
fn (mixed $a, mixed $b): int => $callback($a) <=> $callback($b)
fn(mixed $a, mixed $b): int => $callback($a) <=> $callback($b),
);

return static::from($sorted);
Expand All @@ -391,7 +389,7 @@ public function sortByDescending(callable $callback): IList

usort(
$sorted,
fn (mixed $a, mixed $b): int => $callback($b) <=> $callback($a)
fn(mixed $a, mixed $b): int => $callback($b) <=> $callback($a),
);

return static::from($sorted);
Expand Down Expand Up @@ -455,7 +453,7 @@ public function sumBy(callable $callback): int|float
$callback = Callback::curry($callback);

return $this->reduce(
fn (int|float $sum, mixed $value, int $i): int|float => $sum + $callback($value, $i),
fn(int|float $sum, mixed $value, int $i): int|float => $sum + $callback($value, $i),
0,
);
}
Expand Down Expand Up @@ -574,7 +572,7 @@ public function collect(callable $callback): IList
$callback = Callback::curry($callback);

/** @phsptan-var IList<iterable<T>> $collected */
$collected = $this->map(fn (mixed $v): iterable => $callback($v));
$collected = $this->map(fn(mixed $v): iterable => $callback($v));
/** @phpstan-var IList<T> $concatenated */
$concatenated = $collected->concat();

Expand Down
14 changes: 6 additions & 8 deletions src/Immutable/Generic/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
readonly class Map implements IMap
{
/** @phpstan-param array<TKey, TValue> $mapArray */
public function __construct(private array $mapArray = []) {}

/**
* @phpstan-param iterable<TKey, TValue> $source
* @phpstan-return IMap<TKey, TValue>
Expand Down Expand Up @@ -55,7 +58,7 @@ public static function fromPairs(iterable $pairs): IMap
throw new InvalidArgumentException('Value is not a pair');
}

/**
/*
* @phpstan-var TKey $key
* @phpstan-var TValue $value
*/
Expand Down Expand Up @@ -84,11 +87,6 @@ public static function create(iterable $source, callable $creator): IMap
return new static($mapArray);
}

/** @phpstan-param array<TKey, TValue> $mapArray */
public function __construct(private array $mapArray = [])
{
}

public function count(): int
{
return count($this->mapArray);
Expand Down Expand Up @@ -257,7 +255,7 @@ public function values(): IList
public function pairs(): IList
{
/** @phpstan-var IList<KVPair<TKey, TValue>> $pairs */
$pairs = ListCollection::create($this, fn ($value, $key) => new KVPair($key, $value));
$pairs = ListCollection::create($this, fn($value, $key) => new KVPair($key, $value));

return $pairs;
}
Expand Down Expand Up @@ -330,7 +328,7 @@ public function asMutable(): \MF\Collection\Mutable\Generic\IMap
public function toList(): IList
{
/** @phpstan-var IList<ITuple> $list */
$list = ListCollection::create($this, fn ($value, $key) => Tuple::of($key, $value));
$list = ListCollection::create($this, fn($value, $key) => Tuple::of($key, $value));

return $list;
}
Expand Down
22 changes: 11 additions & 11 deletions src/Immutable/Generic/Seq.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class Seq implements ISeq

private bool $isInfinite = false;

/** @phpstan-param DataSource $iterable */
public function __construct(private readonly iterable|\Closure $iterable)
{
$this->modifiers = [];
}

/**
* @phpstan-template T
* @phpstan-param ISeq<T|iterable<T>> $seq
Expand Down Expand Up @@ -259,12 +265,6 @@ function () use ($callable, $initialValue) {
);
}

/** @phpstan-param DataSource $iterable */
public function __construct(private readonly iterable|\Closure $iterable)
{
$this->modifiers = [];
}

/** @phpstan-return ISeq<TValue> */
private function setIsInfinite(bool $isInfinite = true): ISeq
{
Expand Down Expand Up @@ -479,7 +479,7 @@ public function take(int $limit): ISeq

private function clone(): static
{
return clone ($this);
return clone $this;
}

private function addModifier(SeqModifier $type, mixed $modifier): static
Expand Down Expand Up @@ -687,7 +687,7 @@ public function sortBy(callable $callback): ISeq

usort(
$items,
fn (mixed $a, mixed $b): int => $callback($a) <=> $callback($b)
fn(mixed $a, mixed $b): int => $callback($a) <=> $callback($b),
);

yield from $items;
Expand All @@ -712,7 +712,7 @@ public function sortByDescending(callable $callback): ISeq

usort(
$items,
fn (mixed $a, mixed $b): int => $callback($b) <=> $callback($a)
fn(mixed $a, mixed $b): int => $callback($b) <=> $callback($a),
);

yield from $items;
Expand Down Expand Up @@ -795,7 +795,7 @@ public function reverse(): ISeq
public function sum(): int|float
{
return $this->reduce(
fn (int|float $sum, mixed $value) => $sum + $value,
fn(int|float $sum, mixed $value) => $sum + $value,
0,
);
}
Expand All @@ -806,7 +806,7 @@ public function sumBy(callable $callback): int|float
$callback = Callback::curry($callback);

return $this->reduce(
fn (int|float $sum, mixed $value) => $sum + $callback($value),
fn(int|float $sum, mixed $value) => $sum + $callback($value),
0,
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Immutable/ITuple.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
interface ITuple extends IEnumerable, \ArrayAccess, \Stringable
{
/**
* @see Tuple::toString()
*/
public function __toString(): string;

public static function fst(ITuple $tuple): mixed;

public static function snd(ITuple $tuple): mixed;
Expand All @@ -34,7 +39,7 @@ public static function snd(ITuple $tuple): mixed;
*
* @throws TupleParseException
*/
public static function parse(string $tuple, int $expectedItemsCount = null): self;
public static function parse(string $tuple, ?int $expectedItemsCount = null): self;

/**
* Parse "(x, y, ... z)" string into Tuple(x, y, z) and validates items types
Expand Down Expand Up @@ -153,11 +158,6 @@ public static function merge(ITuple $base, mixed ...$additional): ITuple;
*/
public static function mergeMatch(array $types, ITuple $base, mixed ...$additional): ITuple;

/**
* @see Tuple::toString()
*/
public function __toString(): string;

/**
* Transform tuple values into string (which is compatible with Tuple::parse() method)
* @see Tuple::parse()
Expand Down
Loading

0 comments on commit eee13f0

Please sign in to comment.