Skip to content

Commit

Permalink
add some strong-typing and fix docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
wyrfel committed Jun 8, 2017
1 parent 991d530 commit 7ad219a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
18 changes: 9 additions & 9 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public static function getInstance()

/**
* @param $name
* @return mixed
* @return Space
*/
public function getSpace($name)
public function getSpace($name): Space
{
$name = strtolower($name);

Expand All @@ -64,19 +64,19 @@ public function getSpace($name)

/**
* @param $path
* @return $this
* @return Factory
*/
public function setCachePath($path)
public function setCachePath($path): Factory
{
$this->cachePath = $path;

return $this;
}

/**
* @return mixed
* @return string
*/
public function getCachePath()
public function getCachePath(): string
{
if (null === $this->cachePath) {
throw new PreconditionException('Cache path has not been set.');
Expand All @@ -88,7 +88,7 @@ public function getCachePath()
/**
* @return Cache
*/
public function getCache()
public function getCache(): Cache
{
if (null === $this->cache) {
$this->cache = new Cache($this->getCachePath());
Expand All @@ -99,9 +99,9 @@ public function getCache()

/**
* @param Cache $cache
* @return $this
* @return Factory
*/
public function setCache(Cache $cache)
public function setCache(Cache $cache): Factory
{
$this->cache = $cache;

Expand Down
55 changes: 29 additions & 26 deletions src/Space.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class Space

/**
* Space constructor.
* @param $name
* @param string $name
*/
public function __construct($name)
public function __construct(string $name)
{
$this->name = $name;
}
Expand All @@ -78,7 +78,7 @@ public function get($key = null, $default = null)
/**
* @return array
*/
public function flatten()
public function flatten(): array
{
$this->init();

Expand Down Expand Up @@ -114,7 +114,7 @@ protected function init()
*
* @return array the parsed and flattened config array
*/
protected function parse()
protected function parse(): array
{
$parser = $this->getParser();

Expand All @@ -134,7 +134,7 @@ protected function parse()
* @param array $config
* @return array
*/
protected function replacePlaceholders(array $config)
protected function replacePlaceholders(array $config): array
{
if (empty($this->placeholders)) {
return $config;
Expand All @@ -157,7 +157,7 @@ protected function replacePlaceholders(array $config)
/**
* @return int
*/
protected function getTimestamp()
protected function getTimestamp(): int
{
$timestamp = 0;
foreach ($this->getReadableSources() as $path) {
Expand All @@ -173,7 +173,7 @@ protected function getTimestamp()
*
* @return array
*/
protected function getReadableSources()
protected function getReadableSources(): array
{
$paths = [];

Expand All @@ -192,7 +192,7 @@ protected function getReadableSources()
* @param array $config the raw config array
* @return array the flattened config array
*/
protected function flattenSections(array $config)
protected function flattenSections(array $config): array
{
$merged = [];

Expand Down Expand Up @@ -220,7 +220,7 @@ protected function flattenSections(array $config)
*
* @return Cache
*/
public function getCache()
public function getCache(): Cache
{
return $this->cache;
}
Expand All @@ -229,9 +229,9 @@ public function getCache()
* set the config cache handler
*
* @param Cache $cache
* @return $this
* @return Space
*/
public function setCache(Cache $cache)
public function setCache(Cache $cache): Space
{
$this->cache = $cache;

Expand All @@ -243,7 +243,7 @@ public function setCache(Cache $cache)
*
* @return array
*/
public function getSections()
public function getSections(): array
{
return $this->sections;
}
Expand All @@ -252,9 +252,9 @@ public function getSections()
* set the sections to use
*
* @param array $sections
* @return $this
* @return Space
*/
public function setSections(array $sections)
public function setSections(array $sections): Space
{
$this->sections = $sections;

Expand All @@ -263,9 +263,9 @@ public function setSections(array $sections)

/**
* @param string $section
* @return $this
* @return Space
*/
public function addSection(string $section)
public function addSection(string $section): Space
{
if (!in_array($section, $this->sections)) {
$this->sections[] = $section;
Expand All @@ -279,7 +279,7 @@ public function addSection(string $section)
*
* @return Parser
*/
public function getParser()
public function getParser(): Parser
{
if (null === $this->parser) {
$this->parser = new Parser();
Expand All @@ -292,9 +292,9 @@ public function getParser()
* set the parser
*
* @param AbstractParser $parser
* @return $this
* @return Space
*/
public function setParser(AbstractParser $parser)
public function setParser(AbstractParser $parser): Space
{
$this->parser = $parser;

Expand Down Expand Up @@ -340,7 +340,7 @@ public function addPath($path): Space
*
* @return string the file path
*/
protected function getCacheKey()
protected function getCacheKey(): string
{
return strtolower(md5(sprintf('%s_%s', implode('::', $this->getPaths()), implode('::', $this->getSections()))));
}
Expand Down Expand Up @@ -373,28 +373,31 @@ protected function merge(array $base, array $subject): array
/**
* @return array
*/
public function getPlaceholders()
public function getPlaceholders(): array
{
return $this->placeholders;
}

/**
* @param array $placeholders
* @return $this
* @return Space
*/
public function setPlaceholders(array $placeholders)
public function setPlaceholders(array $placeholders): Space
{
$this->placeholders = $placeholders;

return $this;
}

/**
* @param $placeholder
* @param $value
* @param string $placeholder
* @param mixed $value
* @return Space
*/
public function addPlaceholder($placeholder, $value)
public function addPlaceholder($placeholder, $value): Space
{
$this->placeholders[$placeholder] = $value;

return $this;
}
}

0 comments on commit 7ad219a

Please sign in to comment.