Scalar type hints, return types, and camelCased methods

This commit is contained in:
Timothy Warren 2016-10-20 20:08:11 -04:00
parent ffaa4a4cab
commit 5890f14c50
28 changed files with 148 additions and 119 deletions

View File

@ -30,7 +30,7 @@ trait ArrayWrapper {
* @param array $arr * @param array $arr
* @return ArrayType * @return ArrayType
*/ */
public function arr(array $arr) public function arr(array $arr): ArrayType
{ {
return new ArrayType($arr); return new ArrayType($arr);
} }

View File

@ -19,6 +19,7 @@ namespace Aviat\Ion\Cache\Driver;
use Aviat\Ion\ConfigInterface; use Aviat\Ion\ConfigInterface;
use Aviat\Ion\Exception\ConfigException; use Aviat\Ion\Exception\ConfigException;
use Aviat\Ion\Model\DB; use Aviat\Ion\Model\DB;
use PDO;
/** /**
* Driver for caching via a traditional SQL database * Driver for caching via a traditional SQL database
@ -64,7 +65,7 @@ class SQLDriver extends DB implements DriverInterface {
->where('key', $key) ->where('key', $key)
->get(); ->get();
$row = $query->fetch(\PDO::FETCH_ASSOC); $row = $query->fetch(PDO::FETCH_ASSOC);
if (empty($row)) if (empty($row))
{ {

View File

@ -16,9 +16,8 @@
namespace Aviat\Ion; namespace Aviat\Ion;
use Aviat\Ion\Exception\ConfigException; use Aviat\Ion\Exception\ConfigException;
use Aviat\Ion\Type\ArrayType;
use InvalidArgumentException; use InvalidArgumentException;
/** /**
@ -31,18 +30,18 @@ class Config implements ConfigInterface {
/** /**
* Config object * Config object
* *
* @var \Aviat\Ion\Type\ArrayType * @var ArrayType
*/ */
protected $map = []; protected $map = [];
/** /**
* Constructor * Constructor
* *
* @param array $config_array * @param array $configArray
*/ */
public function __construct(array $config_array = []) public function __construct(array $configArray = [])
{ {
$this->map = $this->arr($config_array); $this->map = $this->arr($configArray);
} }
/** /**
@ -56,7 +55,7 @@ class Config implements ConfigInterface {
{ {
if (is_array($key)) if (is_array($key))
{ {
return $this->map->get_deep_key($key); return $this->map->getDeepKey($key);
} }
return $this->map->get($key); return $this->map->get($key);
@ -72,7 +71,7 @@ class Config implements ConfigInterface {
{ {
if (is_array($key)) if (is_array($key))
{ {
$this->map->set_deep_key($key, NULL); $this->map->setDeepKey($key, NULL);
} }
else else
{ {
@ -87,13 +86,13 @@ class Config implements ConfigInterface {
* @param integer|string|array $key * @param integer|string|array $key
* @param mixed $value * @param mixed $value
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @return Config * @return ConfigInterface
*/ */
public function set($key, $value) public function set($key, $value): ConfigInterface
{ {
if (is_array($key)) if (is_array($key))
{ {
$this->map->set_deep_key($key, $value); $this->map->setDeepKey($key, $value);
} }
else if (is_scalar($key) && ! empty($key)) else if (is_scalar($key) && ! empty($key))
{ {

View File

@ -36,7 +36,7 @@ interface ConfigInterface {
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return ConfigInterface * @return ConfigInterface
*/ */
public function set($key, $value); public function set($key, $value): ConfigInterface;
/** /**
* Remove a config value * Remove a config value

View File

@ -16,12 +16,9 @@
namespace Aviat\Ion\Di; namespace Aviat\Ion\Di;
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
/** /**
* Dependency container * Dependency container
*/ */
@ -106,13 +103,13 @@ class Container implements ContainerInterface {
{ {
if ( ! is_string($id)) if ( ! is_string($id))
{ {
throw new ContainerException("Id must be a string"); throw new ContainerException('Id must be a string');
} }
if ($this->has($id)) if ($this->has($id))
{ {
// By default, call a factory with the Container // By default, call a factory with the Container
$args = (is_array($args)) ? $args : [$this]; $args = is_array($args) ? $args : [$this];
$obj = call_user_func_array($this->container[$id], $args); $obj = call_user_func_array($this->container[$id], $args);
// Check for container interface, and apply the container to the object // Check for container interface, and apply the container to the object
@ -130,7 +127,7 @@ class Container implements ContainerInterface {
* @param Callable $value - a factory callable for the item * @param Callable $value - a factory callable for the item
* @return ContainerInterface * @return ContainerInterface
*/ */
public function set($id, Callable $value) public function set(string $id, Callable $value): ContainerInterface
{ {
$this->container[$id] = $value; $this->container[$id] = $value;
return $this; return $this;
@ -144,7 +141,7 @@ class Container implements ContainerInterface {
* @throws NotFoundException - No entry was found for this identifier. * @throws NotFoundException - No entry was found for this identifier.
* @return ContainerInterface * @return ContainerInterface
*/ */
public function setInstance($id, $value) public function setInstance(string $id, $value): ContainerInterface
{ {
if ( ! $this->has($id)) if ( ! $this->has($id))
{ {
@ -162,7 +159,7 @@ class Container implements ContainerInterface {
* @param string $id Identifier of the entry to look for. * @param string $id Identifier of the entry to look for.
* @return boolean * @return boolean
*/ */
public function has($id) public function has($id): bool
{ {
return array_key_exists($id, $this->container); return array_key_exists($id, $this->container);
} }
@ -173,7 +170,7 @@ class Container implements ContainerInterface {
* @param string $id The logger channel * @param string $id The logger channel
* @return boolean * @return boolean
*/ */
public function hasLogger($id = 'default') public function hasLogger(string $id = 'default'): bool
{ {
return array_key_exists($id, $this->loggers); return array_key_exists($id, $this->loggers);
} }
@ -185,7 +182,7 @@ class Container implements ContainerInterface {
* @param string $id The logger 'channel' * @param string $id The logger 'channel'
* @return ContainerInterface * @return ContainerInterface
*/ */
public function setLogger(LoggerInterface $logger, $id = 'default') public function setLogger(LoggerInterface $logger, string $id = 'default'): ContainerInterface
{ {
$this->loggers[$id] = $logger; $this->loggers[$id] = $logger;
return $this; return $this;
@ -197,9 +194,9 @@ class Container implements ContainerInterface {
* @param string $id The logger to retrieve * @param string $id The logger to retrieve
* @return LoggerInterface|null * @return LoggerInterface|null
*/ */
public function getLogger($id = 'default') public function getLogger(string $id = 'default')
{ {
return ($this->hasLogger($id)) return $this->hasLogger($id)
? $this->loggers[$id] ? $this->loggers[$id]
: NULL; : NULL;
} }
@ -217,8 +214,8 @@ class Container implements ContainerInterface {
$trait_name = __NAMESPACE__ . '\\ContainerAware'; $trait_name = __NAMESPACE__ . '\\ContainerAware';
$interface_name = __NAMESPACE__ . '\\ContainerAwareInterface'; $interface_name = __NAMESPACE__ . '\\ContainerAwareInterface';
$uses_trait = in_array($trait_name, class_uses($obj)); $uses_trait = in_array($trait_name, class_uses($obj), TRUE);
$implements_interface = in_array($interface_name, class_implements($obj)); $implements_interface = in_array($interface_name, class_implements($obj), TRUE);
if ($uses_trait OR $implements_interface) if ($uses_trait OR $implements_interface)
{ {

View File

@ -45,7 +45,7 @@ trait ContainerAware {
* *
* @return ContainerInterface * @return ContainerInterface
*/ */
public function getContainer() public function getContainer(): ContainerInterface
{ {
return $this->container; return $this->container;
} }

View File

@ -34,7 +34,7 @@ interface ContainerAwareInterface {
* *
* @return ContainerInterface * @return ContainerInterface
*/ */
public function getContainer(); public function getContainer(): ContainerInterface;
} }
// End of ContainerAwareInterface.php // End of ContainerAwareInterface.php

View File

@ -16,13 +16,36 @@
namespace Aviat\Ion\Di; namespace Aviat\Ion\Di;
use Interop\Container\ContainerInterface as InteropInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/** /**
* Interface for the Dependency Injection Container * Interface for the Dependency Injection Container
*
* Based on container-interop interface, but return types and
* scalar type hints make the interface incompatible to the PHP parser
*
* @see https://github.com/container-interop/container-interop
*/ */
interface ContainerInterface extends InteropInterface { interface ContainerInterface {
/**
* Finds an entry of the container by its identifier and returns it.
*
* @param string $id Identifier of the entry to look for.
* @throws NotFoundException No entry was found for this identifier.
* @throws ContainerException Error while retrieving the entry.
* @return mixed Entry.
*/
public function get($id);
/**
* Returns true if the container can return an entry for the given identifier.
* Returns false otherwise.
*
* @param string $id Identifier of the entry to look for.
* @return boolean
*/
public function has($id): bool;
/** /**
* Add a factory to the container * Add a factory to the container
@ -31,7 +54,7 @@ interface ContainerInterface extends InteropInterface {
* @param Callable $value - a factory callable for the item * @param Callable $value - a factory callable for the item
* @return ContainerInterface * @return ContainerInterface
*/ */
public function set($id, Callable $value); public function set(string $id, Callable $value): ContainerInterface;
/** /**
* Set a specific instance in the container for an existing factory * Set a specific instance in the container for an existing factory
@ -40,7 +63,7 @@ interface ContainerInterface extends InteropInterface {
* @param mixed $value * @param mixed $value
* @return ContainerInterface * @return ContainerInterface
*/ */
public function setInstance($id, $value); public function setInstance(string $id, $value): ContainerInterface;
/** /**
* Get a new instance of the specified item * Get a new instance of the specified item
@ -55,22 +78,22 @@ interface ContainerInterface extends InteropInterface {
* @param string $id The logger channel * @param string $id The logger channel
* @return boolean * @return boolean
*/ */
public function hasLogger($id = 'default'); public function hasLogger(string $id = 'default'): bool;
/** /**
* Add a logger to the Container * Add a logger to the Container
* *
* @param LoggerInterface $logger * @param LoggerInterface $logger
* @param string $id The logger 'channel' * @param string $id The logger 'channel'
* @return Container * @return ContainerInterface
*/ */
public function setLogger(LoggerInterface $logger, $id = 'default'); public function setLogger(LoggerInterface $logger, string $id = 'default'): ContainerInterface;
/** /**
* Retrieve a logger for the selected channel * Retrieve a logger for the selected channel
* *
* @param string $id The logger to retreive * @param string $id The logger to retrieve
* @return LoggerInterface|null * @return LoggerInterface|null
*/ */
public function getLogger($id = 'default'); public function getLogger(string $id = 'default');
} }

View File

@ -16,10 +16,13 @@
namespace Aviat\Ion\Di\Exception; namespace Aviat\Ion\Di\Exception;
use Exception;
use Interop\Container\Exception\ContainerException as InteropContainerException;
/** /**
* Generic exception for Di Container * Generic exception for Di Container
*/ */
class ContainerException extends \Exception implements \Interop\Container\Exception\ContainerException { class ContainerException extends Exception implements InteropContainerException {
} }
// End of ContainerException.php // End of ContainerException.php

View File

@ -16,11 +16,13 @@
namespace Aviat\Ion\Di\Exception; namespace Aviat\Ion\Di\Exception;
use Interop\Container\Exception\NotFoundException as InteropNotFoundException;
/** /**
* Exception for Di Container when trying to access a * Exception for Di Container when trying to access a
* key that doesn't exist in the container * key that doesn't exist in the container
*/ */
class NotFoundException extends ContainerException implements \Interop\Container\Exception\NotFoundException { class NotFoundException extends ContainerException implements InteropNotFoundException {
} }
// End of NotFoundException.php // End of NotFoundException.php

View File

@ -33,7 +33,7 @@ abstract class Enum {
* *
* @return array * @return array
*/ */
protected function getConstList() protected function getConstList(): array
{ {
$reflect = new ReflectionClass($this); $reflect = new ReflectionClass($this);
return $reflect->getConstants(); return $reflect->getConstants();
@ -44,7 +44,7 @@ abstract class Enum {
* @param mixed $key * @param mixed $key
* @return boolean * @return boolean
*/ */
protected function isValid($key) protected function isValid($key): bool
{ {
$values = array_values($this->getConstList()); $values = array_values($this->getConstList());
return in_array($key, $values); return in_array($key, $values);

View File

@ -16,9 +16,11 @@
namespace Aviat\Ion\Exception; namespace Aviat\Ion\Exception;
use InvalidArgumentException;
/** /**
* Exception for bad configuration * Exception for bad configuration
*/ */
class ConfigException extends \InvalidArgumentException { class ConfigException extends InvalidArgumentException {
} }

View File

@ -16,10 +16,13 @@
namespace Aviat\Ion\Exception; namespace Aviat\Ion\Exception;
use Exception;
use LogicException;
/** /**
* Exception called when a view is attempted to be sent twice * Exception called when a view is attempted to be sent twice
*/ */
class DoubleRenderException extends \LogicException { class DoubleRenderException extends LogicException {
/** /**
* DoubleRenderException constructor. * DoubleRenderException constructor.
@ -28,7 +31,7 @@ class DoubleRenderException extends \LogicException {
* @param int $code * @param int $code
* @param null $previous * @param null $previous
*/ */
public function __construct($message = 'A view can only be rendered once, because headers can only be sent once.', $code = 0, $previous = NULL) public function __construct(string $message = 'A view can only be rendered once, because headers can only be sent once.', int $code = 0, Exception $previous = NULL)
{ {
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
} }

View File

@ -16,11 +16,11 @@
namespace Aviat\Ion; namespace Aviat\Ion;
use BadMethodCallException;
use InvalidArgumentException;
use ReflectionClass; use ReflectionClass;
use ReflectionMethod; use ReflectionMethod;
use ReflectionProperty; use ReflectionProperty;
use InvalidArgumentException;
use BadMethodCallException;
/** /**
* Friend class for testing * Friend class for testing
@ -62,7 +62,7 @@ class Friend {
* @param string $key * @param string $key
* @return mixed * @return mixed
*/ */
public function __get($key) public function __get(string $key)
{ {
if ($this->_reflect_->hasProperty($key)) if ($this->_reflect_->hasProperty($key))
{ {
@ -80,7 +80,7 @@ class Friend {
* @param mixed $value * @param mixed $value
* @return void * @return void
*/ */
public function __set($key, $value) public function __set(string $key, $value)
{ {
if ($this->_reflect_->hasProperty($key)) if ($this->_reflect_->hasProperty($key))
{ {
@ -97,7 +97,7 @@ class Friend {
* @return mixed * @return mixed
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function __call($method, $args) public function __call(string $method, array $args)
{ {
if ( ! $this->_reflect_->hasMethod($method)) if ( ! $this->_reflect_->hasMethod($method))
{ {
@ -116,7 +116,7 @@ class Friend {
* @param string $name * @param string $name
* @return ReflectionProperty|null * @return ReflectionProperty|null
*/ */
private function _get_property($name) private function _get_property(string $name)
{ {
try try
{ {

View File

@ -43,26 +43,26 @@ class Json {
* *
* @param string $filename * @param string $filename
* @param mixed $data * @param mixed $data
* @param int $json_options - Options to pass to json_encode * @param int $jsonOptions - Options to pass to json_encode
* @param int $file_options - Options to pass to file_get_contents * @param int $fileOptions - Options to pass to file_get_contents
* @return int * @return int
*/ */
public static function encodeFile($filename, $data, $json_options = 0, $file_options = 0) public static function encodeFile(string $filename, $data, int $jsonOptions = 0, int $fileOptions = 0): int
{ {
$json = self::encode($data, $json_options); $json = self::encode($data, $jsonOptions);
return file_put_contents($filename, $json, $file_options); return file_put_contents($filename, $json, $fileOptions);
} }
/** /**
* Decode data from json * Decode data from json
* *
* @param string $json * @param string|null $json
* @param bool $assoc * @param bool $assoc
* @param int $depth * @param int $depth
* @param int $options * @param int $options
* @return mixed * @return mixed
*/ */
public static function decode($json, $assoc = TRUE, $depth = 512, $options = 0) public static function decode($json, bool $assoc = TRUE, int $depth = 512, int $options = 0)
{ {
// Don't try to decode null // Don't try to decode null
if (empty($json)) if (empty($json))
@ -86,7 +86,7 @@ class Json {
* @param int $options * @param int $options
* @return mixed * @return mixed
*/ */
public static function decodeFile($filename, $assoc = TRUE, $depth = 512, $options = 0) public static function decodeFile(string $filename, bool $assoc = TRUE, int $depth = 512, int $options = 0)
{ {
$json = file_get_contents($filename); $json = file_get_contents($filename);
return self::decode($json, $assoc, $depth, $options); return self::decode($json, $assoc, $depth, $options);
@ -98,7 +98,7 @@ class Json {
* @param string $string * @param string $string
* @return boolean * @return boolean
*/ */
public static function isJson($string) public static function isJson(string $string): bool
{ {
return StringType::create($string)->isJson(); return StringType::create($string)->isJson();
} }

View File

@ -16,10 +16,12 @@
namespace Aviat\Ion; namespace Aviat\Ion;
use InvalidArgumentException;
/** /**
* Exceptions thrown by the Json class * Exceptions thrown by the Json class
*/ */
class JsonException extends \InvalidArgumentException { class JsonException extends InvalidArgumentException {
} }
// End of JsonException.php // End of JsonException.php

View File

@ -37,7 +37,7 @@ trait StaticInstance {
* @param array $args * @param array $args
* @return mixed * @return mixed
*/ */
public function __call($method, $args) public function __call(string $method, array $args)
{ {
if (method_exists($this, $method)) if (method_exists($this, $method))
{ {
@ -53,7 +53,7 @@ trait StaticInstance {
* @param array $args * @param array $args
* @return mixed * @return mixed
*/ */
public static function __callStatic($method, $args) public static function __callStatic(string $method, array $args)
{ {
$class = get_called_class(); $class = get_called_class();
if ( ! array_key_exists($class, self::$instance)) if ( ! array_key_exists($class, self::$instance))

View File

@ -16,12 +16,14 @@
namespace Aviat\Ion\Transformer; namespace Aviat\Ion\Transformer;
use Aviat\Ion\StringWrapper;
/** /**
* Base class for data trasformation * Base class for data trasformation
*/ */
abstract class AbstractTransformer implements TransformerInterface { abstract class AbstractTransformer implements TransformerInterface {
use \Aviat\Ion\StringWrapper; use StringWrapper;
/** /**
* Mutate the data structure * Mutate the data structure
@ -37,7 +39,7 @@ abstract class AbstractTransformer implements TransformerInterface {
* @param array|object $collection * @param array|object $collection
* @return array * @return array
*/ */
public function transform_collection($collection) public function transformCollection($collection): array
{ {
$list = (array)$collection; $list = (array)$collection;
return array_map([$this, 'transform'], $list); return array_map([$this, 'transform'], $list);

View File

@ -16,6 +16,8 @@
namespace Aviat\Ion\Type; namespace Aviat\Ion\Type;
use InvalidArgumentException;
/** /**
* Wrapper class for native array methods for convenience * Wrapper class for native array methods for convenience
* *
@ -37,7 +39,7 @@ class ArrayType {
* *
* @var array * @var array
*/ */
protected $native_methods = [ protected $nativeMethods = [
'chunk' => 'array_chunk', 'chunk' => 'array_chunk',
'pluck' => 'array_column', 'pluck' => 'array_column',
'key_diff' => 'array_diff_key', 'key_diff' => 'array_diff_key',
@ -62,7 +64,7 @@ class ArrayType {
* *
* @var array * @var array
*/ */
protected $native_in_place_methods = [ protected $nativeInPlaceMethods = [
'shuffle' => 'shuffle', 'shuffle' => 'shuffle',
'shift' => 'array_shift', 'shift' => 'array_shift',
'unshift' => 'array_unshift', 'unshift' => 'array_unshift',
@ -88,35 +90,35 @@ class ArrayType {
* @return mixed * @return mixed
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function __call($method, $args) public function __call(string $method, array $args)
{ {
// Simple mapping for the majority of methods // Simple mapping for the majority of methods
if (array_key_exists($method, $this->native_methods)) if (array_key_exists($method, $this->nativeMethods))
{ {
$func = $this->native_methods[$method]; $func = $this->nativeMethods[$method];
// Set the current array as the first argument of the method // Set the current array as the first argument of the method
array_unshift($args, $this->arr); array_unshift($args, $this->arr);
return call_user_func_array($func, $args); return call_user_func_array($func, $args);
} }
// Mapping for in-place methods // Mapping for in-place methods
if (array_key_exists($method, $this->native_in_place_methods)) if (array_key_exists($method, $this->nativeInPlaceMethods))
{ {
$func = $this->native_in_place_methods[$method]; $func = $this->nativeInPlaceMethods[$method];
$func($this->arr); $func($this->arr);
return $this->arr; return $this->arr;
} }
throw new \InvalidArgumentException("Method '{$method}' does not exist"); throw new InvalidArgumentException("Method '{$method}' does not exist");
} }
/** /**
* Does the passed key exist in the current array? * Does the passed key exist in the current array?
* *
* @param string $key * @param int|string $key
* @return bool * @return bool
*/ */
public function has_key($key) public function hasKey($key): bool
{ {
return array_key_exists($key, $this->arr); return array_key_exists($key, $this->arr);
} }
@ -129,7 +131,7 @@ class ArrayType {
* @param mixed $value * @param mixed $value
* @return array * @return array
*/ */
public function fill($start_index, $num, $value) public function fill(int $start_index, int $num, $value): array
{ {
return array_fill($start_index, $num, $value); return array_fill($start_index, $num, $value);
} }
@ -140,7 +142,7 @@ class ArrayType {
* @param callable $callback * @param callable $callback
* @return array * @return array
*/ */
public function map(callable $callback) public function map(callable $callback): array
{ {
return array_map($callback, $this->arr); return array_map($callback, $this->arr);
} }
@ -152,7 +154,7 @@ class ArrayType {
* @param bool $strict * @param bool $strict
* @return false|integer|string * @return false|integer|string
*/ */
public function search($value, $strict = FALSE) public function search($value, bool $strict = TRUE)
{ {
return array_search($value, $this->arr, $strict); return array_search($value, $this->arr, $strict);
} }
@ -164,7 +166,7 @@ class ArrayType {
* @param bool $strict * @param bool $strict
* @return bool * @return bool
*/ */
public function has($value, $strict = FALSE) public function has($value, bool $strict = TRUE): bool
{ {
return in_array($value, $this->arr, $strict); return in_array($value, $this->arr, $strict);
} }
@ -184,7 +186,7 @@ class ArrayType {
} }
else else
{ {
if ($this->has_key($key)) if ($this->hasKey($key))
{ {
$value =& $this->arr[$key]; $value =& $this->arr[$key];
} }
@ -200,7 +202,7 @@ class ArrayType {
* @param mixed $value * @param mixed $value
* @return ArrayType * @return ArrayType
*/ */
public function set($key, $value) public function set($key, $value): ArrayType
{ {
$this->arr[$key] = $value; $this->arr[$key] = $value;
return $this; return $this;
@ -212,7 +214,7 @@ class ArrayType {
* @param array $key * @param array $key
* @return mixed * @return mixed
*/ */
public function &get_deep_key(array $key) public function &getDeepKey(array $key)
{ {
$pos =& $this->arr; $pos =& $this->arr;
@ -241,7 +243,7 @@ class ArrayType {
* @param mixed $value * @param mixed $value
* @return array * @return array
*/ */
public function set_deep_key(array $key, $value) public function setDeepKey(array $key, $value): array
{ {
$pos =& $this->arr; $pos =& $this->arr;

View File

@ -75,7 +75,7 @@ abstract class View
* @throws DoubleRenderException * @throws DoubleRenderException
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
if ($this->hasRendered) if ($this->hasRendered)
{ {
@ -88,10 +88,10 @@ abstract class View
/** /**
* Set the output string * Set the output string
* *
* @param string $string * @param mixed $string
* @return ViewInterface * @return ViewInterface
*/ */
public function setOutput($string) public function setOutput($string): ViewInterface
{ {
$this->response->getBody()->write($string); $this->response->getBody()->write($string);
@ -104,7 +104,7 @@ abstract class View
* @param string $string * @param string $string
* @return ViewInterface * @return ViewInterface
*/ */
public function appendOutput($string) public function appendOutput(string $string): ViewInterface
{ {
return $this->setOutput($string); return $this->setOutput($string);
} }
@ -115,7 +115,7 @@ abstract class View
* *
* @return string * @return string
*/ */
public function getOutput() public function getOutput(): string
{ {
return $this->response->getBody()->__toString(); return $this->response->getBody()->__toString();
} }

View File

@ -55,7 +55,7 @@ class HtmlView extends HttpView {
* @param array $data * @param array $data
* @return string * @return string
*/ */
public function render_template($path, $data) public function renderTemplate(string $path, array $data): string
{ {
$data['helper'] = $this->helper; $data['helper'] = $this->helper;
$data['escape'] = $this->helper->escape(); $data['escape'] = $this->helper->escape();

View File

@ -41,7 +41,7 @@ class HttpView extends BaseView {
* @param int $code * @param int $code
* @return void * @return void
*/ */
public function redirect($url, $code) public function redirect(string $url, int $code)
{ {
ob_start(); ob_start();
$message = $this->response->getReasonPhrase($code); $message = $this->response->getReasonPhrase($code);
@ -64,7 +64,7 @@ class HttpView extends BaseView {
* @param int $code * @param int $code
* @return HttpView * @return HttpView
*/ */
public function setStatusCode($code) public function setStatusCode(int $code): HttpView
{ {
$this->response = $this->response->withStatus($code) $this->response = $this->response->withStatus($code)
->withProtocolVersion('1.1'); ->withProtocolVersion('1.1');

View File

@ -37,7 +37,7 @@ class JsonView extends HttpView {
* @param mixed $string * @param mixed $string
* @return ViewInterface * @return ViewInterface
*/ */
public function setOutput($string) public function setOutput($string): ViewInterface
{ {
if ( ! is_string($string)) if ( ! is_string($string))
{ {

View File

@ -29,15 +29,15 @@ interface ViewInterface {
* @throws DoubleRenderException * @throws DoubleRenderException
* @return string * @return string
*/ */
public function __toString(); public function __toString(): string;
/** /**
* Set the output string * Set the output string
* *
* @param string $string * @param mixed $string
* @return ViewInterface * @return ViewInterface
*/ */
public function setOutput($string); public function setOutput($string): ViewInterface;
/** /**
* Append additional output. * Append additional output.
@ -45,7 +45,7 @@ interface ViewInterface {
* @param string $string * @param string $string
* @return ViewInterface * @return ViewInterface
*/ */
public function appendOutput($string); public function appendOutput(string $string): ViewInterface;
/** /**
* Get the current output as a string. Does not * Get the current output as a string. Does not
@ -53,7 +53,7 @@ interface ViewInterface {
* *
* @return string * @return string
*/ */
public function getOutput(); public function getOutput(): string;
/** /**
* Send output to client. As it renders the view, * Send output to client. As it renders the view,

View File

@ -16,7 +16,7 @@
namespace Aviat\Ion\Tests\Di; namespace Aviat\Ion\Tests\Di;
use Aviat\Ion\Di\Container; use Aviat\Ion\Di\{Container, ContainerAware};
use Aviat\Ion\Di\Exception\ContainerException; use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Tests\Ion_TestCase; use Aviat\Ion\Tests\Ion_TestCase;
use Monolog\Logger; use Monolog\Logger;
@ -32,12 +32,11 @@ class FooTest {
} }
class FooTest2 { class FooTest2 {
use \Aviat\Ion\Di\ContainerAware; use ContainerAware;
} }
class ContainerTest extends Ion_TestCase { class ContainerTest extends Ion_TestCase {
public function setUp() public function setUp()
{ {
$this->container = new Container(); $this->container = new Container();
@ -85,15 +84,9 @@ class ContainerTest extends Ion_TestCase {
*/ */
public function testGetNewWithException($id, $exception, $message) public function testGetNewWithException($id, $exception, $message)
{ {
try $this->expectException($exception);
{ $this->expectExceptionMessage($message);
$this->container->getNew($id); $this->container->getNew($id);
}
catch(ContainerException $e)
{
$this->assertInstanceOf($exception, $e);
$this->assertEquals($message, $e->getMessage());
}
} }
public function dataSetInstanceWithException() public function dataSetInstanceWithException()

View File

@ -102,7 +102,7 @@ class AbstractTransformerTest extends Ion_TestCase {
*/ */
public function testTransformCollection($original, $expected) public function testTransformCollection($original, $expected)
{ {
$actual = $this->transformer->transform_collection($original); $actual = $this->transformer->transformCollection($original);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
} }

View File

@ -124,8 +124,8 @@ class ArrayTypeTest extends Ion_TestCase {
] ]
]; ];
$obj = $this->arr($arr); $obj = $this->arr($arr);
$this->assertEquals('foobar', $obj->get_deep_key(['baz', 'bar'])); $this->assertEquals('foobar', $obj->getDeepKey(['baz', 'bar']));
$this->assertNull($obj->get_deep_key(['foo', 'bar', 'baz'])); $this->assertNull($obj->getDeepKey(['foo', 'bar', 'baz']));
} }
public function testMap() public function testMap()
@ -165,8 +165,8 @@ class ArrayTypeTest extends Ion_TestCase {
'a' => 'b', 'a' => 'b',
'z' => 'y' 'z' => 'y'
]); ]);
$this->assertTrue($obj->has_key('a')); $this->assertTrue($obj->hasKey('a'));
$this->assertFalse($obj->has_key('b')); $this->assertFalse($obj->hasKey('b'));
} }
public function testHas() public function testHas()

View File

@ -34,7 +34,7 @@ class HtmlViewTest extends HttpViewTest {
{ {
$path = _dir(self::TEST_VIEW_DIR, 'test_view.php'); $path = _dir(self::TEST_VIEW_DIR, 'test_view.php');
$expected = '<tag>foo</tag>'; $expected = '<tag>foo</tag>';
$actual = $this->view->render_template($path, [ $actual = $this->view->renderTemplate($path, [
'var' => 'foo' 'var' => 'foo'
]); ]);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);