Skip to content

Commit

Permalink
Update minimum requirement to PHP 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Aug 6, 2018
1 parent 9884606 commit 82485dc
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 115 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017 Trilby Media, LLC
Copyright (c) 2018 Trilby Media, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 14 additions & 6 deletions classes/Flex.php
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Grav\Plugin\FlexObjects;

use Grav\Common\Filesystem\Folder;
Expand All @@ -12,7 +14,7 @@ class Flex implements \Countable
/** @var array|FlexDirectory[] */
protected $types = [];

public function __construct(array $types = [], array $config)
public function __construct(array $types, array $config)
{
$defaults = ['enabled' => true] + $config['object'];

Expand All @@ -21,7 +23,10 @@ public function __construct(array $types = [], array $config)
}
}

public function getAll()
/**
* @return array
*/
public function getAll() : array
{
$params = [
'pattern' => '|\.yaml|',
Expand All @@ -44,7 +49,10 @@ public function getAll()
return $directories;
}

public function getDirectories()
/**
* @return array
*/
public function getDirectories() : array
{
return $this->types;
}
Expand All @@ -53,19 +61,19 @@ public function getDirectories()
* @param string|null $type
* @return FlexDirectory|null
*/
public function getDirectory($type = null)
public function getDirectory($type = null) : ?FlexDirectory
{
if (!$type) {
return reset($this->types) ?: null;
}

return isset($this->types[$type]) ? $this->types[$type] : null;
return $this->types[$type] ?? null;
}

/**
* @return int
*/
public function count()
public function count() : int
{
return \count($this->types);
}
Expand Down
2 changes: 1 addition & 1 deletion classes/FlexCollection.php
Expand Up @@ -42,7 +42,7 @@ public static function getCachedMethods()

/**
* @param array $elements
* @param FlexDirectory $type
* @param FlexDirectory|null $flexDirectory
* @throws \InvalidArgumentException
*/
public function __construct(array $elements = [], FlexDirectory $flexDirectory = null)
Expand Down
59 changes: 30 additions & 29 deletions classes/FlexDirectory.php
Expand Up @@ -10,6 +10,7 @@
use Grav\Framework\Cache\Adapter\DoctrineCache;
use Grav\Framework\Cache\Adapter\MemoryCache;
use Grav\Framework\Cache\CacheInterface;
use Grav\Framework\Collection\CollectionInterface;
use Grav\Plugin\FlexObjects\Storage\SimpleStorage;
use Grav\Plugin\FlexObjects\Storage\StorageInterface;
use Psr\SimpleCache\InvalidArgumentException;
Expand Down Expand Up @@ -51,7 +52,7 @@ class FlexDirectory
* @param string $blueprint_file
* @param array $defaults
*/
public function __construct($type, $blueprint_file, $defaults = [])
public function __construct(string $type, string $blueprint_file, array $defaults = [])
{
$this->type = $type;
$this->blueprint_file = $blueprint_file;
Expand All @@ -62,31 +63,31 @@ public function __construct($type, $blueprint_file, $defaults = [])
/**
* @return bool
*/
public function isEnabled()
public function isEnabled() : bool
{
return $this->enabled;
}

/**
* @return string
*/
public function getType()
public function getType() : string
{
return $this->type;
}

/**
* @return string
*/
public function getTitle()
public function getTitle() : string
{
return $this->getBlueprint()->get('title', ucfirst($this->getType()));
}

/**
* @return string
*/
public function getDescription()
public function getDescription() : string
{
return $this->getBlueprint()->get('description', '');
}
Expand All @@ -96,7 +97,7 @@ public function getDescription()
* @param mixed $default
* @return mixed
*/
public function getConfig($name = null, $default = null)
public function getConfig(string $name = null, $default = null)
{
if (null === $this->config) {
$this->config = new Config(array_merge_recursive($this->getBlueprint()->get('config'), $this->defaults));
Expand All @@ -108,7 +109,7 @@ public function getConfig($name = null, $default = null)
/**
* @return Blueprint
*/
public function getBlueprint()
public function getBlueprint() : Blueprint
{
if (null === $this->blueprint) {
$this->blueprint = (new Blueprint($this->blueprint_file))->load();
Expand All @@ -128,16 +129,16 @@ public function getBlueprint()
/**
* @return string
*/
public function getBlueprintFile()
public function getBlueprintFile() : string
{
return $this->blueprint_file;
}

/**
* @param array|null $keys Array of keys.
* @return FlexIndex
* @return FlexIndex|FlexCollection
*/
public function getCollection(array $keys = null)
public function getCollection(array $keys = null) : CollectionInterface
{
$index = clone $this->getIndex($keys);

Expand All @@ -155,7 +156,7 @@ public function getCollection(array $keys = null)
* @param string $key
* @return FlexObject|null
*/
public function getObject($key)
public function getObject($key) : ?FlexObject
{
return $this->getCollection()->get($key);
}
Expand All @@ -166,7 +167,7 @@ public function getObject($key)
* @param bool $isFullUpdate
* @return FlexObject
*/
public function update(array $data, $key = null, $isFullUpdate = false)
public function update(array $data, string $key = null, bool $isFullUpdate = false) : FlexObject
{
$object = null !== $key ? $this->getIndex()->get($key) : null;

Expand Down Expand Up @@ -219,7 +220,7 @@ public function update(array $data, $key = null, $isFullUpdate = false)
* @param string $key
* @return FlexObject|null
*/
public function remove($key)
public function remove(string $key) : ?FlexObject
{
$object = null !== $key ? $this->getIndex()->get($key) : null;
if (!$object) {
Expand All @@ -245,7 +246,7 @@ public function remove($key)
* @param string|null $namespace
* @return CacheInterface
*/
public function getCache($namespace = null)
public function getCache(string $namespace = null) : CacheInterface
{
$namespace = $namespace ?: 'index';

Expand Down Expand Up @@ -281,7 +282,7 @@ public function getCache($namespace = null)
/**
* @return $this
*/
public function clearCache()
public function clearCache() : self
{
/** @var Debugger $debugger */
$debugger = Grav::instance()['debugger'];
Expand All @@ -298,7 +299,7 @@ public function clearCache()
* @param string|null $key
* @return string
*/
public function getStorageFolder($key = null)
public function getStorageFolder(string $key = null) : string
{
return $this->getStorage()->getStoragePath($key);
}
Expand All @@ -307,15 +308,15 @@ public function getStorageFolder($key = null)
* @param string|null $key
* @return string
*/
public function getMediaFolder($key = null)
public function getMediaFolder(string $key = null) : string
{
return $this->getStorage()->getMediaPath($key);
}

/**
* @return StorageInterface
*/
public function getStorage()
public function getStorage() : StorageInterface
{
if (!$this->storage) {
$this->storage = $this->createStorage();
Expand All @@ -326,10 +327,10 @@ public function getStorage()

/**
* @param array|null $keys Array of keys.
* @return FlexIndex
* @return FlexIndex|FlexCollection
* @internal
*/
public function getIndex(array $keys = null)
public function getIndex(array $keys = null) : CollectionInterface
{
$index = clone $this->loadIndex();

Expand All @@ -346,7 +347,7 @@ public function getIndex(array $keys = null)
* @param bool $validate
* @return FlexObject
*/
public function createObject(array $data, $key, $validate = false)
public function createObject(array $data, string $key, bool $validate = false) : FlexObject
{
$className = $this->objectClassName ?: $this->getObjectClass();

Expand All @@ -357,7 +358,7 @@ public function createObject(array $data, $key, $validate = false)
* @param array $entries
* @return FlexCollection
*/
public function createCollection(array $entries)
public function createCollection(array $entries) : FlexCollection
{
$className = $this->collectionClassName ?: $this->getCollectionClass();

Expand All @@ -367,7 +368,7 @@ public function createCollection(array $entries)
/**
* @return string
*/
public function getObjectClass()
public function getObjectClass() : string
{
if (!$this->objectClassName) {
$this->objectClassName = $this->getConfig('data.object', 'Grav\\Plugin\\FlexObjects\\FlexObject');
Expand All @@ -379,7 +380,7 @@ public function getObjectClass()
/**
* @return string
*/
public function getCollectionClass()
public function getCollectionClass() : string
{
if (!$this->collectionClassName) {
$this->collectionClassName = $this->getConfig('data.collection', 'Grav\\Plugin\\FlexObjects\\FlexCollection');
Expand All @@ -391,7 +392,7 @@ public function getCollectionClass()
* @param array $entries
* @return FlexCollection
*/
public function loadCollection(array $entries)
public function loadCollection(array $entries) : FlexCollection
{
return $this->createCollection($this->loadObjects($entries));
}
Expand All @@ -400,7 +401,7 @@ public function loadCollection(array $entries)
* @param array $entries
* @return FlexObject[]
*/
public function loadObjects(array $entries)
public function loadObjects(array $entries) : array
{
/** @var Debugger $debugger */
$debugger = Grav::instance()['debugger'];
Expand Down Expand Up @@ -462,7 +463,7 @@ public function loadObjects(array $entries)
/**
* @return StorageInterface
*/
protected function createStorage()
protected function createStorage() : StorageInterface
{
$this->collection = $this->createCollection([]);

Expand All @@ -479,9 +480,9 @@ protected function createStorage()
}

/**
* @return FlexIndex
* @return FlexIndex|FlexCollection
*/
protected function loadIndex()
protected function loadIndex() : CollectionInterface
{
static $i = 0;

Expand Down
4 changes: 2 additions & 2 deletions classes/FlexIndex.php
Expand Up @@ -8,13 +8,13 @@
use Grav\Plugin\FlexObjects\Collections\ArrayIndex;
use PSR\SimpleCache\InvalidArgumentException;

class FlexIndex extends ArrayIndex // implements ObjectCollectionInterface
class FlexIndex extends ArrayIndex // implements FlexCollectionInterface
{
/** @var FlexDirectory */
private $flexDirectory;

/**
* Initializes a new IndexCollection.
* Initializes a new FlexIndex.
*
* @param array $entries
* @param FlexDirectory $flexDirectory
Expand Down

0 comments on commit 82485dc

Please sign in to comment.