Skip to content

Commit 8617aec

Browse files
committed
Refactoring.
1 parent 4dc6c2c commit 8617aec

Some content is hidden

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

51 files changed

+550
-743
lines changed

.php_cs.dist

Lines changed: 0 additions & 33 deletions
This file was deleted.

.scrutinizer.yml

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
build:
2-
environment:
3-
php: '5.6'
2+
nodes:
3+
analysis:
4+
tests:
5+
override:
6+
- php-scrutinizer-run
47

58
filter:
69
paths:
@@ -9,52 +12,6 @@ filter:
912
tools:
1013
external_code_coverage:
1114
timeout: 600
12-
php_mess_detector:
13-
config:
14-
code_size_rules: { cyclomatic_complexity: true, npath_complexity: true, excessive_method_length: true, excessive_class_length: true, excessive_parameter_list: true, excessive_public_count: true, too_many_fields: true, too_many_methods: true, excessive_class_complexity: true }
15-
design_rules: { number_of_class_children: true, depth_of_inheritance: true, coupling_between_objects: true }
16-
unused_code_rules: { unused_local_variable: true, unused_private_method: true, unused_formal_parameter: true }
17-
naming_rules: { short_variable: true, long_variable: true, short_method: true, boolean_method_name: true }
18-
controversial_rules: { camel_case_class_name: true, camel_case_property_name: true, camel_case_method_name: true, camel_case_parameter_name: true, camel_case_variable_name: true }
19-
php_cs_fixer:
20-
config:
21-
level: all
22-
fixers: { unused_use: true, phpdoc_params: true, braces: true, php_closing_tag: true }
23-
php_analyzer:
24-
config:
25-
suspicious_code: { enabled: true, overriding_parameter: true, overriding_closure_use: true, parameter_closure_use_conflict: true, parameter_multiple_times: true, non_existent_class_in_instanceof_check: true, non_existent_class_in_catch_clause: true, assignment_of_null_return: true, non_commented_switch_fallthrough: true, non_commented_empty_catch_block: true, overriding_private_members: true, use_statement_alias_conflict: true, precedence_in_condition_assignment: true }
26-
verify_php_doc_comments: { enabled: true, parameters: true, return: true, suggest_more_specific_types: true, ask_for_return_if_not_inferrable: true, ask_for_param_type_annotation: true }
27-
loops_must_use_braces: { enabled: true }
28-
simplify_boolean_return: { enabled: true }
29-
phpunit_checks: { enabled: true }
30-
reflection_fixes: { enabled: true }
31-
use_statement_fixes: { enabled: true, order_alphabetically: true, remove_unused: true, preserve_multiple: false, preserve_blanklines: false }
32-
parameter_reference_check: { enabled: false }
33-
checkstyle: { enabled: false, no_trailing_whitespace: true, naming: { enabled: true, local_variable: '^[a-z][a-zA-Z0-9]*$', abstract_class_name: ^Abstract|Factory$, utility_class_name: 'Utils?$', constant_name: '^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$', property_name: '^[a-z][a-zA-Z0-9]*$', method_name: '^(?:[a-z]|__)[a-zA-Z0-9]*$', parameter_name: '^[a-z][a-zA-Z0-9]*$', interface_name: '^[A-Z][a-zA-Z0-9]*Interface$', type_name: '^[A-Z][a-zA-Z0-9]*$', exception_name: '^[A-Z][a-zA-Z0-9]*Exception$', isser_method_name: '^(?:is|has|should|may|supports)' } }
34-
unreachable_code: { enabled: false }
35-
check_access_control: { enabled: false }
36-
typo_checks: { enabled: false }
37-
check_variables: { enabled: false }
38-
check_calls: { enabled: true, too_many_arguments: true, missing_argument: true, argument_type_checks: lenient }
39-
dead_assignments: { enabled: false }
40-
check_usage_context: { enabled: true, foreach: { value_as_reference: true, traversable: true } }
41-
reflection_checks: { enabled: false }
42-
precedence_checks: { enabled: true, assignment_in_condition: true, comparison_of_bit_result: true }
43-
basic_semantic_checks: { enabled: false }
44-
unused_code: { enabled: false }
45-
deprecation_checks: { enabled: false }
46-
useless_function_calls: { enabled: false }
47-
metrics_lack_of_cohesion_methods: { enabled: false }
48-
metrics_coupling: { enabled: true, stable_code: { namespace_prefixes: { }, classes: { } } }
49-
doctrine_parameter_binding: { enabled: false }
50-
doctrine_entity_manager_injection: { enabled: false }
51-
symfony_request_injection: { enabled: false }
52-
doc_comment_fixes: { enabled: false }
53-
php_code_sniffer:
54-
config:
55-
standard: PSR2
56-
sniffs: { psr2: { classes: { property_declaration_sniff: true }, methods: { method_declaration_sniff: true } } }
57-
sensiolabs_security_checker: true
5815
php_loc: true
5916
php_pdepend: true
6017
php_sim: true

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ php:
1212
- 5.6
1313
- 7.1
1414
- 7.2
15+
- 7.3
1516

1617
install:
1718
- composer install
1819

1920
script:
20-
- composer phpunit
2121
- composer grumphp
2222

2323
after_success:

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ objects), the library will still continue to work without any trouble.
3434
## Requirements
3535

3636
* PHP >= 5.6,
37-
* (optional) [PHPUnit](https://phpunit.de/) to run tests.
3837

3938
## How to use
4039

composer.json

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drupol/phpermutations",
3-
"description": "Generate iterators for array permutations in an efficient way.",
3+
"description": "Generators and iterators, permutations and combinations.",
44
"type": "library",
55
"homepage": "https://github.com/drupol/phpermutations",
66
"keywords": ["math", "numbers", "permutations", "combinations", "iterators", "fibonacci", "prime numbers", "product"],
@@ -9,7 +9,6 @@
99
"issues": "https://github.com/drupol/phpermutations/issues",
1010
"source": "https://github.com/drupol/phpermutations"
1111
},
12-
"minimum-stability": "stable",
1312
"authors": [
1413
{
1514
"name": "Pol Dellaiera",
@@ -20,20 +19,10 @@
2019
"php": ">= 5.6"
2120
},
2221
"require-dev": {
23-
"phpunit/phpunit": "^5.7",
24-
"mockery/mockery": "^0.9",
25-
"squizlabs/php_codesniffer": "^2.0",
26-
"satooshi/php-coveralls": "^1.0",
27-
"phpunit/php-code-coverage": "^4.0",
28-
"scrutinizer/ocular": "^1.3",
29-
"phpro/grumphp": "^0.13",
30-
"jakub-onderka/php-parallel-lint": "^0.9.2",
31-
"nikic/php-parser": "~2.1",
32-
"sensiolabs/security-checker": "^4.1",
33-
"phpmd/phpmd": "^2.6",
34-
"sebastian/phpcpd": "^3.0",
35-
"friendsofphp/php-cs-fixer": "^2.10"
36-
22+
"drupol/php-conventions": "^1.3",
23+
"phpunit/phpunit": "^6",
24+
"phpunit/php-code-coverage": "^5.0",
25+
"scrutinizer/ocular": "^1.3"
3726
},
3827
"scripts": {
3928
"phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c tests/phpunit.xml tests",
@@ -45,5 +34,8 @@
4534
"drupol\\phpermutations\\": "src/",
4635
"drupol\\phpermutations\\Tests\\": "tests/src/"
4736
}
37+
},
38+
"config": {
39+
"sort-packages": true
4840
}
4941
}

examples/e.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*/
2222
include './vendor/autoload.php';
2323

24-
for ($i = 2; $i < 15; ++$i) {
25-
$input = range(1, $i);
24+
for ($i = 2; 15 > $i; ++$i) {
25+
$input = \range(1, $i);
2626
$size = $i;
2727

2828
echo '**********************************************************' . "\n";
@@ -32,7 +32,7 @@
3232

3333
$j = 0;
3434
foreach ($Permutations->generator() as $permutation) {
35-
if (!($array3 = array_intersect_assoc($input, $permutation))) {
35+
if (!($array3 = \array_intersect_assoc($input, $permutation))) {
3636
++$j;
3737
}
3838
}

examples/pi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
$Fibonacci = new \drupol\phpermutations\Generators\Fibonacci();
3434

35-
for ($i = 2; $i <= 50; $i = $i + 2) {
35+
for ($i = 2; 50 >= $i; $i = $i + 2) {
3636
$gen = $Fibonacci->generator();
3737

3838
$input = [];
@@ -41,9 +41,9 @@
4141
$gen->next();
4242
}
4343

44-
$input = array_sum(array_filter(array_map(function ($item) {
45-
return 4 * atan(1 / $item);
46-
}, array_slice($input, 3)), function ($key) {
44+
$input = \array_sum(\array_filter(\array_map(function ($item) {
45+
return 4 * \atan(1 / $item);
46+
}, \array_slice($input, 3)), function ($key) {
4747
return !($key % 2);
4848
}, ARRAY_FILTER_USE_KEY));
4949

grumphp.yml.dist

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1+
imports:
2+
- { resource: vendor/drupol/php-conventions/config/php56/grumphp.yml }
3+
14
parameters:
25
git_dir: .
36
bin_dir: bin
4-
tasks:
5-
phpcsfixer2:
6-
allow_risky: false
7-
cache_file: ~
8-
config: .php_cs.dist
9-
rules: []
10-
using_cache: true
11-
config_contains_finder: true
12-
verbose: true
13-
diff: true
14-
triggered_by: ['php']
15-
git_commit_message:
16-
matchers:
17-
- '/^(([A-Z]+\-\d+)|(#\d+)): [A-Z].+\./'
18-
case_insensitive: false
19-
multiline: false
7+
extensions:
8+
- drupol\PhpConventions\GrumphpTasksExtension
9+
extra_tasks:
2010
phpunit:
2111
config_file: ./tests/phpunit.xml
2212
testsuite: ~
2313
group: []
2414
always_execute: false
25-
securitychecker:
26-
lockfile: ./composer.lock
27-
format: ~
28-
end_point: ~
29-
timeout: ~
30-
run_always: false

src/Combinatorics.php

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Class Combinatorics.
77
*/
8-
abstract class Combinatorics implements \Countable
8+
abstract class Combinatorics
99
{
1010
/**
1111
* The dataset.
@@ -33,30 +33,36 @@ abstract class Combinatorics implements \Countable
3333
*
3434
* @param array $dataset
3535
* The dataset
36-
* @param int|null $length
36+
* @param null|int $length
3737
* The length
3838
*/
3939
public function __construct(array $dataset = [], $length = null)
4040
{
4141
$this->setDataset($dataset);
42-
$this->datasetCount = count($this->dataset);
42+
$this->datasetCount = \count($this->dataset);
4343
$this->setLength($length);
4444
}
4545

4646
/**
47-
* Set the length.
48-
*
49-
* @param int $length
50-
* The length
47+
* Count elements of an object.
5148
*
52-
* @return $this
49+
* @return int
50+
* The number of element
5351
*/
54-
public function setLength($length = null)
52+
public function count()
5553
{
56-
$length = (null === $length) ? $this->datasetCount : $length;
57-
$this->length = ($length > $this->datasetCount) ? $this->datasetCount : $length;
54+
return \count($this->toArray());
55+
}
5856

59-
return $this;
57+
/**
58+
* Get the dataset.
59+
*
60+
* @return mixed[]
61+
* The dataset
62+
*/
63+
public function getDataset()
64+
{
65+
return $this->dataset;
6066
}
6167

6268
/**
@@ -86,50 +92,27 @@ public function setDataset(array $dataset = [])
8692
}
8793

8894
/**
89-
* Get the dataset.
95+
* Set the length.
9096
*
91-
* @return mixed[]
92-
* The dataset
93-
*/
94-
public function getDataset()
95-
{
96-
return $this->dataset;
97-
}
98-
99-
/**
100-
* Count elements of an object.
97+
* @param null|int $length
98+
* The length
10199
*
102-
* @return int
103-
* The number of element
100+
* @return $this
104101
*/
105-
public function count()
102+
public function setLength($length = null)
106103
{
107-
return count($this->toArray());
104+
$length = (null === $length) ? $this->datasetCount : $length;
105+
$this->length = (\abs($length) > $this->datasetCount) ? $this->datasetCount : $length;
106+
107+
return $this;
108108
}
109109

110110
/**
111-
* Convert the iterator into an array.
112-
*
113111
* @return array
114-
* The elements
115112
*/
116113
public function toArray()
117114
{
118-
$data = [];
119-
120-
for ($this->rewind(); $this->valid(); $this->next()) {
121-
$data[] = $this->current();
122-
}
123-
124-
return $data;
125-
}
126-
127-
/**
128-
* {@inheritdoc}
129-
*/
130-
public function key()
131-
{
132-
return $this->key;
115+
return [];
133116
}
134117

135118
/**
@@ -145,6 +128,6 @@ public function key()
145128
*/
146129
protected function fact($n, $total = 1)
147130
{
148-
return ($n < 2) ? $total : $this->fact($n - 1, $total * $n);
131+
return (2 > $n) ? $total : $this->fact($n - 1, $total * $n);
149132
}
150133
}

0 commit comments

Comments
 (0)