Skip to content
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
44 changes: 44 additions & 0 deletions bin/compile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);

try {
$pharFile = 'app.phar';

// clean up
if (file_exists($pharFile)) {
unlink($pharFile);
}

if (file_exists($pharFile . '.gz')) {
unlink($pharFile . '.gz');
}

// create phar
$phar = new Phar($pharFile);

// start buffering. Mandatory to modify stub to add shebang
$phar->startBuffering();

// Create the default stub from main.php entrypoint
$defaultStub = Phar::createDefaultStub('main.php');

// Add the rest of the apps files
$phar->buildFromDirectory(__DIR__ . '/app');

// Customize the stub to add the shebang
$stub = "#!/usr/bin/env php \n" . $defaultStub;

// Add the stub
$phar->setStub($stub);

$phar->stopBuffering();

// plus - compressing it into gzip
$phar->compressFiles(Phar::GZ);

# Make the file executable
chmod(__DIR__ . '/app.phar', 0770);

echo "$pharFile successfully created" . PHP_EOL;
} catch (\Throwable $e) {
echo $e->getMessage();
}
5 changes: 5 additions & 0 deletions bin/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

php --define phar.readonly=0 bin/compile.php
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"require-dev": {
"ergebnis/composer-normalize": "^2.40",
"lmc/coding-standard": "^3.3",
"lmc/coding-standard": "^4.1",
"mockery/mockery": "^1.6.7",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpstan/extension-installer": "^1.3.1",
Expand Down Expand Up @@ -54,13 +54,12 @@
],
"analyze": [
"@cs",
"vendor/bin/ecs check-markdown README.md --ansi",
"@phpstan"
],
"cs": "vendor/bin/ecs check --ansi -- src/ tests/ ecs.php",
"cs": "vendor/bin/ecs check --ansi",
"fix": [
"@composer normalize",
"vendor/bin/ecs check --ansi --clear-cache --fix -- src/ tests/ ecs.php"
"vendor/bin/ecs check --ansi --clear-cache --fix"
],
"lint": [
"vendor/bin/parallel-lint -j 10 -e php ./src ./tests ecs.php",
Expand Down
50 changes: 24 additions & 26 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@
use Lmc\CodingStandard\Sniffs\Naming\InterfaceNameSniff;
use PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();

$parameters->set(
Option::SKIP,
[
SelfAccessorFixer::class => null,
'SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff.ReferencedGeneralException' => ['tests/Exception/*.php'],
'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.TagsNotGrouped' => [
'src/Immutable/Generic/ISeq.php', // skip fixing the order of phpstan annotations
'src/Immutable/Generic/Seq.php', // skip fixing the order of phpstan annotations
],
InterfaceNameSniff::class => null,
'SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff.MissingAnyTypeHint' => null,
'SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff.MissingAnyTypeHint' => null,
'SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff.MissingAnyTypeHint' => null,
PhpdocToParamTypeFixer::class => [
'src/Immutable/Tuple.php',
],
return ECSConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withRootFiles()
->withSets([
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
])
->withSkip([
SelfAccessorFixer::class => null,
'SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff.ReferencedGeneralException' => ['tests/Exception/*.php'],
'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.TagsNotGrouped' => [
'src/Immutable/Generic/ISeq.php', // skip fixing the order of phpstan annotations
'src/Immutable/Generic/Seq.php', // skip fixing the order of phpstan annotations
],
);

$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.1.php');
};
InterfaceNameSniff::class => null,
'SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff.MissingAnyTypeHint' => null,
'SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff.MissingAnyTypeHint' => null,
'SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff.MissingAnyTypeHint' => null,
PhpdocToParamTypeFixer::class => [
'src/Immutable/Tuple.php',
],
]);
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ parameters:

-
message: '#Parameter \#3 \$index of method MF\\Collection\\Immutable\\Generic\\Seq<TValue>::mapiValue\(\) expects int, mixed given.#'
count: 2
count: 1
path: src/Immutable/Generic/Seq.php

-
Expand All @@ -87,7 +87,7 @@ parameters:

-
message: '#Generator expects key type int, mixed given.#'
count: 2
count: 1
path: src/Immutable/Generic/Seq.php

-
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
Loading