Skip to content

Commit 779bee1

Browse files
committed
refact: rewrite of the library
- Remove Generators - It was not necessary to keep them - Switch to PHPUnit 11 - Remove temporarily drupol/php-conventions, deps issue with vimeo/psalm - Remove methods toArray and count - Remove custom interfaces - Update CI
1 parent c64ff50 commit 779bee1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1195
-1818
lines changed

.editorconfig

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ charset = utf-8
66
max_line_length = 80
77
indent_style = space
88
indent_size = 4
9-
insert_final_newline = true

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake github:loophp/nix-shell#env-php82 --impure

.github/workflows/continuous-integration.yml

+4-16
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
17-
php-versions: ['7.1', '7.2', '7.3', '7.4']
17+
php-versions: ["8.2", "8.3"]
1818

1919
steps:
2020
- name: Checkout
@@ -26,7 +26,7 @@ jobs:
2626
uses: shivammathur/setup-php@master
2727
with:
2828
php-version: ${{ matrix.php-versions }}
29-
extensions: mbstring,xdebug
29+
extensions: mbstring,pcov
3030
- name: Get Composer Cache Directory
3131
id: composer-cache
3232
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
@@ -41,17 +41,5 @@ jobs:
4141
- name: Install dependencies
4242
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
4343

44-
- name: Run Grumphp
45-
run: vendor/bin/grumphp run --no-ansi -n
46-
env:
47-
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
48-
49-
- name: Send PSALM data
50-
run: vendor/bin/psalm --shepherd --stats
51-
continue-on-error: true
52-
53-
- name: Scrutinizer
54-
run: |
55-
wget https://scrutinizer-ci.com/ocular.phar
56-
php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
57-
continue-on-error: true
44+
- name: Run Tests
45+
run: composer phpunit

composer.json

+18-8
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,35 @@
2121
}
2222
],
2323
"require": {
24-
"php": ">= 7.1.3"
24+
"php": ">= 8.2"
2525
},
2626
"require-dev": {
27-
"drupol/php-conventions": "^1.7.1",
28-
"phpunit/php-code-coverage": "^4 || ^5",
29-
"phpunit/phpunit": "^6 || ^7"
27+
"ext-pcov": "*",
28+
"phpunit/php-code-coverage": "^11",
29+
"phpunit/phpunit": "^11",
30+
"symfony/finder": "^7.2",
31+
"symfony/yaml": "^7.2"
3032
},
3133
"config": {
32-
"sort-packages": true
34+
"sort-packages": true,
35+
"allow-plugins": {
36+
"ergebnis/composer-normalize": true,
37+
"phpro/grumphp": true,
38+
"phpstan/extension-installer": true
39+
}
3340
},
3441
"autoload": {
3542
"psr-4": {
36-
"drupol\\phpermutations\\": "src/",
43+
"drupol\\phpermutations\\": "src/"
44+
}
45+
},
46+
"autoload-dev": {
47+
"psr-4": {
3748
"drupol\\phpermutations\\Tests\\": "tests/src/"
3849
}
3950
},
4051
"scripts": {
41-
"grumphp": "./vendor/bin/grumphp run",
42-
"phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c tests/phpunit.xml tests"
52+
"phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c phpunit.xml tests"
4353
},
4454
"support": {
4555
"issues": "https://github.com/drupol/phpermutations/issues",

phpunit.xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheDirectory=".phpunit.cache"
6+
executionOrder="depends,defects"
7+
shortenArraysForExportThreshold="10"
8+
requireCoverageMetadata="true"
9+
beStrictAboutCoverageMetadata="true"
10+
beStrictAboutOutputDuringTests="true"
11+
displayDetailsOnPhpunitDeprecations="true"
12+
failOnPhpunitDeprecation="true"
13+
failOnRisky="true"
14+
failOnWarning="true">
15+
<testsuites>
16+
<testsuite name="default">
17+
<directory>tests</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
22+
<include>
23+
<directory>src</directory>
24+
</include>
25+
</source>
26+
</phpunit>

src/Combinatorics.php

+4-74
Original file line numberDiff line numberDiff line change
@@ -8,114 +8,44 @@
88

99
abstract class Combinatorics
1010
{
11-
/**
12-
* The dataset.
13-
*
14-
* @var array<int, mixed>
15-
*/
1611
protected $dataset;
1712

18-
/**
19-
* The number of values in the dataset.
20-
*
21-
* @var int
22-
*/
23-
protected $datasetCount;
13+
protected int $datasetCount;
2414

25-
/**
26-
* The length.
27-
*
28-
* @var int
29-
*/
3015
protected $length;
3116

32-
/**
33-
* Combinatorics constructor.
34-
*
35-
* @param array<int, mixed> $dataset
36-
* The dataset
37-
* @param int|null $length
38-
* The length
39-
*/
40-
public function __construct(array $dataset = [], $length = null)
17+
public function __construct(array $dataset = [], ?int $length = null)
4118
{
4219
$this->setDataset($dataset);
4320
$this->datasetCount = count($this->dataset);
4421
$this->setLength($length);
4522
}
4623

47-
/**
48-
* Count elements of an object.
49-
*
50-
* @return int
51-
* The number of element
52-
*/
53-
public function count(): int
54-
{
55-
return count($this->toArray());
56-
}
57-
58-
/**
59-
* Get the dataset.
60-
*
61-
* @return mixed[]
62-
* The dataset
63-
*/
6424
public function getDataset(): array
6525
{
6626
return $this->dataset;
6727
}
6828

69-
/**
70-
* Get the length.
71-
*
72-
* @return int
73-
* The length
74-
*/
7529
public function getLength(): int
7630
{
7731
return (int) $this->length;
7832
}
7933

80-
/**
81-
* Set the dataset.
82-
*
83-
* @param array<int, mixed> $dataset
84-
* The dataset
85-
*
86-
* @return $this
87-
*/
8834
public function setDataset(array $dataset = []): Combinatorics
8935
{
9036
$this->dataset = $dataset;
9137

9238
return $this;
9339
}
9440

95-
/**
96-
* Set the length.
97-
*
98-
* @param int|null $length
99-
* The length
100-
*
101-
* @return $this
102-
*/
103-
public function setLength($length = null): Combinatorics
41+
public function setLength(?int $length = null): Combinatorics
10442
{
10543
$length = $length ?? $this->datasetCount;
10644
$this->length = (abs($length) > $this->datasetCount) ? $this->datasetCount : $length;
10745

10846
return $this;
10947
}
11048

111-
/**
112-
* @return array<int, mixed>
113-
*/
114-
public function toArray(): array
115-
{
116-
return [];
117-
}
118-
11949
/**
12050
* Compute the factorial of an integer.
12151
*
@@ -127,7 +57,7 @@ public function toArray(): array
12757
* @return int
12858
* The factorial of $n
12959
*/
130-
protected function fact($n, $total = 1): int
60+
protected function fact(int $n, int $total = 1): int
13161
{
13262
return (2 > $n) ? $total : $this->fact($n - 1, $total * $n);
13363
}

src/GeneratorInterface.php

-25
This file was deleted.

src/Generators/Combinations.php

-60
This file was deleted.

src/Generators/Fibonacci.php

-39
This file was deleted.

0 commit comments

Comments
 (0)