Skip to content

Commit

Permalink
Upgrading packages
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed May 23, 2024
1 parent 5b55b64 commit b7cdda5
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 222 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
uses: dependabot/fetch-metadata@v2.1.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Auto-merge Dependabot PRs for semver-minor updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Auto-merge Dependabot PRs for semver-patch updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: "Run Laravel Pint"
uses: aglipanci/laravel-pint-action@2.3.0
uses: aglipanci/laravel-pint-action@2.4.0

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
4 changes: 2 additions & 2 deletions .github/workflows/run-tests-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: [ '8.2' ]
php-versions: [ '8.3' ]
dependency-stability: [ 'prefer-none' ]

name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install PHP versions
uses: shivammathur/setup-php@v2
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0, 8.1, 8.2]
php: [8.1, 8.2, 8.3]
exclude:
- os: windows-latest
php: 8.0
- os: windows-latest
php: 8.1
- os: windows-latest
php: 8.2

name: P${{ matrix.php }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ phpunit.xml
psalm.xml
vendor
.php-cs-fixer.cache

/.phpunit.cache
.DS_Store
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
}
],
"require": {
"php": "^8.0"
"php": "^8.1|^8.2|^8.3"
},
"require-dev": {
"laravel/pint": "^1.2",
"pestphp/pest": "^1.22",
"pestphp/pest": "^2",
"phpstan/phpstan": "^1.6",
"rector/rector": "^0.15.0"
"rector/rector": "^1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion examples/cheatsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
print_result($arr->find(fn ($element, $index): bool => $element > 1 && $index > 1));
// 3
$arr = Arr::make(['foo', 'bar', 'baz']);
print_result($arr->find(fn ($element): bool => str_contains($element, 'a')));
print_result($arr->find(fn ($element): bool => str_contains((string) $element, 'a')));
// 'bar'

// Returns the shadow copied part of the array to another location and keeps its length
Expand Down
4 changes: 2 additions & 2 deletions examples/sets.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require './vendor/autoload.php';
require __DIR__ . '/vendor/autoload.php';

use HiFolks\DataType\Arr;

Expand All @@ -10,5 +10,5 @@
$arrB = Arr::make([1, 2, 5, 6, 7]);

echo " --- Intersection" . PHP_EOL;
$intersection = $arrA->filter(fn ($x) => $arrB->includes($x));
$intersection = $arrA->filter(fn ($x): bool => $arrB->includes($x));
echo $intersection->toString() . PHP_EOL;
58 changes: 21 additions & 37 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="HiFolks Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="HiFolks Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
LevelSetList::UP_TO_PHP_81,
SetList::DEAD_CODE,
SetList::CODE_QUALITY,
SetList::EARLY_RETURN,
Expand Down
10 changes: 2 additions & 8 deletions src/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function from(iterable|string $arrayLike, ?Closure $mapFn = null):
$arrayLike = iterator_to_array($arrayLike);
}

$array = self::make((array) $arrayLike);
$array = self::make($arrayLike);

if (! is_callable($mapFn)) {
return $array;
Expand Down Expand Up @@ -268,7 +268,6 @@ public function pop(): mixed
/**
* Add element to start of Arr and return new length
*
* @param mixed $element the elements to add to the front of the array
* @return int the new length of the array upon which the method was called.
*/
public function unshift(mixed ...$element): int
Expand Down Expand Up @@ -371,7 +370,6 @@ public function slice(int $start, int $end = null): Arr
/**
* Returns index of first occurrence of element in arr
*
* @param mixed $searchElement the element to search
* @return string|int|bool the index of element found. If it is not found, false is returned
*/
public function indexOf(mixed $searchElement): string|int|bool
Expand All @@ -382,7 +380,6 @@ public function indexOf(mixed $searchElement): string|int|bool
/**
* Returns index of last occurrence of element in Arr
*
* @param mixed $searchElement the element to search
* @return string|int|bool the index of element found. If it is not found, false is returned
*/
public function lastIndexOf(mixed $searchElement): string|int|bool
Expand Down Expand Up @@ -481,7 +478,7 @@ public function flat(): self
{
$array = array_reduce(
$this->arr,
fn ($result, $element) => array_merge($result, is_array($element) ? [...$element] : [$element]),
fn ($result, $element): array => array_merge($result, is_array($element) ? [...$element] : [$element]),
[]
);

Expand Down Expand Up @@ -518,7 +515,6 @@ public function flatMap(callable $callback): self
/**
* Changes all elements in range from $start for $count, to the specified value
*
* @param mixed $value the value to fill the array with
* @param int $start start index (from 0)
* @param int|null $end end index (default, the end of array)
*/
Expand Down Expand Up @@ -587,7 +583,6 @@ public function sort(): Arr
*
* @param int $start the index at which to start changing the array
* @param int|null $deleteCount an integer indicating the number of elements in the array to remove from $start
* @param mixed $newElements The elements to add to the array, beginning from $start
* @return Arr an array containing the deleted elements
*/
public function splice(int $start, int $deleteCount = null, mixed $newElements = []): Arr
Expand All @@ -606,7 +601,6 @@ public function toString(): string
/**
* Returns true if the input is an array
*
* @param mixed $input the input value, to test if it is an array
* @return bool true if $input is an array, false otherwise
*/
public static function isArray(mixed $input): bool
Expand Down
4 changes: 2 additions & 2 deletions src/Classes/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class Operation
{
public static function add(int|string $field, int|float $value): Closure
{
return fn ($element) => $value + $element[$field];
return fn ($element): int|float => $value + $element[$field];
}

public static function double(int|string $field): Closure
{
return fn ($element) => $element[$field] * 2;
return fn ($element): int|float => $element[$field] * 2;
}
}
49 changes: 24 additions & 25 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function rows(): array
public function toArray(): array
{
$result = [];
foreach ($this->rows() as $key => $row) {
foreach ($this->rows as $key => $row) {
$result[$key] = $row->arr();
}
return $result;
Expand Down Expand Up @@ -89,9 +89,7 @@ public function select(int|string ...$columns): self
$newRow = [];
foreach ($columns as $column) {
$value = $row->get($column);
if ($column !== null) {
$newRow[$column] = $value;
}
$newRow[$column] = $value;
}
$table->append(Arr::make($newRow));
}
Expand Down Expand Up @@ -129,14 +127,14 @@ public function where(string|int $field, mixed $operator = null, mixed $value =
}

$function = match ($operator) {
'==' => fn ($element) => $element->get($field) == $value,
'>' => fn ($element) => $element->get($field) > $value,
'<' => fn ($element) => $element->get($field) < $value,
'>=' => fn ($element) => $element->get($field) >= $value,
'<=' => fn ($element) => $element->get($field) <= $value,
'!=' => fn ($element) => $element->get($field) != $value,
'!==' => fn ($element) => $element->get($field) !== $value,
default => fn ($element) => $element->get($field) === $value
'==' => fn ($element): bool => $element->get($field) == $value,
'>' => fn ($element): bool => $element->get($field) > $value,
'<' => fn ($element): bool => $element->get($field) < $value,
'>=' => fn ($element): bool => $element->get($field) >= $value,
'<=' => fn ($element): bool => $element->get($field) <= $value,
'!=' => fn ($element): bool => $element->get($field) != $value,
'!==' => fn ($element): bool => $element->get($field) !== $value,
default => fn ($element): bool => $element->get($field) === $value
};
$filteredArray = array_filter($this->rows, $function);

Expand All @@ -145,12 +143,12 @@ public function where(string|int $field, mixed $operator = null, mixed $value =

public function orderBy(string|int $field, string $order = 'desc'): self
{
$array = $this->rows();
$array = $this->rows;

if ($order !== 'asc') {
$closure = static fn (Arr $item1, Arr $item2) => $item2->get($field) <=> $item1->get($field);
$closure = static fn (Arr $item1, Arr $item2): int => $item2->get($field) <=> $item1->get($field);
} else {
$closure = static fn ($item1, $item2) => $item1->get($field) <=> $item2->get($field);
$closure = static fn ($item1, $item2): int => $item1->get($field) <=> $item2->get($field);
}

usort($array, $closure);
Expand Down Expand Up @@ -179,9 +177,10 @@ public function groupBy(string|int $field): Table
foreach ($this->rows as $value) {
$property = $value->get($field);
$property = $this->castVariableForStrval($property);

if (!$property
|| array_key_exists(strval($property), $result)) {
if (!$property) {
continue;
}
if (array_key_exists(strval($property), $result)) {
continue;
}
$result[$property] = $value;
Expand All @@ -197,10 +196,10 @@ public function groupBy(string|int $field): Table
private function castVariableForStrval(mixed $property): bool|float|int|string|null
{
return match(gettype($property)) {
'boolean' => (bool) $property,
'double' => (float) $property,
'integer' => (int) $property,
'string' => (string) $property,
'boolean' => $property,
'double' => $property,
'integer' => $property,
'string' => $property,
default => null,
};
}
Expand All @@ -212,7 +211,7 @@ public function transform(
string|int $field,
callable $function,
): self {
$array = $this->rows();
$array = $this->rows;

foreach ($array as $row) {
/** @var array<int, mixed> $keys */
Expand All @@ -228,7 +227,7 @@ public function transform(

public function count(): int
{
return count($this->rows());
return count($this->rows);
}

/**
Expand All @@ -237,7 +236,7 @@ public function count(): int
private function getArr(array|Arr $value): Arr
{
if (!$value instanceof Arr) {
$value = Arr::make($value);
return Arr::make($value);
}
return $value;
}
Expand Down
Loading

0 comments on commit b7cdda5

Please sign in to comment.