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

#11 Statistical analysis tools #15

Merged
merged 1 commit into from
Jan 6, 2021
Merged
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ install:

script:
- vendor/bin/ecs --level psr12 check src
- vendor/bin/phpstan analyse
- vendor/bin/phpunit
- php check-coverage.php coverage.xml 100

after_success:
- travis_retry php vendor/bin/php-coveralls -v
- travis_retry mkdir -p build/logs && php vendor/bin/php-coveralls -x coverage.xml -v

env:
- XDEBUG_MODE=coverage
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Build Status](https://travis-ci.com/elegant-bro/arrayee.svg?branch=master)](https://travis-ci.com/elegant-bro/arrayee)
[![Coverage Status](https://coveralls.io/repos/github/elegant-bro/arayee/badge.svg?branch=master)](https://coveralls.io/github/elegant-bro/arayee?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/elegant-bro/arrayee/badge.svg?branch=master)](https://coveralls.io/github/elegant-bro/arrayee?branch=master)
# Work with arrays in elegant way

## For contributors
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"require-dev": {
"ext-simplexml": "*",
"php-coveralls/php-coveralls": "^2.4",
"phpstan/phpstan": "^0.12.64",
"phpstan/phpstan-phpunit": "^0.12.17",
"phpunit/phpunit": "^5.7 || ^6.4 || ^7.0",
"symplify/easy-coding-standard": "^6.0"
},
Expand Down
1,497 changes: 684 additions & 813 deletions composer.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
level: max
paths:
- src
- tests
14 changes: 9 additions & 5 deletions src/Aggregation/Reduced.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
use ElegantBro\Arrayee\Just;
use ElegantBro\Interfaces\Arrayee;
use Exception;
use RuntimeException;

use function array_reduce;

/**
* @template V
*/
final class Reduced implements Arrayee
{
/**
Expand All @@ -17,7 +22,7 @@ final class Reduced implements Arrayee
private $arrayee;

/**
* @var callback
* @var callable
*/
private $callback;

Expand All @@ -27,7 +32,6 @@ final class Reduced implements Arrayee
private $initial;

/**
* Reduced constructor.
* @param Arrayee $arrayee
* @param callable $callback Function that reduces items to array <code>function(array $carry, $item): array</code>
* @param Arrayee $initial
Expand All @@ -42,7 +46,7 @@ public function __construct(Arrayee $arrayee, callable $callback, Arrayee $initi
/**
* @param Arrayee $arrayee
* @param callable $callback Function that reduces items to array <code>function(array $carry, $item): array</code>
* @return Reduced
* @return Reduced<V>
stepanets marked this conversation as resolved.
Show resolved Hide resolved
*/
public static function initialEmpty(Arrayee $arrayee, callable $callback): Reduced
{
Expand All @@ -54,7 +58,7 @@ public static function initialEmpty(Arrayee $arrayee, callable $callback): Reduc
}

/**
* @return array
* @return array<V>
* @throws Exception
*/
public function asArray(): array
Expand All @@ -65,7 +69,7 @@ public function asArray(): array
$this->initial->asArray()
);
if (!is_array($reduced)) {
throw new \RuntimeException("Reduced is not array");
throw new RuntimeException("Reduced is not array");
}
return $reduced;
}
Expand Down
12 changes: 9 additions & 3 deletions src/Diff/ByKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
use ElegantBro\Arrayee\Just;
use ElegantBro\Arrayee\Mapped;
use ElegantBro\Interfaces\Arrayee;
use Exception;

/**
* @template T
* @implements DiffWay<T>
*/
final class ByKeys implements DiffWay
{
/**
Expand All @@ -19,8 +24,6 @@ final class ByKeys implements DiffWay
private $arrayees;

/**
* ByValues constructor.
*
* @param Arrayee ...$arrayees
*/
public function __construct(Arrayee ...$arrayees)
Expand All @@ -29,7 +32,10 @@ public function __construct(Arrayee ...$arrayees)
}

/**
* @inheritDoc
* @param Arrayee $arrayee
*
* @throws Exception
* @return array<T>
*/
public function diff(Arrayee $arrayee): array
{
Expand Down
13 changes: 10 additions & 3 deletions src/Diff/ByValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
use ElegantBro\Arrayee\Just;
use ElegantBro\Arrayee\Mapped;
use ElegantBro\Interfaces\Arrayee;
use Exception;

use function array_diff;

/**
* @template T
* @implements DiffWay<T>
*/
final class ByValues implements DiffWay
{
/**
Expand All @@ -20,8 +26,6 @@ final class ByValues implements DiffWay
private $arrayees;

/**
* ByValues constructor.
*
* @param Arrayee ...$arrayees
*/
public function __construct(Arrayee ...$arrayees)
Expand All @@ -30,7 +34,10 @@ public function __construct(Arrayee ...$arrayees)
}

/**
* @inheritDoc
* @param Arrayee $arrayee
*
* @throws Exception
* @return array<T>
*/
public function diff(Arrayee $arrayee): array
{
Expand Down
13 changes: 10 additions & 3 deletions src/Diff/ByValuesAndKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
use ElegantBro\Arrayee\Just;
use ElegantBro\Arrayee\Mapped;
use ElegantBro\Interfaces\Arrayee;
use Exception;

use function array_diff_assoc;

/**
* @template T
* @implements DiffWay<T>
*/
final class ByValuesAndKeys implements DiffWay
{
/**
Expand All @@ -20,8 +26,6 @@ final class ByValuesAndKeys implements DiffWay
private $arrayees;

/**
* ByValues constructor.
*
* @param Arrayee ...$arrayees
*/
public function __construct(Arrayee ...$arrayees)
Expand All @@ -30,7 +34,10 @@ public function __construct(Arrayee ...$arrayees)
}

/**
* @inheritDoc
* @param Arrayee $arrayee
*
* @throws Exception
* @return array<T>
*/
public function diff(Arrayee $arrayee): array
{
Expand Down
5 changes: 4 additions & 1 deletion src/Diff/DiffWay.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
use ElegantBro\Interfaces\Arrayee;
use Exception;

/**
* @template T
*/
interface DiffWay
{
/**
* @param Arrayee $arrayee
*
* @return array
* @return array<T>
* @throws Exception
*/
public function diff(Arrayee $arrayee): array;
Expand Down
13 changes: 8 additions & 5 deletions src/DiffOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

use ElegantBro\Arrayee\Diff\DiffWay;
use ElegantBro\Interfaces\Arrayee;
use Exception;

/**
* @template T
*/
final class DiffOf implements Arrayee
{
/**
Expand All @@ -18,15 +22,13 @@ final class DiffOf implements Arrayee
private $arrayee;

/**
* @var DiffWay
* @var DiffWay<T>
*/
private $way;

/**
* DiffOf constructor.
*
* @param Arrayee $arrayee
* @param DiffWay $way
* @param DiffWay<T> $way
*/
public function __construct(Arrayee $arrayee, DiffWay $way)
{
Expand All @@ -35,7 +37,8 @@ public function __construct(Arrayee $arrayee, DiffWay $way)
}

/**
* @inheritDoc
* @return array<T>
* @throws Exception
*/
public function asArray(): array
{
Expand Down
6 changes: 4 additions & 2 deletions src/Filtered.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

declare(strict_types=1);


namespace ElegantBro\Arrayee;

use ElegantBro\Interfaces\Arrayee;
use Exception;
use function array_filter;

/**
* @template T
*/
final class Filtered implements Arrayee
{
/**
Expand All @@ -28,7 +30,7 @@ public function __construct(Arrayee $arrayee, callable $predicate)
}

/**
* @return array
* @return array<T>
* @throws Exception
*/
public function asArray(): array
Expand Down
5 changes: 4 additions & 1 deletion src/FromCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use ElegantBro\Interfaces\Arrayee;
use Exception;

/**
* @template T
*/
final class FromCallable implements Arrayee
{
/**
Expand All @@ -20,7 +23,7 @@ public function __construct(callable $func)
}

/**
* @return array
* @return array<T>
* @throws Exception
*/
public function asArray(): array
Expand Down
11 changes: 9 additions & 2 deletions src/FromIterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use ElegantBro\Interfaces\Arrayee;
use Exception;

/**
* @template T
*/
final class FromIterable implements Arrayee
{
/**
* @var iterable
* @var iterable<T>
*/
private $iterable;

Expand All @@ -19,14 +22,18 @@ final class FromIterable implements Arrayee
*/
private $limit;

/**
* @param iterable<T> $iterable
* @param int $limit
*/
public function __construct(iterable $iterable, int $limit = 0)
{
$this->iterable = $iterable;
$this->limit = $limit;
}

/**
* @return array
* @return array<T>
* @throws Exception
*/
public function asArray(): array
Expand Down
6 changes: 4 additions & 2 deletions src/JsonDecoded.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

declare(strict_types=1);


namespace ElegantBro\Arrayee;

use ElegantBro\Interfaces\Arrayee;
use ElegantBro\Interfaces\Stringify;
use Exception;
use RuntimeException;

/**
* @template T
*/
final class JsonDecoded implements Arrayee
{
/**
Expand All @@ -23,7 +25,7 @@ public function __construct(Stringify $json)
}

/**
* @return array
* @return array<T>
* @throws Exception
*/
public function asArray(): array
Expand Down
Loading