Code style updates

This commit is contained in:
Timothy Warren 2018-01-17 12:43:44 -05:00
parent d52515a24a
commit f64a8e0e9d
6 changed files with 52 additions and 29 deletions

View File

@ -42,7 +42,7 @@
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
"build": "robo build",
"docs": "cd build && ../vendor/bin/phpdox && cd ..",
"phpstan": "phpstan analyse src tests",
"phpstan": "phpstan analyse -l 7 src ",
"test": "phpunit"
},
"suggest": {

View File

@ -32,7 +32,7 @@ class Config implements ConfigInterface {
*
* @var ArrayType
*/
protected $map = [];
protected $map;
/**
* Constructor
@ -53,7 +53,7 @@ class Config implements ConfigInterface {
*/
public function get($key)
{
if (is_array($key))
if (\is_array($key))
{
return $this->map->getDeepKey($key);
}
@ -67,9 +67,9 @@ class Config implements ConfigInterface {
* @param string|array $key
* @return void
*/
public function delete($key)
public function delete($key): void
{
if (is_array($key))
if (\is_array($key))
{
$this->map->setDeepKey($key, NULL);
}
@ -90,7 +90,7 @@ class Config implements ConfigInterface {
*/
public function set($key, $value): ConfigInterface
{
if (is_array($key))
if (\is_array($key))
{
$this->map->setDeepKey($key, $value);
}
@ -100,7 +100,7 @@ class Config implements ConfigInterface {
}
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;

View File

@ -29,27 +29,27 @@ class Friend {
/**
* Object to create a friend of
* @var object
* @var mixed
*/
private $_friend_;
/**
* Reflection class of the object
* @var object
* @var \ReflectionClass
*/
private $_reflect_;
/**
* Create a friend object
*
* @param object $obj
* @param mixed $obj
* @throws InvalidArgumentException
*/
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;
@ -64,15 +64,30 @@ class Friend {
*/
public function __get(string $key)
{
if ($this->_reflect_->hasProperty($key))
if ($this->__isset($key))
{
$property = $this->_get_property($key);
return $property->getValue($this->_friend_);
if ($property !== NULL)
{
return $property->getValue($this->_friend_);
}
}
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
*
@ -82,10 +97,14 @@ class Friend {
*/
public function __set(string $key, $value)
{
if ($this->_reflect_->hasProperty($key))
if ($this->__isset($key))
{
$property = $this->_get_property($key);
$property->setValue($this->_friend_, $value);
if ($property !== NULL)
{
$property->setValue($this->_friend_, $value);
}
}
}
@ -115,7 +134,7 @@ class Friend {
* @param string $name
* @return ReflectionProperty|null
*/
private function _get_property(string $name)
private function _get_property(string $name): ?ReflectionProperty
{
try
{

View File

@ -28,12 +28,13 @@ class StringType extends Stringy {
* such as camelCase, PascalCase, kebab-case, or snake_case.
*
* @param string $strToMatch
* @throws \InvalidArgumentException
* @return boolean
*/
public function fuzzyCaseMatch(string $strToMatch): bool
{
$firstStr = StringType::create($this->str)->dasherize($this->str)->__toString();
$secondStr = StringType::create($strToMatch)->dasherize()->__toString();
$firstStr = self::create($this->str)->dasherize()->__toString();
$secondStr = self::create($strToMatch)->dasherize()->__toString();
return $firstStr === $secondStr;
}

View File

@ -26,7 +26,7 @@ class HtmlView extends HttpView {
/**
* HTML generator/escaper helper
*
* @var Aura\Html\HelperLocator
* @var \Aura\Html\HelperLocator
*/
protected $helper;
@ -62,7 +62,7 @@ class HtmlView extends HttpView {
$data['container'] = $this->container;
ob_start();
extract($data);
extract($data, \EXTR_SKIP);
include_once $path;
$buffer = ob_get_contents();
ob_end_clean();

View File

@ -38,14 +38,15 @@ class HttpView extends BaseView {
*
* @param string $url
* @param int $code
* @throws \InvalidArgumentException
* @return void
*/
public function redirect(string $url, int $code)
public function redirect(string $url, int $code): void
{
ob_start();
$message = $this->response->getReasonPhrase($code);
$this->setStatusCode($code);
$this->response->withHeader('Location', $url);
$message = $this->response->getReasonPhrase();
$this->response = $this->response->withHeader('Location', $url);
if (PHP_SAPI !== 'cli')
{
@ -75,9 +76,10 @@ class HttpView extends BaseView {
* any attempt to call again will result in a DoubleRenderException.
*
* @throws DoubleRenderException
* @throws \InvalidArgumentException
* @return void
*/
public function send()
public function send(): void
{
$this->output();
}
@ -86,22 +88,23 @@ class HttpView extends BaseView {
* Send the appropriate response
*
* @throws DoubleRenderException
* @throws \InvalidArgumentException
* @return void
*/
protected function output()
protected function output(): void
{
if ($this->hasRendered)
{
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-XSS-Protection', '1;mode=block')
->withHeader('X-Frame-Options', 'SAMEORIGIN');
$sender = new SapiEmitter($this->response);
$sender->emit($this->response);
(new SapiEmitter())->emit($this->response);
$this->hasRendered = TRUE;
}