diff --git a/.editorconfig b/.editorconfig index aa9a047..173228f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,15 +1,9 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org - -# PHP PSR-2 Coding Standards -# http://www.php-fig.org/psr/psr-2/ - root = true -[*.php] -charset = utf-8 +[*] end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true +charset = utf-8 +max_line_length = 80 indent_style = space indent_size = 4 +insert_final_newline = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e5620ab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +/spec export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.scrutinizer.yml export-ignore +.travis.yml export-ignore +phpunit.xml.dist export-ignore +infection.json.dist export-ignore +grumphp.yml.dist export-ignore +phpspec.yml.dist export-ignore diff --git a/.github/settings.yml b/.github/settings.yml new file mode 100644 index 0000000..f6c3cf9 --- /dev/null +++ b/.github/settings.yml @@ -0,0 +1,49 @@ +# https://github.com/probot/settings + +branches: + - name: master + protection: + enforce_admins: false + required_pull_request_reviews: + dismiss_stale_reviews: true + require_code_owner_reviews: true + required_approving_review_count: 1 + required_status_checks: + contexts: + - "Grumphp" + strict: false + restrictions: null + +labels: + - name: bug + color: ee0701 + + - name: dependencies + color: 0366d6 + + - name: enhancement + color: 0e8a16 + + - name: question + color: cc317c + + - name: security + color: ee0701 + + - name: stale + color: eeeeee + +repository: + allow_merge_commit: true + allow_rebase_merge: false + allow_squash_merge: false + default_branch: master + description: "Generators and iterators, permutations and combinations." + topics: math,numbers,permutations,combinations,iterators,fibonacci,prime numbers,product + has_downloads: true + has_issues: true + has_pages: false + has_projects: false + has_wiki: false + name: phptree + private: false diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..ad87565 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,44 @@ +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions + +on: + - pull_request + - push + +name: "Continuous Integration" + +jobs: + grumphp: + name: "Grumphp" + + runs-on: ubuntu-latest + + strategy: + matrix: + php-binary: + - php7.1 + - php7.2 + - php7.3 + + steps: + - name: "Checkout" + uses: actions/checkout@master + with: + fetch-depth: 1 + + - name: "Composer install" + run: ${{ matrix.php-binary }} $(which composer) install --no-interaction --no-progress --no-suggest + + - name: "Composer install lowest dependencies" + if: matrix.dependencies == 'lowest' + run: ${{ matrix.php-binary }} $(which composer) update --no-interaction --no-progress --no-suggest --prefer-lowest + + - name: "Install Graphviz" + run: sudo apt-get install graphviz + + - name: "Run Grumphp" + run: ${{ matrix.php-binary }} vendor/bin/grumphp run + env: + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + + - name: "Scrutinizer" + run: wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml diff --git a/.gitignore b/.gitignore index 68e42c3..5f5cc1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,63 +1,8 @@ -# Created by .ignore support plugin (hsz.mobi) -### Composer template -composer.phar -/vendor/ - -# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries - -# Sensitive or high-churn files: -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml - -# Gradle: -.idea/**/gradle.xml -.idea/**/libraries - -# CMake -cmake-build-debug/ - -# Mongo Explorer plugin: -.idea/**/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -/.php_cs.cache /composer.lock +/vendor +/build +/.php_cs.cache +/example/ +/.idea/ /test.php -/build/ +/phpspec.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 9d356fb..8662fd1 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,4 +1,9 @@ -build: false +build: + nodes: + analysis: + tests: + override: + - php-scrutinizer-run filter: paths: @@ -7,3 +12,7 @@ filter: tools: external_code_coverage: timeout: 600 + php_loc: true + php_pdepend: true + php_sim: true + php_changetracking: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 843a2cc..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: php - -git: - depth: 1 - -cache: - directories: - - $HOME/.cache/composer - - $HOME/.composer/cache - -php: - - 5.6 - - 7.1 - - 7.2 - - 7.3 - -matrix: - allow_failures: - - php: 5.6 - -install: - - composer install - -script: - - composer grumphp - -after_success: - - bash <(curl -s https://codecov.io/bash) -f build/logs/clover.xml diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 4e9c7f9..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,46 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at pol.dellaiera@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/README.md b/README.md index 941ba3e..353e56e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Latest Stable Version](https://img.shields.io/packagist/v/drupol/phpermutations.svg?style=flat-square)](https://packagist.org/packages/drupol/phpermutations) [![GitHub stars](https://img.shields.io/github/stars/drupol/phpermutations.svg?style=flat-square)](https://packagist.org/packages/drupol/phpermutations) [![Total Downloads](https://img.shields.io/packagist/dt/drupol/phpermutations.svg?style=flat-square)](https://packagist.org/packages/drupol/phpermutations) - [![Build Status](https://img.shields.io/travis/drupol/phpermutations/master.svg?style=flat-square)](https://travis-ci.org/drupol/phpermutations) + [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/drupol/phpermutations/Continuous%20Integration?style=flat-square)](https://github.com/drupol/phpermutations/actions) [![Build Status](https://img.shields.io/appveyor/ci/drupol/phpermutations.svg?style=flat-square)](https://ci.appveyor.com/project/drupol/phpermutations) [![Scrutinizer code quality](https://img.shields.io/scrutinizer/quality/g/drupol/phpermutations/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/drupol/phpermutations/?branch=master) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/drupol/phpermutations/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/drupol/phpermutations/?branch=master) @@ -44,7 +44,7 @@ objects), the library will still continue to work without any trouble. ## Requirements -* PHP >= 5.6, +* PHP >= 7.1.3, ## How to use @@ -166,7 +166,7 @@ of each combinations having a length of 3 of that array. Each Generators and Iterators are tested using the same values as input. I try to be as much complete as possible with the [tests](https://github.com/drupol/phpermutations/tree/master/tests/fixtures). -Every time the sources are modified, [Travis](https://travis-ci.org/drupol/phpermutations), the continuous integration +Every time the sources are modified, [Github](https://github.com/drupol/phpermutations/actions), the continuous integration service, tests the code against those tests, this way you are aware if the changes that you are introducing are valid. # Contributing diff --git a/composer.json b/composer.json index 30e9f40..a20fc6a 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,19 @@ { "name": "drupol/phpermutations", - "description": "Generators and iterators, permutations and combinations.", "type": "library", + "description": "Generators and iterators, permutations and combinations.", + "keywords": [ + "math", + "numbers", + "permutations", + "combinations", + "iterators", + "fibonacci", + "prime numbers", + "product" + ], "homepage": "https://github.com/drupol/phpermutations", - "keywords": ["math", "numbers", "permutations", "combinations", "iterators", "fibonacci", "prime numbers", "product"], "license": "GPL-3.0-only", - "support": { - "issues": "https://github.com/drupol/phpermutations/issues", - "source": "https://github.com/drupol/phpermutations" - }, "authors": [ { "name": "Pol Dellaiera", @@ -16,16 +21,16 @@ } ], "require": { - "php": ">= 5.6" + "php": ">= 7.1.3" }, "require-dev": { - "drupol/php-conventions": "^1.3", - "phpunit/phpunit": "^5 || ^6", - "phpunit/php-code-coverage": "^4 || ^5" + "drupol/php-conventions": "^1.6.8", + "phpunit/php-code-coverage": "^4 || ^5", + "phpunit/phpunit": "^6 || ^7", + "symfony/process": "^4.4.1" }, - "scripts": { - "phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c tests/phpunit.xml tests", - "grumphp": "./vendor/bin/grumphp run" + "config": { + "sort-packages": true }, "autoload": { "psr-4": { @@ -33,7 +38,12 @@ "drupol\\phpermutations\\Tests\\": "tests/src/" } }, - "config": { - "sort-packages": true + "scripts": { + "grumphp": "./vendor/bin/grumphp run", + "phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c tests/phpunit.xml tests" + }, + "support": { + "issues": "https://github.com/drupol/phpermutations/issues", + "source": "https://github.com/drupol/phpermutations" } } diff --git a/examples/e.php b/examples/e.php deleted file mode 100644 index 9ed12de..0000000 --- a/examples/e.php +++ /dev/null @@ -1,43 +0,0 @@ - M_E constant in PHP). - * - * To find the number e using permutations: - * 1: Generate a set of size S of random values, - * 2: Find the number of permutations of that set, let it be #P0, - * 3: With all the permutations of this set, count the number of permutation - * (#P1) that doesn't share any single item with the original input set, - * 4: Divide #P0 by #P1, - * 5: Restart at 1 and increase the size of the set. - * - * Requirements: - * - https://packagist.org/packages/drupol/phpermutations - * - * Install: - * 1: Git clone phpermutations, - * 2: Run composer install, - * 3: Create this file at the root of the project, - * 4: Run php e.php. - */ -include './vendor/autoload.php'; - -for ($i = 2; 15 > $i; ++$i) { - $input = \range(1, $i); - $size = $i; - - echo '**********************************************************' . "\n"; - echo 'Size: ' . $i . "\n"; - - $Permutations = new \drupol\phpermutations\Generators\Permutations($input, $size); - - $j = 0; - foreach ($Permutations->generator() as $permutation) { - if (!($array3 = \array_intersect_assoc($input, $permutation))) { - ++$j; - } - } - - echo 'Number of permutations (#P0): ' . $Permutations->count() . "\n"; - echo 'Number of permutations without item at the same place (#P1): ' . $j . "\n"; - echo '(#P0) / (#P1): ' . $Permutations->count() / $j . "\n"; -} diff --git a/examples/pi.php b/examples/pi.php deleted file mode 100644 index f16f273..0000000 --- a/examples/pi.php +++ /dev/null @@ -1,53 +0,0 @@ - M_PI constant in PHP). - * - * π/4 = arctan(1/2) + arctan(1/5) + arctan(1/13) + arctan(1/21) + ... - * - * You'll have already noticed the Fibonacci numbers here. - * However, not all the Fibonacci numbers appear on the left hand sides. - * For instance, we have no expansion for arctan(1/5) nor for arctan(1/13). - * Only the even numbered Fibonacci terms seem to be expanded: - * (F2=1, F4=3, F6=8, F8=21, ...) - * - * To find the number pi using Fibonacci: - * 1: Generate a set of size S of Fibonacci numbers, - * 2: Apply on each item of the set a function that will compute the inverse - * of the item, - * 3: Apply on each item of the set the atan() function and multiply by 4, - * 4: Filter out values where the key value is odd, - * 3: Sum all the terms of the array. - * - * Requirements: - * - https://packagist.org/packages/drupol/phpermutations - * - * Install: - * 1: Git clone phpermutations, - * 2: Run composer install, - * 3: Create this file at the root of the project, - * 4: Run php pi.php. - */ -include './vendor/autoload.php'; - -$Fibonacci = new \drupol\phpermutations\Generators\Fibonacci(); - -for ($i = 2; 50 >= $i; $i = $i + 2) { - $gen = $Fibonacci->generator(); - - $input = []; - for ($s = 0; $s <= $i; ++$s) { - $input[] = $gen->current(); - $gen->next(); - } - - $input = \array_sum(\array_filter(\array_map(function ($item) { - return 4 * \atan(1 / $item); - }, \array_slice($input, 3)), function ($key) { - return !($key % 2); - }, ARRAY_FILTER_USE_KEY)); - - echo '**********************************************************' . "\n"; - echo 'Size: ' . $i . "\n"; - echo 'Pi estimation: ' . $input . "\n"; -} diff --git a/grumphp.yml.dist b/grumphp.yml.dist index 027ba42..c55ed40 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -1,11 +1,7 @@ imports: - - { resource: vendor/drupol/php-conventions/config/php56/grumphp.yml } + - { resource: vendor/drupol/php-conventions/config/php71/grumphp.yml } parameters: - git_dir: . - bin_dir: bin - extensions: - - drupol\PhpConventions\GrumphpTasksExtension extra_tasks: phpunit: config_file: ./tests/phpunit.xml diff --git a/src/Combinatorics.php b/src/Combinatorics.php index 09f1bf4..d0da466 100644 --- a/src/Combinatorics.php +++ b/src/Combinatorics.php @@ -1,7 +1,11 @@ */ protected $dataset; @@ -31,15 +35,15 @@ abstract class Combinatorics /** * Combinatorics constructor. * - * @param array $dataset + * @param array $dataset * The dataset - * @param null|int $length + * @param int|null $length * The length */ public function __construct(array $dataset = [], $length = null) { $this->setDataset($dataset); - $this->datasetCount = \count($this->dataset); + $this->datasetCount = count($this->dataset); $this->setLength($length); } @@ -51,7 +55,7 @@ public function __construct(array $dataset = [], $length = null) */ public function count() { - return \count($this->toArray()); + return count($this->toArray()); } /** @@ -79,7 +83,7 @@ public function getLength() /** * Set the dataset. * - * @param array $dataset + * @param array $dataset * The dataset * * @return $this @@ -94,21 +98,21 @@ public function setDataset(array $dataset = []) /** * Set the length. * - * @param null|int $length + * @param int|null $length * The length * * @return $this */ public function setLength($length = null) { - $length = (null === $length) ? $this->datasetCount : $length; - $this->length = (\abs($length) > $this->datasetCount) ? $this->datasetCount : $length; + $length = $length ?? $this->datasetCount; + $this->length = (abs($length) > $this->datasetCount) ? $this->datasetCount : $length; return $this; } /** - * @return array + * @return array */ public function toArray() { diff --git a/src/GeneratorInterface.php b/src/GeneratorInterface.php index 9fa62be..5cceca3 100644 --- a/src/GeneratorInterface.php +++ b/src/GeneratorInterface.php @@ -1,13 +1,17 @@ * The generator */ public function generator(); @@ -15,7 +19,7 @@ public function generator(); /** * Convert the generator into an array. * - * @return array + * @return array */ public function toArray(); } diff --git a/src/Generators/Combinations.php b/src/Generators/Combinations.php index 263e142..e2d84b2 100644 --- a/src/Generators/Combinations.php +++ b/src/Generators/Combinations.php @@ -1,9 +1,15 @@ $dataset * The dataset * @param int $length * The length * - * @codingStandardsIgnoreStart - * - * @return \Generator - * @codingStandardsIgnoreEnd + * @return Generator */ protected function get(array $dataset, $length) { - $originalLength = \count($dataset); + $originalLength = count($dataset); $remainingLength = $originalLength - $length + 1; + for ($i = 0; $i < $remainingLength; ++$i) { $current = $dataset[$i]; + if (1 === $length) { yield [$current]; } else { - $remaining = \array_slice($dataset, $i + 1); + $remaining = array_slice($dataset, $i + 1); + foreach ($this->get($remaining, $length - 1) as $permutation) { - \array_unshift($permutation, $current); + array_unshift($permutation, $current); + yield $permutation; } } diff --git a/src/Generators/Fibonacci.php b/src/Generators/Fibonacci.php index 7826509..e15ce00 100644 --- a/src/Generators/Fibonacci.php +++ b/src/Generators/Fibonacci.php @@ -1,9 +1,12 @@ */ protected function get() { $a = 0; $b = 1; $to = $this->getMaxLimit(); + while (0 < $to) { yield $a; - list($a, $b) = [$b, $a + $b]; + [$a, $b] = [$b, $a + $b]; --$to; } } diff --git a/src/Generators/FiniteGroup.php b/src/Generators/FiniteGroup.php index 0a258aa..03e688a 100644 --- a/src/Generators/FiniteGroup.php +++ b/src/Generators/FiniteGroup.php @@ -1,9 +1,12 @@ * The finite group generator - * @codingStandardsIgnoreEnd */ protected function get() { diff --git a/src/Generators/NGrams.php b/src/Generators/NGrams.php index d088154..127f5dd 100644 --- a/src/Generators/NGrams.php +++ b/src/Generators/NGrams.php @@ -1,9 +1,12 @@ * The generator - * @codingStandardsIgnoreEnd */ protected function get() { while (true) { $this->next(); + yield $this->current(); } } diff --git a/src/Generators/Perfect.php b/src/Generators/Perfect.php index 3feb9ab..9a28d30 100644 --- a/src/Generators/Perfect.php +++ b/src/Generators/Perfect.php @@ -1,5 +1,7 @@ $dataset * The dataset - * @param null|int $length + * @param int|null $length * The length */ public function __construct(array $dataset = [], $length = null) @@ -68,29 +73,27 @@ public function toArray() /** * The permutations generator. * - * @param array $dataset + * @param array $dataset * The dataset * - * @codingStandardsIgnoreStart - * - * @return \Generator - * @codingStandardsIgnoreEnd + * @return Generator */ protected function get(array $dataset) { foreach ($dataset as $key => $firstItem) { $remaining = $dataset; - \array_splice($remaining, $key, 1); + array_splice($remaining, $key, 1); - if (0 === \count($remaining)) { + if (0 === count($remaining)) { yield [$firstItem]; continue; } foreach ($this->get($remaining) as $permutation) { - \array_unshift($permutation, $firstItem); + array_unshift($permutation, $firstItem); + yield $permutation; } } diff --git a/src/Generators/Prime.php b/src/Generators/Prime.php index 96379d3..35253b9 100644 --- a/src/Generators/Prime.php +++ b/src/Generators/Prime.php @@ -1,5 +1,7 @@ $data * The dataset - * @codingStandardsIgnoreStart * - * @return \Generator - * The generator - * @codingStandardsIgnoreEnd + * @return Generator */ protected function get(array $data) { if (!empty($data)) { - if ($u = \array_pop($data)) { + if ($u = array_pop($data)) { foreach ($this->get($data) as $p) { foreach ($u as $v) { - yield $p + [\count($p) => $v]; + yield $p + [count($p) => $v]; } } } diff --git a/src/Generators/Shift.php b/src/Generators/Shift.php index 2b90528..2b5d4c6 100644 --- a/src/Generators/Shift.php +++ b/src/Generators/Shift.php @@ -1,13 +1,16 @@ next(); + yield $this->current(); } } diff --git a/src/IteratorInterface.php b/src/IteratorInterface.php index 8dbe32a..a00c770 100644 --- a/src/IteratorInterface.php +++ b/src/IteratorInterface.php @@ -1,7 +1,16 @@ + */ +interface IteratorInterface extends Iterator { } diff --git a/src/Iterators.php b/src/Iterators.php index 0fedcc6..dfb8c48 100644 --- a/src/Iterators.php +++ b/src/Iterators.php @@ -1,16 +1,20 @@ */ protected $current; @@ -46,7 +50,7 @@ public function rewind() /** * Convert the iterator into an array. * - * @return array + * @return array * The elements */ public function toArray() diff --git a/src/Iterators/Combinations.php b/src/Iterators/Combinations.php index ad8436f..b2221a6 100644 --- a/src/Iterators/Combinations.php +++ b/src/Iterators/Combinations.php @@ -1,5 +1,7 @@ */ protected $c = []; /** * Combinations constructor. * - * @param array $dataset + * @param array $dataset * The dataset - * @param null|int $length + * @param int|null $length * The length */ public function __construct(array $dataset = [], $length = null) { - parent::__construct(\array_values($dataset), $length); + parent::__construct(array_values($dataset), $length); $this->rewind(); } @@ -75,7 +77,7 @@ public function next() */ public function rewind() { - $this->c = \range(0, $this->length); + $this->c = range(0, $this->length); $this->key = 0; } @@ -96,6 +98,7 @@ public function valid() protected function nextHelper() { $i = $this->length - 1; + while (0 <= $i && $this->datasetCount - $this->length + $i === $this->c[$i]) { --$i; } @@ -105,6 +108,7 @@ protected function nextHelper() } ++$this->c[$i]; + while ($this->length - 1 > $i++) { $this->c[$i] = $this->c[$i - 1] + 1; } diff --git a/src/Iterators/Cycle.php b/src/Iterators/Cycle.php index 2fd03ca..a0583cf 100644 --- a/src/Iterators/Cycle.php +++ b/src/Iterators/Cycle.php @@ -1,9 +1,13 @@ getDataset()); + return count($this->getDataset()); } /** diff --git a/src/Iterators/Fibonacci.php b/src/Iterators/Fibonacci.php index bbe3a2a..7112ddb 100644 --- a/src/Iterators/Fibonacci.php +++ b/src/Iterators/Fibonacci.php @@ -1,9 +1,13 @@ current, $this->previous) = [$this->current + $this->previous, $this->current]; + [$this->current, $this->previous] = [$this->current + $this->previous, $this->current]; ++$this->key; } diff --git a/src/Iterators/FiniteGroup.php b/src/Iterators/FiniteGroup.php index c56c456..331a1a2 100644 --- a/src/Iterators/FiniteGroup.php +++ b/src/Iterators/FiniteGroup.php @@ -1,9 +1,13 @@ group); + return count($this->group); } /** @@ -41,7 +45,7 @@ public function count() */ public function current() { - return \current($this->group); + return current($this->group); } /** @@ -61,7 +65,7 @@ public function getSize() public function next() { ++$this->key; - \next($this->group); + next($this->group); } /** @@ -77,12 +81,12 @@ public function order($generator) { $result = []; - foreach (\range(1, $this->getSize()) as $number) { + foreach (range(1, $this->getSize()) as $number) { $value = ($generator ** $number) % $this->getSize(); $result[$value] = $value; } - return \count($result); + return count($result); } /** @@ -112,7 +116,7 @@ private function computeGroup() { $this->group = []; - foreach (\range(1, $this->getSize()) as $number) { + foreach (range(1, $this->getSize()) as $number) { if (1 === $this->gcd($number, $this->getSize())) { $this->group[] = $number; } diff --git a/src/Iterators/NGrams.php b/src/Iterators/NGrams.php index 207b6c8..4bc0a36 100644 --- a/src/Iterators/NGrams.php +++ b/src/Iterators/NGrams.php @@ -1,7 +1,11 @@ $dataset * The dataset * @param int $length * The shift length @@ -24,7 +28,7 @@ public function __construct(array $dataset = [], $length = 1) { parent::__construct($dataset, $length); - $this->currentValue = \array_slice( + $this->currentValue = array_slice( $this->getDataset(), 0, $length @@ -45,7 +49,7 @@ public function current() public function next() { parent::next(); - $this->currentValue = \array_slice($this->current, 0, $this->getLength()); + $this->currentValue = array_slice($this->current, 0, $this->getLength()); } /** @@ -54,6 +58,6 @@ public function next() public function rewind() { parent::rewind(); - $this->currentValue = \array_slice($this->current, 0, $this->getLength()); + $this->currentValue = array_slice($this->current, 0, $this->getLength()); } } diff --git a/src/Iterators/Perfect.php b/src/Iterators/Perfect.php index 4d28860..57f4b30 100644 --- a/src/Iterators/Perfect.php +++ b/src/Iterators/Perfect.php @@ -1,9 +1,13 @@ factors); + return count($this->factors); } /** @@ -39,7 +43,7 @@ public function count() */ public function current() { - return \current($this->factors); + return current($this->factors); } /** @@ -59,7 +63,7 @@ public function getNumber() public function next() { ++$this->key; - \next($this->factors); + next($this->factors); } /** diff --git a/src/Iterators/Product.php b/src/Iterators/Product.php index 15572bd..cf31565 100644 --- a/src/Iterators/Product.php +++ b/src/Iterators/Product.php @@ -1,8 +1,14 @@ $datasetArray * The array of dataset */ public function __construct(array $datasetArray) @@ -27,7 +33,7 @@ public function __construct(array $datasetArray) parent::__construct($datasetArray); foreach ($datasetArray as $dataset) { - $this->iterators[] = new \ArrayIterator($dataset); + $this->iterators[] = new ArrayIterator($dataset); } $this->key = 0; @@ -41,7 +47,7 @@ public function count() $product = 1; foreach ($this->getDataset() as $dataset) { - $product *= \count($dataset); + $product *= count($dataset); } return $product; @@ -66,10 +72,12 @@ public function current() */ public function next() { - foreach (\array_reverse($this->iterators) as $key => $iterator) { + foreach (array_reverse($this->iterators) as $key => $iterator) { $iterator->next(); + if ($iterator->valid()) { - $count_iterators = \count($this->iterators); + $count_iterators = count($this->iterators); + foreach ($this->iterators as $key2 => $iterator2) { if ($count_iterators - $key2 <= $key) { $iterator2->rewind(); diff --git a/src/Iterators/Rotation.php b/src/Iterators/Rotation.php index 2ab6554..62860aa 100644 --- a/src/Iterators/Rotation.php +++ b/src/Iterators/Rotation.php @@ -1,9 +1,14 @@ $dataset * The dataset */ public function __construct(array $dataset = []) @@ -33,7 +38,7 @@ public function __construct(array $dataset = []) */ public function count() { - return \count($this->getDataset()); + return count($this->getDataset()); } /** @@ -47,18 +52,18 @@ public function current() /** * Compute the next value of the Iterator. * - * @param null|int $offset + * @param int|null $offset * The offset */ public function next($offset = 1) { $offset = (null === $offset) ? 1 : $offset % $this->count(); - $this->rotation = \array_merge( - \array_slice( + $this->rotation = array_merge( + array_slice( $this->rotation, $offset ), - \array_slice( + array_slice( $this->rotation, 0, $offset diff --git a/src/Iterators/Shift.php b/src/Iterators/Shift.php index 0faea8b..21a6945 100644 --- a/src/Iterators/Shift.php +++ b/src/Iterators/Shift.php @@ -1,9 +1,14 @@ $dataset * The dataset * @param int $length * The shift length @@ -28,7 +33,7 @@ public function __construct(array $dataset = [], $length = 1) */ public function count() { - return \count($this->getDataset()); + return count($this->getDataset()); } /** @@ -65,16 +70,16 @@ protected function doShift($length = 1) $parameters = []; if (0 > $length) { - $parameters[] = ['start' => \abs($length), 'end' => null]; - $parameters[] = ['start' => 0, 'end' => \abs($length)]; + $parameters[] = ['start' => abs($length), 'end' => null]; + $parameters[] = ['start' => 0, 'end' => abs($length)]; } else { $parameters[] = ['start' => -1 * $length, 'end' => null]; $parameters[] = ['start' => 0, 'end' => $this->datasetCount + $length * -1]; } - $this->current = \array_merge( - \array_slice($this->current, $parameters[0]['start'], $parameters[0]['end']), - \array_slice($this->current, $parameters[1]['start'], $parameters[1]['end']) + $this->current = array_merge( + array_slice($this->current, $parameters[0]['start'], $parameters[0]['end']), + array_slice($this->current, $parameters[1]['start'], $parameters[1]['end']) ); } } diff --git a/tests/src/AbstractTest.php b/tests/src/AbstractTest.php index a3c063b..e2f6be0 100644 --- a/tests/src/AbstractTest.php +++ b/tests/src/AbstractTest.php @@ -1,5 +1,7 @@ files()->in($path) as $file) { - $type = \basename($file->getRelativePathname(), '.yml'); + $type = basename($file->getRelativePathname(), '.yml'); $data[$type] = [ 'file' => $file->getRelativePathname(), - 'type' => \basename($file->getRelativePathname(), '.yml'), + 'type' => basename($file->getRelativePathname(), '.yml'), 'content' => Yaml::parse($file->getContents()), ]; } diff --git a/tests/src/Generators/CombinationsTest.php b/tests/src/Generators/CombinationsTest.php index a12cee3..b034e1b 100644 --- a/tests/src/Generators/CombinationsTest.php +++ b/tests/src/Generators/CombinationsTest.php @@ -1,5 +1,7 @@ getDataset()); - static::assertSame($input['length'], $combinations->getLength()); - static::assertEquals( + self::assertSame($input['dataset'], $combinations->getDataset()); + self::assertSame($input['length'], $combinations->getLength()); + self::assertEquals( $expected['dataset'], $combinations->toArray(), '$canonicalize = true', @@ -40,6 +42,6 @@ public function testCombinationsClass($input, $expected) $maxDepth = 10, $canonicalize = true ); - static::assertSame($expected['count'], $combinations->count()); + self::assertSame($expected['count'], $combinations->count()); } } diff --git a/tests/src/Generators/FibonacciTest.php b/tests/src/Generators/FibonacciTest.php index 50ddf8e..9489897 100644 --- a/tests/src/Generators/FibonacciTest.php +++ b/tests/src/Generators/FibonacciTest.php @@ -1,5 +1,7 @@ setMaxLimit(1000); - static::assertSame($expected['count'], $prime->count()); - static::assertEquals( + self::assertSame($expected['count'], $prime->count()); + self::assertEquals( $expected['dataset'], $prime->toArray(), '$canonicalize = true', diff --git a/tests/src/Generators/FiniteGroupTest.php b/tests/src/Generators/FiniteGroupTest.php index f83a0b4..631877a 100644 --- a/tests/src/Generators/FiniteGroupTest.php +++ b/tests/src/Generators/FiniteGroupTest.php @@ -1,5 +1,7 @@ setSize($input['size']); - static::assertSame($expected['count'], $prime->count()); - static::assertEquals( + self::assertSame($expected['count'], $prime->count()); + self::assertEquals( $expected['dataset'], $prime->toArray(), '$canonicalize = true', diff --git a/tests/src/Generators/PerfectTest.php b/tests/src/Generators/PerfectTest.php index 880c1c0..c3f674a 100644 --- a/tests/src/Generators/PerfectTest.php +++ b/tests/src/Generators/PerfectTest.php @@ -1,5 +1,7 @@ setMaxLimit($input['max']); if (2 > $input['min']) { - static::assertSame(2, $perfect->getMinLimit()); + self::assertSame(2, $perfect->getMinLimit()); } else { - static::assertSame($input['min'], $perfect->getMinLimit()); + self::assertSame($input['min'], $perfect->getMinLimit()); } - static::assertSame($input['max'], $perfect->getMaxLimit()); - static::assertSame($expected['count'], $perfect->count()); - static::assertEquals( + self::assertSame($input['max'], $perfect->getMaxLimit()); + self::assertSame($expected['count'], $perfect->count()); + self::assertEquals( $expected['dataset'], $perfect->toArray(), '$canonicalize = true', diff --git a/tests/src/Generators/PermutationsTest.php b/tests/src/Generators/PermutationsTest.php index 737b83e..db11c2d 100644 --- a/tests/src/Generators/PermutationsTest.php +++ b/tests/src/Generators/PermutationsTest.php @@ -1,5 +1,7 @@ getDataset()); - static::assertSame($input['length'], $generator->getLength()); - static::assertSame($expected['count'], $generator->count()); - static::assertEquals( + self::assertSame($input['dataset'], $generator->getDataset()); + self::assertSame($input['length'], $generator->getLength()); + self::assertSame($expected['count'], $generator->count()); + self::assertEquals( $expected['dataset'], $generator->toArray(), '$canonicalize = true', diff --git a/tests/src/Generators/PrimeFactorsTest.php b/tests/src/Generators/PrimeFactorsTest.php index 8d32e5a..e2bb49b 100644 --- a/tests/src/Generators/PrimeFactorsTest.php +++ b/tests/src/Generators/PrimeFactorsTest.php @@ -1,5 +1,7 @@ setNumber($input['number']); - static::assertSame($expected['count'], $prime->count()); - static::assertEquals( + self::assertSame($expected['count'], $prime->count()); + self::assertEquals( $expected['dataset'], $prime->toArray(), '$canonicalize = true', diff --git a/tests/src/Generators/PrimeTest.php b/tests/src/Generators/PrimeTest.php index 277e774..5f33acf 100644 --- a/tests/src/Generators/PrimeTest.php +++ b/tests/src/Generators/PrimeTest.php @@ -1,5 +1,7 @@ setMaxLimit($input['max']); if (2 > $input['min']) { - static::assertSame(2, $prime->getMinLimit()); + self::assertSame(2, $prime->getMinLimit()); } else { - static::assertSame($input['min'], $prime->getMinLimit()); + self::assertSame($input['min'], $prime->getMinLimit()); } - static::assertSame($input['max'], $prime->getMaxLimit()); + self::assertSame($input['max'], $prime->getMaxLimit()); - static::assertSame($expected['count'], $prime->count()); - static::assertEquals( + self::assertSame($expected['count'], $prime->count()); + self::assertEquals( $expected['dataset'], $prime->toArray(), '$canonicalize = true', diff --git a/tests/src/Generators/ProductTest.php b/tests/src/Generators/ProductTest.php index 5de52aa..f3729ab 100644 --- a/tests/src/Generators/ProductTest.php +++ b/tests/src/Generators/ProductTest.php @@ -1,5 +1,7 @@ getDataset()); - static::assertSame($expected['count'], $product->count()); - static::assertEquals( + self::assertSame($input['dataset'], $product->getDataset()); + self::assertSame($expected['count'], $product->count()); + self::assertEquals( $expected['dataset'], $product->toArray(), '$canonicalize = true', diff --git a/tests/src/Generators/ShiftTest.php b/tests/src/Generators/ShiftTest.php index 71dd14a..11af0b4 100644 --- a/tests/src/Generators/ShiftTest.php +++ b/tests/src/Generators/ShiftTest.php @@ -1,5 +1,7 @@ getDataset()); - static::assertSame($expected['count'], $shift->count()); + self::assertSame($input['dataset'], $shift->getDataset()); + self::assertSame($expected['count'], $shift->count()); } } diff --git a/tests/src/Iterators/CombinationsTest.php b/tests/src/Iterators/CombinationsTest.php index 701cd16..2e8af4e 100644 --- a/tests/src/Iterators/CombinationsTest.php +++ b/tests/src/Iterators/CombinationsTest.php @@ -1,9 +1,12 @@ getDataset()); - static::assertSame($input['length'], $combinations->getLength()); - static::assertCount( - \count($input['dataset']), + self::assertSame($input['dataset'], $combinations->getDataset()); + self::assertSame($input['length'], $combinations->getLength()); + self::assertCount( + count($input['dataset']), $combinations->getDataset() ); - static::assertEquals( + self::assertEquals( $expected['dataset'], $combinations->toArray(), '$canonicalize = true', @@ -44,7 +47,7 @@ public function testCombinations($input, $expected) $maxDepth = 10, $canonicalize = true ); - static::assertSame($expected['count'], $combinations->count()); + self::assertSame($expected['count'], $combinations->count()); } /** @@ -54,7 +57,7 @@ public function testCombinations($input, $expected) */ public function testCombinationsWithBigNumbers() { - $combinations = new Combinations(\range(1, 200), 2); - static::assertCount($combinations->count(), $combinations->toArray()); + $combinations = new Combinations(range(1, 200), 2); + self::assertCount($combinations->count(), $combinations->toArray()); } } diff --git a/tests/src/Iterators/CycleTest.php b/tests/src/Iterators/CycleTest.php index a3e3f99..e5236a8 100644 --- a/tests/src/Iterators/CycleTest.php +++ b/tests/src/Iterators/CycleTest.php @@ -1,5 +1,7 @@ next(); } - static::assertSame($expected['current'], $cycle->current()); + self::assertSame($expected['current'], $cycle->current()); - static::assertSame($input['dataset'], $cycle->getDataset()); - static::assertSame($expected['count'], $cycle->count()); + self::assertSame($input['dataset'], $cycle->getDataset()); + self::assertSame($expected['count'], $cycle->count()); } } diff --git a/tests/src/Iterators/FibonacciTest.php b/tests/src/Iterators/FibonacciTest.php index 5840fbd..969af9d 100644 --- a/tests/src/Iterators/FibonacciTest.php +++ b/tests/src/Iterators/FibonacciTest.php @@ -1,5 +1,7 @@ setMaxLimit(1000); - static::assertSame($expected['count'], $prime->count()); - static::assertEquals( + self::assertSame($expected['count'], $prime->count()); + self::assertEquals( $expected['dataset'], $prime->toArray(), '$canonicalize = true', diff --git a/tests/src/Iterators/FiniteGroupTest.php b/tests/src/Iterators/FiniteGroupTest.php index ad74423..bff2bfe 100644 --- a/tests/src/Iterators/FiniteGroupTest.php +++ b/tests/src/Iterators/FiniteGroupTest.php @@ -1,5 +1,7 @@ setSize($input['size']); - static::assertSame($expected['count'], $prime->count()); - static::assertEquals( + self::assertSame($expected['count'], $prime->count()); + self::assertEquals( $expected['dataset'], $prime->toArray(), '$canonicalize = true', diff --git a/tests/src/Iterators/NgramsTest.php b/tests/src/Iterators/NgramsTest.php index 77468f6..c158c54 100644 --- a/tests/src/Iterators/NgramsTest.php +++ b/tests/src/Iterators/NgramsTest.php @@ -1,5 +1,7 @@ next(); } - static::assertSame($expected['current'], $ngrams->current()); + self::assertSame($expected['current'], $ngrams->current()); - static::assertSame($input['dataset'], $ngrams->getDataset()); - static::assertSame($expected['count'], $ngrams->count()); + self::assertSame($input['dataset'], $ngrams->getDataset()); + self::assertSame($expected['count'], $ngrams->count()); } } diff --git a/tests/src/Iterators/PerfectTest.php b/tests/src/Iterators/PerfectTest.php index cc85b3d..71af1ff 100644 --- a/tests/src/Iterators/PerfectTest.php +++ b/tests/src/Iterators/PerfectTest.php @@ -1,5 +1,7 @@ setMaxLimit($input['max']); if (2 > $input['min']) { - static::assertSame(2, $perfect->getMinLimit()); + self::assertSame(2, $perfect->getMinLimit()); } else { - static::assertSame($input['min'], $perfect->getMinLimit()); + self::assertSame($input['min'], $perfect->getMinLimit()); } - static::assertSame($input['max'], $perfect->getMaxLimit()); - static::assertSame($input['max'], $perfect->getMaxLimit()); - static::assertSame($expected['count'], $perfect->count()); - static::assertEquals( + self::assertSame($input['max'], $perfect->getMaxLimit()); + self::assertSame($input['max'], $perfect->getMaxLimit()); + self::assertSame($expected['count'], $perfect->count()); + self::assertEquals( $expected['dataset'], $perfect->toArray(), '$canonicalize = true', diff --git a/tests/src/Iterators/PrimeFactorsTest.php b/tests/src/Iterators/PrimeFactorsTest.php index e24910b..fe32d4d 100644 --- a/tests/src/Iterators/PrimeFactorsTest.php +++ b/tests/src/Iterators/PrimeFactorsTest.php @@ -1,5 +1,7 @@ setNumber($input['number']); - static::assertSame($expected['count'], $prime->count()); - static::assertEquals( + self::assertSame($expected['count'], $prime->count()); + self::assertEquals( $expected['dataset'], $prime->toArray(), '$canonicalize = true', diff --git a/tests/src/Iterators/PrimeTest.php b/tests/src/Iterators/PrimeTest.php index ffc36dd..fa582cf 100644 --- a/tests/src/Iterators/PrimeTest.php +++ b/tests/src/Iterators/PrimeTest.php @@ -1,5 +1,7 @@ setMaxLimit($input['max']); if (2 > $input['min']) { - static::assertSame(2, $prime->getMinLimit()); + self::assertSame(2, $prime->getMinLimit()); } else { - static::assertSame($input['min'], $prime->getMinLimit()); + self::assertSame($input['min'], $prime->getMinLimit()); } - static::assertSame($input['max'], $prime->getMaxLimit()); - static::assertSame($expected['count'], $prime->count()); - static::assertEquals( + self::assertSame($input['max'], $prime->getMaxLimit()); + self::assertSame($expected['count'], $prime->count()); + self::assertEquals( $expected['dataset'], $prime->toArray(), '$canonicalize = true', diff --git a/tests/src/Iterators/ProductTest.php b/tests/src/Iterators/ProductTest.php index 2aadee7..1ae52ee 100644 --- a/tests/src/Iterators/ProductTest.php +++ b/tests/src/Iterators/ProductTest.php @@ -1,5 +1,7 @@ getDataset()); - static::assertEquals( + self::assertSame($input['dataset'], $product->getDataset()); + self::assertEquals( $expected['dataset'], $product->toArray(), '$canonicalize = true', @@ -39,6 +41,6 @@ public function testProduct($input, $expected) $maxDepth = 10, $canonicalize = true ); - static::assertSame($expected['count'], $product->count()); + self::assertSame($expected['count'], $product->count()); } } diff --git a/tests/src/Iterators/RotationTest.php b/tests/src/Iterators/RotationTest.php index 562f6bb..8bcec33 100644 --- a/tests/src/Iterators/RotationTest.php +++ b/tests/src/Iterators/RotationTest.php @@ -1,9 +1,12 @@ null, ]; $rotation->next($input['turn']); - static::assertSame($expected['dataset'], $rotation->current()); + self::assertSame($expected['dataset'], $rotation->current()); $rotation->rewind(); - static::assertSame($input['dataset'], $rotation->current()); - static::assertSame(\count($input['dataset']), $rotation->count()); + self::assertSame($input['dataset'], $rotation->current()); + self::assertSame(count($input['dataset']), $rotation->count()); } } diff --git a/tests/src/Iterators/ShiftTest.php b/tests/src/Iterators/ShiftTest.php index 3934473..48a718d 100644 --- a/tests/src/Iterators/ShiftTest.php +++ b/tests/src/Iterators/ShiftTest.php @@ -1,5 +1,7 @@ next(); } - static::assertSame($expected['current'], $shift->current()); + self::assertSame($expected['current'], $shift->current()); - static::assertSame($input['dataset'], $shift->getDataset()); - static::assertSame($expected['count'], $shift->count()); + self::assertSame($input['dataset'], $shift->getDataset()); + self::assertSame($expected['count'], $shift->count()); } }