Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
[TASK] Migrate all PHP files to PSR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellienert committed Oct 15, 2015
1 parent 17d2314 commit d029735
Show file tree
Hide file tree
Showing 310 changed files with 24,129 additions and 23,074 deletions.
371 changes: 195 additions & 176 deletions Classes/Assertions/Assert.php

Large diffs are not rendered by default.

108 changes: 63 additions & 45 deletions Classes/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
* @author Michael Knoll
* @package Collection
*/
abstract class Tx_PtExtbase_Collection_Collection implements IteratorAggregate, Countable, ArrayAccess {

abstract class Tx_PtExtbase_Collection_Collection implements IteratorAggregate, Countable, ArrayAccess
{
/**
* @var array array containing items as values
*/
Expand Down Expand Up @@ -68,7 +68,8 @@ abstract class Tx_PtExtbase_Collection_Collection implements IteratorAggregate,
* @param void
* @return ArrayIterator object of type ArrayIterator: Iterator for items within this collection
*/
public function getIterator() {
public function getIterator()
{
$itemIterator = new ArrayIterator($this->itemsArr);
return $itemIterator;
}
Expand All @@ -85,7 +86,8 @@ public function getIterator() {
* @param void
* @return integer number of items in the items array
*/
public function count() {
public function count()
{
return count($this->itemsArr);
}

Expand All @@ -101,7 +103,8 @@ public function count() {
* @param mixed offset
* @return bool
*/
public function offsetExists($offset) {
public function offsetExists($offset)
{
return $this->hasItem($offset);
}

Expand All @@ -111,7 +114,8 @@ public function offsetExists($offset) {
* @param mixed offset
* @return mixed element of the collection
*/
public function offsetGet($offset) {
public function offsetGet($offset)
{
return $this->getItemById($offset);
}

Expand All @@ -121,7 +125,8 @@ public function offsetGet($offset) {
* @param mixed offset
* @param mixed value
*/
public function offsetSet($offset, $value) {
public function offsetSet($offset, $value)
{
$this->addItem($value, $offset);
}

Expand All @@ -130,7 +135,8 @@ public function offsetSet($offset, $value) {
*
* @param mixed offset
*/
public function offsetUnset($offset) {
public function offsetUnset($offset)
{
$this->deleteItem($offset);
}

Expand All @@ -145,15 +151,16 @@ public function offsetUnset($offset) {
* Here are the equivalent methods:
*/

/**
* Shift an element off the beginning of the collection
*
* @param bool $doNotModifyKeys (optional) if true key won't be modified, else numerical keys will be renumbered, default if false
* @return mixed item or NULL if collection is empty
*/
public function shift($doNotModifyKeys = false) {
/**
* Shift an element off the beginning of the collection
*
* @param bool $doNotModifyKeys (optional) if true key won't be modified, else numerical keys will be renumbered, default if false
* @return mixed item or NULL if collection is empty
*/
public function shift($doNotModifyKeys = false)
{
if (empty($this->itemsArr)) {
return NULL;
return null;
} elseif ($doNotModifyKeys == true) {
$keys = array_keys($this->itemsArr);
$element = $this->itemsArr[$keys[0]];
Expand All @@ -176,9 +183,10 @@ public function shift($doNotModifyKeys = false) {
* @param void
* @return mixed item or NULL if collection is empty
*/
public function pop() {
public function pop()
{
if (empty($this->itemsArr)) {
return NULL;
return null;
} else {
$keys = array_keys($this->itemsArr);
if ($this->selectedId == $keys[count($this->itemsArr)-1]) {
Expand All @@ -188,16 +196,17 @@ public function pop() {
}
}

/**
* Prepend one element to the beginning of the collection
* Multiple elements (like in array_unshift) are not supported!
*
* @param mixed $element element to prepend
* @param bool $doNotModifyKeys (optional) if true key won't be modified, else numerical keys will be renumbered, default if false
* @param mixed $useKey
* @return integer (optional) Returns the new number of elements in the collection
*/
public function unshift($element, $doNotModifyKeys = false, $useKey = NULL) {
/**
* Prepend one element to the beginning of the collection
* Multiple elements (like in array_unshift) are not supported!
*
* @param mixed $element element to prepend
* @param bool $doNotModifyKeys (optional) if true key won't be modified, else numerical keys will be renumbered, default if false
* @param mixed $useKey
* @return integer (optional) Returns the new number of elements in the collection
*/
public function unshift($element, $doNotModifyKeys = false, $useKey = null)
{
$this->checkItemType($element);

if ($doNotModifyKeys == true) {
Expand All @@ -224,7 +233,8 @@ public function unshift($element, $doNotModifyKeys = false, $useKey = NULL) {
* @param mixed element to append
* @return integer Returns the new number of elements in the collection
*/
public function push($element) {
public function push($element)
{
$this->checkItemType($element);

array_push($this->itemsArr, $element);
Expand All @@ -240,7 +250,8 @@ public function push($element) {
* @param bool $strict (optional) determines if strict comparision (===) should be used during the search.
* @return array Returns an array of all the keys
*/
public function keys($search_value = '', $strict = false) {
public function keys($search_value = '', $strict = false)
{
if ($search_value != '') {
$result = array_keys($this->itemsArr, $search_value, $strict);
} else {
Expand All @@ -263,7 +274,8 @@ public function keys($search_value = '', $strict = false) {
* @return void
* @throws Tx_PtExtbase_Exception_Internal if item to add to collection is of wrong type
*/
public function addItem($itemObj, $id = 0) {
public function addItem($itemObj, $id = 0)
{
// add item if item type is validated
if ($this->checkItemType($itemObj) == true) {
if ($id === 0) {
Expand All @@ -272,8 +284,8 @@ public function addItem($itemObj, $id = 0) {
$this->itemsArr[$id] = $itemObj;
}
} else {
// throw exception if item type is not validated
throw new Tx_PtExtbase_Exception_Internal('Item to add to collection is of wrong type (' . get_class($itemObj) . '). 1316764449' );
// throw exception if item type is not validated
throw new Tx_PtExtbase_Exception_Internal('Item to add to collection is of wrong type (' . get_class($itemObj) . '). 1316764449');
}
}

Expand All @@ -286,7 +298,8 @@ public function addItem($itemObj, $id = 0) {
* @return void
* @throws Tx_PtExtbase_Exception_Internal if trying to delete invalid id
*/
public function deleteItem($id) {
public function deleteItem($id)
{
if (isset($this->selectedId) && ($id == $this->selectedId)) {
$this->clearSelectedId();
}
Expand All @@ -305,7 +318,8 @@ public function deleteItem($id) {
* @param void
* @return void
*/
public function clearItems() {
public function clearItems()
{
$this->clearSelectedId();
$this->itemsArr = array();
}
Expand All @@ -318,7 +332,8 @@ public function clearItems() {
* @param mixed $id key of item to check for existance
* @return boolean item with this key exists
*/
public function hasItem($id) {
public function hasItem($id)
{
return array_key_exists($id, $this->itemsArr);
}

Expand All @@ -331,7 +346,8 @@ public function hasItem($id) {
* @return mixed item that has been requested
* @throws Tx_PtExtbase_Exception_Internal if requesting an invalid id
*/
public function &getItemById($id) {
public function &getItemById($id)
{
if ($this->hasItem($id)) {
return $this->itemsArr[$id];
} else {
Expand All @@ -349,7 +365,8 @@ public function &getItemById($id) {
* @remarks index starts with 0 for first element
* @throws Tx_PtExtbase_Exception_Internal if idx is invalid
*/
public function &getItemByIndex($idx) {
public function &getItemByIndex($idx)
{
// check parameters
$idx = intval($idx);
if (($idx < 0) || ($idx >= $this->count())) {
Expand All @@ -368,7 +385,8 @@ public function &getItemByIndex($idx) {
* @param mixed $itemObj
* @return boolean true by default in this parent class - individual implementations of this method (in inheriting classes) should return the item validation result as true or false
*/
protected function checkItemType($itemObj) {
protected function checkItemType($itemObj)
{
return true;
}

Expand All @@ -384,7 +402,8 @@ protected function checkItemType($itemObj) {
* @param void
* @return flexible property value
*/
public function getSelectedId() {
public function getSelectedId()
{
return $this->selectedId;
}

Expand All @@ -397,7 +416,8 @@ public function getSelectedId() {
* @return void
* @throws Tx_PtExtbase_Exception_Internal when parameter is not a valid item id
*/
public function setSelectedId($selectedId) {
public function setSelectedId($selectedId)
{
if ($this->hasItem($selectedId)) {
$this->selectedId = $selectedId;
} else {
Expand All @@ -413,10 +433,8 @@ public function setSelectedId($selectedId) {
* @param void
* @return void
*/
public function clearSelectedId() {
public function clearSelectedId()
{
unset($this->selectedId);
}

}

?>
55 changes: 28 additions & 27 deletions Classes/Collection/ObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,33 @@
* @author Michael Knoll
* @package Collection
*/
abstract class Tx_PtExtbase_Collection_ObjectCollection extends Tx_PtExtbase_Collection_Collection {
abstract class Tx_PtExtbase_Collection_ObjectCollection extends Tx_PtExtbase_Collection_Collection
{
/**
* if set, added objects will be type checked against this classname -
* this property should be set by your inheriting class if want to check the object type when adding an item
*
* @var string
*/
protected $restrictedClassName = null;

/**
* if set, added objects will be type checked against this classname -
* this property should be set by your inheriting class if want to check the object type when adding an item
*
* @var string
*/
protected $restrictedClassName = NULL;


/**
* Checks if the type of an item object matches the restrictedClassName
* (this property should be set in your inheriting class if want to check the object type when adding an item)
*
* Template method that overwrites behaviour of base class so that all
* items added to the collection are checked to implement / extend
* the type given in restrictedClassName property
*
* @param mixed object item to validate
* @return boolean true if object validation suceeded, false otherwise
*/
final protected function checkItemType($itemObj) {
if (!is_null($this->restrictedClassName) && !($itemObj instanceof $this->restrictedClassName)) {
return false;
}
return true;
}
}
/**
* Checks if the type of an item object matches the restrictedClassName
* (this property should be set in your inheriting class if want to check the object type when adding an item)
*
* Template method that overwrites behaviour of base class so that all
* items added to the collection are checked to implement / extend
* the type given in restrictedClassName property
*
* @param mixed object item to validate
* @return boolean true if object validation suceeded, false otherwise
*/
final protected function checkItemType($itemObj)
{
if (!is_null($this->restrictedClassName) && !($itemObj instanceof $this->restrictedClassName)) {
return false;
}
return true;
}
}
14 changes: 6 additions & 8 deletions Classes/Collection/SortableEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
* @package pt_extbase
* @subpackaga Collection
*/
interface Tx_PtExtbase_Collection_SortableEntityInterface {

/**
* @return integer Sorting value
*/
public function getSortingValue();

interface Tx_PtExtbase_Collection_SortableEntityInterface
{
/**
* @return integer Sorting value
*/
public function getSortingValue();
}
?>
Loading

0 comments on commit d029735

Please sign in to comment.