Code style updates
This commit is contained in:
parent
d52515a24a
commit
f64a8e0e9d
@ -42,7 +42,7 @@
|
|||||||
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
|
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
|
||||||
"build": "robo build",
|
"build": "robo build",
|
||||||
"docs": "cd build && ../vendor/bin/phpdox && cd ..",
|
"docs": "cd build && ../vendor/bin/phpdox && cd ..",
|
||||||
"phpstan": "phpstan analyse src tests",
|
"phpstan": "phpstan analyse -l 7 src ",
|
||||||
"test": "phpunit"
|
"test": "phpunit"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
|
@ -32,7 +32,7 @@ class Config implements ConfigInterface {
|
|||||||
*
|
*
|
||||||
* @var ArrayType
|
* @var ArrayType
|
||||||
*/
|
*/
|
||||||
protected $map = [];
|
protected $map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -53,7 +53,7 @@ class Config implements ConfigInterface {
|
|||||||
*/
|
*/
|
||||||
public function get($key)
|
public function get($key)
|
||||||
{
|
{
|
||||||
if (is_array($key))
|
if (\is_array($key))
|
||||||
{
|
{
|
||||||
return $this->map->getDeepKey($key);
|
return $this->map->getDeepKey($key);
|
||||||
}
|
}
|
||||||
@ -67,9 +67,9 @@ class Config implements ConfigInterface {
|
|||||||
* @param string|array $key
|
* @param string|array $key
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function delete($key)
|
public function delete($key): void
|
||||||
{
|
{
|
||||||
if (is_array($key))
|
if (\is_array($key))
|
||||||
{
|
{
|
||||||
$this->map->setDeepKey($key, NULL);
|
$this->map->setDeepKey($key, NULL);
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ class Config implements ConfigInterface {
|
|||||||
*/
|
*/
|
||||||
public function set($key, $value): ConfigInterface
|
public function set($key, $value): ConfigInterface
|
||||||
{
|
{
|
||||||
if (is_array($key))
|
if (\is_array($key))
|
||||||
{
|
{
|
||||||
$this->map->setDeepKey($key, $value);
|
$this->map->setDeepKey($key, $value);
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ class Config implements ConfigInterface {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("Key must be integer, string, or array, and cannot be empty");
|
throw new InvalidArgumentException('Key must be integer, string, or array, and cannot be empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -29,27 +29,27 @@ class Friend {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Object to create a friend of
|
* Object to create a friend of
|
||||||
* @var object
|
* @var mixed
|
||||||
*/
|
*/
|
||||||
private $_friend_;
|
private $_friend_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflection class of the object
|
* Reflection class of the object
|
||||||
* @var object
|
* @var \ReflectionClass
|
||||||
*/
|
*/
|
||||||
private $_reflect_;
|
private $_reflect_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a friend object
|
* Create a friend object
|
||||||
*
|
*
|
||||||
* @param object $obj
|
* @param mixed $obj
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function __construct($obj)
|
public function __construct($obj)
|
||||||
{
|
{
|
||||||
if ( ! is_object($obj))
|
if ( ! \is_object($obj))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("Friend must be an object");
|
throw new InvalidArgumentException('Friend must be an object');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_friend_ = $obj;
|
$this->_friend_ = $obj;
|
||||||
@ -64,15 +64,30 @@ class Friend {
|
|||||||
*/
|
*/
|
||||||
public function __get(string $key)
|
public function __get(string $key)
|
||||||
{
|
{
|
||||||
if ($this->_reflect_->hasProperty($key))
|
if ($this->__isset($key))
|
||||||
{
|
{
|
||||||
$property = $this->_get_property($key);
|
$property = $this->_get_property($key);
|
||||||
|
|
||||||
|
if ($property !== NULL)
|
||||||
|
{
|
||||||
return $property->getValue($this->_friend_);
|
return $property->getValue($this->_friend_);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See if a property exists on the friend
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function __isset(string $name): bool
|
||||||
|
{
|
||||||
|
return $this->_reflect_->hasProperty($name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a friend's property
|
* Set a friend's property
|
||||||
*
|
*
|
||||||
@ -82,12 +97,16 @@ class Friend {
|
|||||||
*/
|
*/
|
||||||
public function __set(string $key, $value)
|
public function __set(string $key, $value)
|
||||||
{
|
{
|
||||||
if ($this->_reflect_->hasProperty($key))
|
if ($this->__isset($key))
|
||||||
{
|
{
|
||||||
$property = $this->_get_property($key);
|
$property = $this->_get_property($key);
|
||||||
|
|
||||||
|
if ($property !== NULL)
|
||||||
|
{
|
||||||
$property->setValue($this->_friend_, $value);
|
$property->setValue($this->_friend_, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls a protected or private method on the friend
|
* Calls a protected or private method on the friend
|
||||||
@ -115,7 +134,7 @@ class Friend {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @return ReflectionProperty|null
|
* @return ReflectionProperty|null
|
||||||
*/
|
*/
|
||||||
private function _get_property(string $name)
|
private function _get_property(string $name): ?ReflectionProperty
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -28,12 +28,13 @@ class StringType extends Stringy {
|
|||||||
* such as camelCase, PascalCase, kebab-case, or snake_case.
|
* such as camelCase, PascalCase, kebab-case, or snake_case.
|
||||||
*
|
*
|
||||||
* @param string $strToMatch
|
* @param string $strToMatch
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function fuzzyCaseMatch(string $strToMatch): bool
|
public function fuzzyCaseMatch(string $strToMatch): bool
|
||||||
{
|
{
|
||||||
$firstStr = StringType::create($this->str)->dasherize($this->str)->__toString();
|
$firstStr = self::create($this->str)->dasherize()->__toString();
|
||||||
$secondStr = StringType::create($strToMatch)->dasherize()->__toString();
|
$secondStr = self::create($strToMatch)->dasherize()->__toString();
|
||||||
|
|
||||||
return $firstStr === $secondStr;
|
return $firstStr === $secondStr;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ class HtmlView extends HttpView {
|
|||||||
/**
|
/**
|
||||||
* HTML generator/escaper helper
|
* HTML generator/escaper helper
|
||||||
*
|
*
|
||||||
* @var Aura\Html\HelperLocator
|
* @var \Aura\Html\HelperLocator
|
||||||
*/
|
*/
|
||||||
protected $helper;
|
protected $helper;
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ class HtmlView extends HttpView {
|
|||||||
$data['container'] = $this->container;
|
$data['container'] = $this->container;
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
extract($data);
|
extract($data, \EXTR_SKIP);
|
||||||
include_once $path;
|
include_once $path;
|
||||||
$buffer = ob_get_contents();
|
$buffer = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
@ -38,14 +38,15 @@ class HttpView extends BaseView {
|
|||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param int $code
|
* @param int $code
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function redirect(string $url, int $code)
|
public function redirect(string $url, int $code): void
|
||||||
{
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
$message = $this->response->getReasonPhrase($code);
|
|
||||||
$this->setStatusCode($code);
|
$this->setStatusCode($code);
|
||||||
$this->response->withHeader('Location', $url);
|
$message = $this->response->getReasonPhrase();
|
||||||
|
$this->response = $this->response->withHeader('Location', $url);
|
||||||
|
|
||||||
if (PHP_SAPI !== 'cli')
|
if (PHP_SAPI !== 'cli')
|
||||||
{
|
{
|
||||||
@ -75,9 +76,10 @@ class HttpView extends BaseView {
|
|||||||
* any attempt to call again will result in a DoubleRenderException.
|
* any attempt to call again will result in a DoubleRenderException.
|
||||||
*
|
*
|
||||||
* @throws DoubleRenderException
|
* @throws DoubleRenderException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function send()
|
public function send(): void
|
||||||
{
|
{
|
||||||
$this->output();
|
$this->output();
|
||||||
}
|
}
|
||||||
@ -86,22 +88,23 @@ class HttpView extends BaseView {
|
|||||||
* Send the appropriate response
|
* Send the appropriate response
|
||||||
*
|
*
|
||||||
* @throws DoubleRenderException
|
* @throws DoubleRenderException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function output()
|
protected function output(): void
|
||||||
{
|
{
|
||||||
if ($this->hasRendered)
|
if ($this->hasRendered)
|
||||||
{
|
{
|
||||||
throw new DoubleRenderException();
|
throw new DoubleRenderException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response = $this->response->withHeader('Content-type', "{$this->contentType};charset=utf-8")
|
$this->response = $this->response
|
||||||
|
->withHeader('Content-type', "{$this->contentType};charset=utf-8")
|
||||||
->withHeader('X-Content-Type-Options', 'nosniff')
|
->withHeader('X-Content-Type-Options', 'nosniff')
|
||||||
->withHeader('X-XSS-Protection', '1;mode=block')
|
->withHeader('X-XSS-Protection', '1;mode=block')
|
||||||
->withHeader('X-Frame-Options', 'SAMEORIGIN');
|
->withHeader('X-Frame-Options', 'SAMEORIGIN');
|
||||||
|
|
||||||
$sender = new SapiEmitter($this->response);
|
(new SapiEmitter())->emit($this->response);
|
||||||
$sender->emit($this->response);
|
|
||||||
|
|
||||||
$this->hasRendered = TRUE;
|
$this->hasRendered = TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user