🎨 Adjust spacing and PHPDoc

This commit is contained in:
Flavio Copes
2016-01-28 13:32:18 +01:00
parent 2d49054a95
commit d440739b8b

View File

@@ -8,7 +8,7 @@ use Grav\Common\Utils;
/**
* Collection of Pages.
*
* @author RocketTheme
* @author RocketTheme
* @license MIT
*/
class Collection extends Iterator
@@ -23,7 +23,14 @@ class Collection extends Iterator
*/
protected $params;
public function __construct($items = array(), array $params = array(), Pages $pages = null)
/**
* Collection constructor.
*
* @param array $items
* @param array $params
* @param Pages|null $pages
*/
public function __construct($items = [], array $params = [], Pages $pages = null)
{
parent::__construct($items);
@@ -31,6 +38,11 @@ class Collection extends Iterator
$this->pages = $pages ? $pages : Grav::instance()->offsetGet('pages');
}
/**
* Get the collection params
*
* @return array
*/
public function params()
{
return $this->params;
@@ -40,11 +52,13 @@ class Collection extends Iterator
* Add a single page to a collection
*
* @param Page $page
*
* @return $this
*/
public function addPage(Page $page)
{
$this->items[$page->path()] = ['slug' => $page->slug()];
return $this;
}
@@ -63,11 +77,13 @@ class Collection extends Iterator
* Set parameters to the Collection
*
* @param array $params
*
* @return $this
*/
public function setParams(array $params)
{
$this->params = array_merge($this->params, $params);
return $this;
}
@@ -79,6 +95,7 @@ class Collection extends Iterator
public function current()
{
$current = parent::key();
return $this->pages->get($current);
}
@@ -90,13 +107,15 @@ class Collection extends Iterator
public function key()
{
$current = parent::current();
return $current['slug'];
}
/**
* Returns the value at specified offset.
*
* @param mixed $offset The offset to retrieve.
* @param mixed $offset The offset to retrieve.
*
* @return mixed Can return all value types.
*/
public function offsetGet($offset)
@@ -108,6 +127,7 @@ class Collection extends Iterator
* Remove item from the list.
*
* @param Page|string|null $key
*
* @return $this|void
* @throws \InvalidArgumentException
*/
@@ -123,6 +143,7 @@ class Collection extends Iterator
}
parent::remove($key);
return $this;
}
@@ -132,6 +153,7 @@ class Collection extends Iterator
* @param string $by
* @param string $dir
* @param array $manual
*
* @return $this
*/
public function order($by, $dir = 'asc', $manual = null)
@@ -145,6 +167,7 @@ class Collection extends Iterator
* Check to see if this item is the first in the collection.
*
* @param string $path
*
* @return boolean True if item is first.
*/
public function isFirst($path)
@@ -160,11 +183,12 @@ class Collection extends Iterator
* Check to see if this item is the last in the collection.
*
* @param string $path
*
* @return boolean True if item is last.
*/
public function isLast($path)
{
if ($this->items && $path == array_keys($this->items)[count($this->items)-1]) {
if ($this->items && $path == array_keys($this->items)[count($this->items) - 1]) {
return true;
} else {
return false;
@@ -174,7 +198,8 @@ class Collection extends Iterator
/**
* Gets the previous sibling based on current position.
*
* @param string $path
* @param string $path
*
* @return Page The previous item.
*/
public function prevSibling($path)
@@ -185,7 +210,8 @@ class Collection extends Iterator
/**
* Gets the next sibling based on current position.
*
* @param string $path
* @param string $path
*
* @return Page The next item.
*/
public function nextSibling($path)
@@ -198,6 +224,7 @@ class Collection extends Iterator
*
* @param string $path
* @param integer $direction either -1 or +1
*
* @return Page The sibling item.
*/
public function adjacentSibling($path, $direction = 1)
@@ -210,6 +237,7 @@ class Collection extends Iterator
return isset($values[$index]) ? $this->offsetGet($values[$index]) : $this;
}
return $this;
}
@@ -217,7 +245,8 @@ class Collection extends Iterator
/**
* Returns the item in the current position.
*
* @param string $path the path the item
* @param string $path the path the item
*
* @return Page Item in the array the the current position.
*/
public function currentPosition($path)
@@ -256,6 +285,7 @@ class Collection extends Iterator
}
}
$this->items = $date_range;
return $this;
}
@@ -275,6 +305,7 @@ class Collection extends Iterator
}
}
$this->items = $visible;
return $this;
}
@@ -294,6 +325,7 @@ class Collection extends Iterator
}
}
$this->items = $visible;
return $this;
}
@@ -313,6 +345,7 @@ class Collection extends Iterator
}
}
$this->items = $modular;
return $this;
}
@@ -332,6 +365,7 @@ class Collection extends Iterator
}
}
$this->items = $modular;
return $this;
}
@@ -351,6 +385,7 @@ class Collection extends Iterator
}
}
$this->items = $published;
return $this;
}
@@ -370,6 +405,7 @@ class Collection extends Iterator
}
}
$this->items = $published;
return $this;
}
@@ -391,6 +427,7 @@ class Collection extends Iterator
}
$this->items = $routable;
return $this;
}
@@ -410,12 +447,15 @@ class Collection extends Iterator
}
}
$this->items = $routable;
return $this;
}
/**
* Creates new collection with only pages of the specified type
*
* @param $type
*
* @return Collection The collection
*/
public function ofType($type)
@@ -430,12 +470,15 @@ class Collection extends Iterator
}
$this->items = $items;
return $this;
}
/**
* Creates new collection with only pages of one of the specified types
*
* @param $types
*
* @return Collection The collection
*/
public function ofOneOfTheseTypes($types)
@@ -450,12 +493,15 @@ class Collection extends Iterator
}
$this->items = $items;
return $this;
}
/**
* Creates new collection with only pages of one of the specified access levels
*
* @param $accessLevels
*
* @return Collection The collection
*/
public function ofOneOfTheseAccessLevels($accessLevels)
@@ -472,7 +518,7 @@ class Collection extends Iterator
foreach ($page->header()->access as $index => $accessLevel) {
if (is_array($accessLevel)) {
foreach($accessLevel as $innerIndex => $innerAccessLevel) {
foreach ($accessLevel as $innerIndex => $innerAccessLevel) {
if (in_array($innerAccessLevel, $accessLevels)) {
$valid = true;
}
@@ -497,11 +543,7 @@ class Collection extends Iterator
}
$this->items = $items;
return $this;
}
}