Skip to content

Commit

Permalink
Style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nibra committed Jul 21, 2020
1 parent 4f0de18 commit bf34723
Show file tree
Hide file tree
Showing 18 changed files with 952 additions and 968 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
autoload.php
vendor/
original/
42 changes: 21 additions & 21 deletions src/GreenCape/AllPairs/PairHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

namespace GreenCape\AllPairs;

use OutOfBoundsException;

class PairHash
{
private $data = array();
private $data = array();

public function set($i, $j, $value)
{
if (!isset($this->data[min($i, $j)]))
{
$this->data[min($i, $j)] = array();
}
$this->data[min($i, $j)][max($i, $j)] = $value;
}
public function set($i, $j, $value)
{
if (!isset($this->data[min($i, $j)])) {
$this->data[min($i, $j)] = array();
}
$this->data[min($i, $j)][max($i, $j)] = $value;
}

public function get($i, $j)
{
if (!isset($this->data[min($i, $j)]))
{
throw new \OutOfBoundsException();
}
if (!isset($this->data[min($i, $j)][max($i, $j)]))
{
throw new \OutOfBoundsException();
}
public function get($i, $j)
{
if (!isset($this->data[min($i, $j)])) {
throw new OutOfBoundsException("No value for [$i,$j]");
}

if (!isset($this->data[min($i, $j)][max($i, $j)])) {
throw new OutOfBoundsException("No value for [$i,$j]");
}

return $this->data[min($i, $j)][max($i, $j)];
}
return $this->data[min($i, $j)][max($i, $j)];
}
}
300 changes: 152 additions & 148 deletions src/GreenCape/AllPairs/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,153 +2,157 @@

namespace GreenCape\AllPairs;

class Parameter implements \ArrayAccess, \Countable, \Iterator
use ArrayAccess;
use Countable;
use Iterator;

class Parameter implements ArrayAccess, Countable, Iterator
{
private $label;

private $values;

private $current = 0;

public function __construct(array $values, $label = null)
{
if (is_null($label))
{
$label = uniqid();
}
$this->label = $label;
$this->values = array_values($values);
}

public function getLabel()
{
return $this->label;
}

public function getValues()
{
return $this->values;
}

/*
* ArrayAccess Interface
*/

/**
* Whether a offset exists
*
* @param mixed $offset An offset to check for.
*
* @return boolean true on success or false on failure.
*/
public function offsetExists($offset)
{
return (array_key_exists($offset, $this->values));
}

/**
* Offset to retrieve
*
* @param mixed $offset The offset to retrieve.
*
* @return mixed Can return all value types.
*/
public function offsetGet($offset)
{
return $this->values[$offset];
}

/**
* Offset to set
*
* @param mixed $offset The offset to assign the value to.
* @param mixed $value The value to set.
*
* @return void
*/
public function offsetSet($offset, $value)
{
$this->values[$offset] = $value;
}

/**
* Offset to unset
*
* @param mixed $offset The offset to unset.
*
* @return void
*/
public function offsetUnset($offset)
{
unset($this->values[$offset]);
}

/*
* Countable Interface
*/

/**
* Count elements of an object
*
* @return int The custom count as an integer.
*/
public function count()
{
return count($this->values);
}

/*
* Iterator Interface
*/

/**
* Return the current element
*
* @return mixed Can return any type.
*/
public function current()
{
return $this->values[$this->current];
}

/**
* Move forward to next element
*
* @return void
*/
public function next()
{
$this->current++;
}

/**
* Return the key of the current element
*
* @return int
*/
public function key()
{
return $this->current;
}

/**
* Checks if current position is valid
*
* @return boolean The return value will be casted to boolean and then evaluated.
* Returns true on success or false on failure.
*/
public function valid()
{
return isset($this->values[$this->current]);
}

/**
* Rewind the Iterator to the first element
*
* @return void
*/
public function rewind()
{
$this->current = 0;
}
private $label;

private $values;

private $current = 0;

public function __construct(array $values, $label = null)
{
if (is_null($label)) {
$label = uniqid('', true);
}
$this->label = $label;
$this->values = array_values($values);
}

public function getLabel()
{
return $this->label;
}

public function getValues()
{
return $this->values;
}

/*
* ArrayAccess Interface
*/

/**
* Whether a offset exists
*
* @param mixed $offset An offset to check for.
*
* @return boolean true on success or false on failure.
*/
public function offsetExists($offset)
{
return (array_key_exists($offset, $this->values));
}

/**
* Offset to retrieve
*
* @param mixed $offset The offset to retrieve.
*
* @return mixed Can return all value types.
*/
public function offsetGet($offset)
{
return $this->values[$offset];
}

/**
* Offset to set
*
* @param mixed $offset The offset to assign the value to.
* @param mixed $value The value to set.
*
* @return void
*/
public function offsetSet($offset, $value)
{
$this->values[$offset] = $value;
}

/**
* Offset to unset
*
* @param mixed $offset The offset to unset.
*
* @return void
*/
public function offsetUnset($offset)
{
unset($this->values[$offset]);
}

/*
* Countable Interface
*/

/**
* Count elements of an object
*
* @return int The custom count as an integer.
*/
public function count()
{
return count($this->values);
}

/*
* Iterator Interface
*/

/**
* Return the current element
*
* @return mixed Can return any type.
*/
public function current()
{
return $this->values[$this->current];
}

/**
* Move forward to next element
*
* @return void
*/
public function next()
{
$this->current++;
}

/**
* Return the key of the current element
*
* @return int
*/
public function key()
{
return $this->current;
}

/**
* Checks if current position is valid
*
* @return boolean The return value will be casted to boolean and then evaluated.
* Returns true on success or false on failure.
*/
public function valid()
{
return isset($this->values[$this->current]);
}

/**
* Rewind the Iterator to the first element
*
* @return void
*/
public function rewind()
{
$this->current = 0;
}
}
18 changes: 9 additions & 9 deletions src/GreenCape/AllPairs/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

interface Reader
{
/**
* @param string $labelDelimiter
* @param string $valueDelimiter
*
* @return Parameter[]
*/
public function getParameters();
/**
* @param string $labelDelimiter
* @param string $valueDelimiter
*
* @return Parameter[]
*/
public function getParameters($labelDelimiter = ':', $valueDelimiter = ',');

public function getSubModules();
public function getSubModules();

public function getConstraints();
public function getConstraints();
}
8 changes: 4 additions & 4 deletions src/GreenCape/AllPairs/Reader/FileReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class FileReader extends StringReader
{
public function __construct($file)
{
parent::__construct(file_get_contents($file));
}
public function __construct($file)
{
parent::__construct(file_get_contents($file));
}
}
Loading

0 comments on commit bf34723

Please sign in to comment.