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

Refactoring - Rewrite #19

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ charset = utf-8
max_line_length = 80
indent_style = space
indent_size = 4
insert_final_newline = true
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake github:loophp/nix-shell#env-php82 --impure
20 changes: 4 additions & 16 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.1', '7.2', '7.3', '7.4']
php-versions: ["8.2", "8.3"]

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

- name: Run Grumphp
run: vendor/bin/grumphp run --no-ansi -n
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}

- name: Send PSALM data
run: vendor/bin/psalm --shepherd --stats
continue-on-error: true

- name: Scrutinizer
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
continue-on-error: true
- name: Run Tests
run: composer phpunit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/.idea/
/test.php
/phpspec.yml
/.direnv
/.phpunit.cache
26 changes: 18 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,35 @@
}
],
"require": {
"php": ">= 7.1.3"
"php": ">= 8.2"
},
"require-dev": {
"drupol/php-conventions": "^1.7.1",
"phpunit/php-code-coverage": "^4 || ^5",
"phpunit/phpunit": "^6 || ^7"
"ext-pcov": "*",
"phpunit/php-code-coverage": "^11",
"phpunit/phpunit": "^11",
"symfony/finder": "^7.2",
"symfony/yaml": "^7.2"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"ergebnis/composer-normalize": true,
"phpro/grumphp": true,
"phpstan/extension-installer": true
}
},
"autoload": {
"psr-4": {
"drupol\\phpermutations\\": "src/",
"drupol\\phpermutations\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"drupol\\phpermutations\\Tests\\": "tests/src/"
}
},
"scripts": {
"grumphp": "./vendor/bin/grumphp run",
"phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c tests/phpunit.xml tests"
"phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c phpunit.xml tests"
},
"support": {
"issues": "https://github.com/drupol/phpermutations/issues",
Expand Down
26 changes: 26 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
shortenArraysForExportThreshold="10"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnPhpunitDeprecations="true"
failOnPhpunitDeprecation="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
78 changes: 4 additions & 74 deletions src/Combinatorics.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,114 +8,44 @@

abstract class Combinatorics
{
/**
* The dataset.
*
* @var array<int, mixed>
*/
protected $dataset;

/**
* The number of values in the dataset.
*
* @var int
*/
protected $datasetCount;
protected int $datasetCount;

/**
* The length.
*
* @var int
*/
protected $length;

/**
* Combinatorics constructor.
*
* @param array<int, mixed> $dataset
* The dataset
* @param int|null $length
* The length
*/
public function __construct(array $dataset = [], $length = null)
public function __construct(array $dataset = [], ?int $length = null)
{
$this->setDataset($dataset);
$this->datasetCount = count($this->dataset);
$this->setLength($length);
}

/**
* Count elements of an object.
*
* @return int
* The number of element
*/
public function count(): int
{
return count($this->toArray());
}

/**
* Get the dataset.
*
* @return mixed[]
* The dataset
*/
public function getDataset(): array
{
return $this->dataset;
}

/**
* Get the length.
*
* @return int
* The length
*/
public function getLength(): int
{
return (int) $this->length;
}

/**
* Set the dataset.
*
* @param array<int, mixed> $dataset
* The dataset
*
* @return $this
*/
public function setDataset(array $dataset = []): Combinatorics
{
$this->dataset = $dataset;

return $this;
}

/**
* Set the length.
*
* @param int|null $length
* The length
*
* @return $this
*/
public function setLength($length = null): Combinatorics
public function setLength(?int $length = null): Combinatorics
{
$length = $length ?? $this->datasetCount;
$this->length = (abs($length) > $this->datasetCount) ? $this->datasetCount : $length;

return $this;
}

/**
* @return array<int, mixed>
*/
public function toArray(): array
{
return [];
}

/**
* Compute the factorial of an integer.
*
Expand All @@ -127,7 +57,7 @@ public function toArray(): array
* @return int
* The factorial of $n
*/
protected function fact($n, $total = 1): int
protected function fact(int $n, int $total = 1): int
{
return (2 > $n) ? $total : $this->fact($n - 1, $total * $n);
}
Expand Down
25 changes: 0 additions & 25 deletions src/GeneratorInterface.php

This file was deleted.

60 changes: 0 additions & 60 deletions src/Generators/Combinations.php

This file was deleted.

39 changes: 0 additions & 39 deletions src/Generators/Fibonacci.php

This file was deleted.

Loading
Loading