for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace drupol\phpermutations;
/**
* Class Permutations.
*
* @package drupol\phpermutations
*/
class Permutations {
* @var mixed
protected $elements;
* @var int
protected $size;
* Permutations constructor.
* @param array $elements
* @param int $size
public function __construct(array $elements, $size = NULL) {
$this->setElements($elements);
$size = $size ? $size : count($elements);
$this->setSize($size);
return $this;
}
public function setSize($size) {
$this->size = $size;
* @return int
public function getSize() {
return (int) $this->size;
* @return $this
public function setElements(array $elements) {
$this->elements = $elements;
* @return mixed
public function getElements() {
return $this->elements;
* @return \Generator
public function generator() {
return $this->generate($this->getElements(), $this->getSize());
protected function generate(array $elements, $length) {
$length
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
if (count($elements) <= 1) {
yield $elements;
} else {
foreach ($this->generate(array_slice($elements, 1)) as $permutation) {
generate()
This check looks for function calls that miss required arguments.
foreach (range(0, count($elements) - 1) as $i) {
yield array_merge(
array_slice($permutation, 0, $i),
[$elements[0]],
array_slice($permutation, $i)
);
* @return array
public function toArray() {
$results = array();
foreach($this->generator() as $key => $value) {
$results[$key] = $value;
return $results;