Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Update PHP version to 7.1 minimum. #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Exception.php → Source/Exception.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand All @@ -8,7 +10,7 @@
*
* New BSD License
*
* Copyright © 2007-2017, Hoa community. All rights reserved.
* Copyright © 2007-2018, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -42,9 +44,6 @@
* Class \Hoa\Zformat\Exception.
*
* Extending the \Hoa\Exception\Exception class.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Exception extends HoaException
{
Expand Down
102 changes: 19 additions & 83 deletions Parameter.php → Source/Parameter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand All @@ -8,7 +10,7 @@
*
* New BSD License
*
* Copyright © 2007-2017, Hoa community. All rights reserved.
* Copyright © 2007-2018, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -40,56 +42,38 @@
* Class \Hoa\Zformat\Parameter.
*
* Provide a class parameters support.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Parameter
{
/**
* Owner.
*
* @var string
*/
protected $_owner = null;

/**
* Parameters.
*
* @var array
*/
protected $_parameters = [];

/**
* Keywords.
*
* @var array
*/
protected $_keywords = [];

/**
* Constants values for zFormat.
*
* @var array
*/
protected static $_constants = null;

/**
* Cache for zFormat.
*
* @var array
*/
protected $_cache = [];



/**
* Construct a new set of parameters.
*
* @param mixed $owner Owner name or instance.
* @param array $keywords Keywords.
* @param array $parameters Parameters.
* @throws \Hoa\Zformat\Exception
*/
public function __construct(
$owner,
Expand Down Expand Up @@ -129,10 +113,8 @@ public function __construct(

/**
* Initialize constants.
*
* @return void
*/
public static function initializeConstants()
public static function initializeConstants(): void
{
$c = explode('…', date('d…j…N…w…z…W…m…n…Y…y…g…G…h…H…i…s…u…O…T…U'));
self::$_constants = [
Expand Down Expand Up @@ -163,22 +145,16 @@ public static function initializeConstants()

/**
* Get constants.
*
* @return array
*/
public static function getConstants()
public static function getConstants(): array
{
return self::$_constants;
}

/**
* Set default parameters to a class.
*
* @param array $parameters Parameters to set.
* @return void
* @throws \Hoa\Zformat\Exception
*/
private function setDefault(array $parameters)
private function setDefault(array $parameters): void
{
$this->_parameters = $parameters;

Expand All @@ -187,11 +163,8 @@ private function setDefault(array $parameters)

/**
* Set parameters.
*
* @param array $parameters Parameters.
* @return void
*/
public function setParameters(array $parameters)
public function setParameters(array $parameters): void
{
$this->resetCache();

Expand All @@ -204,22 +177,16 @@ public function setParameters(array $parameters)

/**
* Get parameters.
*
* @return array
*/
public function getParameters()
public function getParameters(): array
{
return $this->_parameters;
}

/**
* Set a parameter.
*
* @param string $key Key.
* @param mixed $value Value.
* @return mixed
*/
public function setParameter($key, $value)
public function setParameter(string $key, $value)
{
$this->resetCache();
$old = null;
Expand All @@ -235,11 +202,8 @@ public function setParameter($key, $value)

/**
* Get a parameter.
*
* @param string $parameter Parameter.
* @return mixed
*/
public function getParameter($parameter)
public function getParameter(string $parameter)
{
if (array_key_exists($parameter, $this->_parameters)) {
return $this->_parameters[$parameter];
Expand All @@ -250,11 +214,8 @@ public function getParameter($parameter)

/**
* Get a formatted parameter (i.e. zFormatted).
*
* @param string $parameter Parameter.
* @return mixed
*/
public function getFormattedParameter($parameter)
public function getFormattedParameter(string $parameter)
{
if (null === $value = $this->getParameter($parameter)) {
return null;
Expand All @@ -265,11 +226,8 @@ public function getFormattedParameter($parameter)

/**
* Check a branch exists.
*
* @param string $branch Branch.
* @return bool
*/
public function branchExists($branch)
public function branchExists(string $branch): bool
{
$qBranch = preg_quote($branch);

Expand All @@ -284,11 +242,8 @@ public function branchExists($branch)

/**
* Unlinearize a branch to an array.
*
* @param string $branch Branch.
* @return array
*/
public function unlinearizeBranch($branch)
public function unlinearizeBranch(string $branch): array
{
$parameters = $this->getParameters();
$out = [];
Expand Down Expand Up @@ -329,12 +284,8 @@ public function unlinearizeBranch($branch)

/**
* Set keywords.
*
* @param array $keywords Keywords.
* @return void
* @throws \Hoa\Zformat\Exception
*/
public function setKeywords($keywords)
public function setKeywords(array $keywords): void
{
$this->resetCache();

Expand All @@ -347,22 +298,16 @@ public function setKeywords($keywords)

/**
* Get keywords.
*
* @return array
*/
public function getKeywords()
public function getKeywords(): array
{
return $this->_keywords;
}

/**
* Set a keyword.
*
* @param string $key Key.
* @param mixed $value Value.
* @return mixed
*/
public function setKeyword($key, $value)
public function setKeyword(string $key, $value)
{
$this->resetCache();
$old = null;
Expand All @@ -378,11 +323,8 @@ public function setKeyword($key, $value)

/**
* Get a keyword.
*
* @param string $keyword Keyword.
* @return mixed
*/
public function getKeyword($keyword)
public function getKeyword(string $keyword)
{
if (true === array_key_exists($keyword, $this->_keywords)) {
return $this->_keywords[$keyword];
Expand Down Expand Up @@ -478,12 +420,8 @@ public function getKeyword($keyword)
* and add the extension of power;
* • recursion: 'oofarBaz', get 'arbar' first, and then, replace the
* suffix 'ar' by 'az'.
*
* @param string $value Parameter value.
* @return string
* @throws \Hoa\Zformat\Exception
*/
public function zFormat($value)
public function zFormat(string $value): string
{
if (!is_string($value)) {
return $value;
Expand Down Expand Up @@ -666,10 +604,8 @@ function ($match) use ($self, $value, &$keywords, &$parameters) {

/**
* Reset zFormat cache.
*
* @return void
*/
private function resetCache()
private function resetCache(): void
{
unset($this->_cache);
$this->_cache = [];
Expand Down
11 changes: 4 additions & 7 deletions Parameterizable.php → Source/Parameterizable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand All @@ -8,7 +10,7 @@
*
* New BSD License
*
* Copyright © 2007-2017, Hoa community. All rights reserved.
* Copyright © 2007-2018, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -40,16 +42,11 @@
* Interface \Hoa\Zformat\Parameterizable.
*
* Interface representing a class with zFormat parameters.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
interface Parameterizable
{
/**
* Get parameters.
*
* @return \Hoa\Zformat\Parameter
*/
public function getParameters();
public function getParameters(): Parameter;
}
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@
"source": "https://central.hoa-project.net/Resource/Library/Zformat"
},
"require": {
"hoa/consistency": "~1.0",
"hoa/exception" : "~1.0"
"php" : ">=7.1",
"hoa/consistency": "dev-master",
"hoa/exception" : "dev-master"
},
"autoload": {
"psr-4": {
"Hoa\\Zformat\\": "."
"Hoa\\Zformat\\": "Source"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
}
},
"minimum-stability": "dev"
}