Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference symbols from global space via FQN #7

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Loader/AutoLoadingPluginLoader.php
Expand Up @@ -2,8 +2,6 @@

namespace ipl\Stdlib\Loader;

use InvalidArgumentException;

class AutoLoadingPluginLoader implements PluginLoaderInterface
{
protected $namespace;
Expand All @@ -28,7 +26,7 @@ public function load($name)
$instance = $this->eventuallyLoad($name);

if ($instance === null) {
throw new InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(\sprintf(
'Unable to load %s (%s)',
$name,
$this->getFullClassByName($name)
Expand All @@ -51,7 +49,7 @@ public function eventuallyLoad($name)
public function eventuallyGetClassByName($name)
{
$class = $this->getFullClassByName($name);
if (class_exists($class)) {
if (\class_exists($class)) {
return $class;
} else {
return null;
Expand All @@ -76,7 +74,7 @@ public function setUppercaseFirst($uppercaseFirst = true)
public function getFullClassByName($name)
{
if ($this->uppercaseFirst) {
$name = ucfirst($name);
$name = \ucfirst($name);
}

return $this->namespace . '\\' . $name . $this->postfix;
Expand Down
6 changes: 2 additions & 4 deletions src/Loader/PluginLoader.php
Expand Up @@ -2,8 +2,6 @@

namespace ipl\Stdlib\Loader;

use InvalidArgumentException;

trait PluginLoader
{
/** @var array */
Expand All @@ -19,7 +17,7 @@ public function loadPlugin($type, $name)
$plugin = $this->eventuallyLoadPlugin($type, $name);

if ($plugin === null) {
throw new InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(\sprintf(
'Could not load %s "%s"',
$type,
$name
Expand Down Expand Up @@ -78,7 +76,7 @@ public function addPluginLoader($type, $loaderOrNamespace, $postfix = '')
$this->pluginLoaders[$type] = [];
}

array_unshift($this->pluginLoaders[$type], $loader);
\array_unshift($this->pluginLoaders[$type], $loader);

return $this;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Loader/PluginLoaderInterface.php
Expand Up @@ -2,8 +2,6 @@

namespace ipl\Stdlib\Loader;

use InvalidArgumentException;

interface PluginLoaderInterface
{
/**
Expand All @@ -22,7 +20,7 @@ public function eventuallyLoad($name);

/**
* @param $name
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
* @return object
*/
public function load($name);
Expand Down
6 changes: 3 additions & 3 deletions src/MessageContainer.php
Expand Up @@ -26,12 +26,12 @@ public function getMessages()
*/
public function addMessage($message)
{
$args = func_get_args();
array_shift($args);
$args = \func_get_args();
\array_shift($args);
if (empty($args)) {
$this->messages[] = $message;
} else {
$this->messages[] = vsprintf($message, $args);
$this->messages[] = \vsprintf($message, $args);
}

return $this;
Expand Down
24 changes: 10 additions & 14 deletions src/functions.php
Expand Up @@ -2,10 +2,6 @@

namespace ipl\Stdlib;

use InvalidArgumentException;
use Traversable;
use stdClass;

/**
* Detect and return the PHP type of the given subject
*
Expand All @@ -17,38 +13,38 @@
*/
function get_php_type($subject)
{
if (is_object($subject)) {
return get_class($subject);
if (\is_object($subject)) {
return \get_class($subject);
} else {
return gettype($subject);
return \gettype($subject);
}
}

/**
* Get the array value of the given subject
*
* @param array|object|Traversable $subject
* @param array|object|\Traversable $subject
*
* @return array
*
* @throws InvalidArgumentException If subject type is invalid
* @throws \InvalidArgumentException If subject type is invalid
*/
function arrayval($subject)
{
if (is_array($subject)) {
if (\is_array($subject)) {
return $subject;
}

if ($subject instanceof stdClass) {
if ($subject instanceof \stdClass) {
return (array) $subject;
}

if ($subject instanceof Traversable) {
if ($subject instanceof \Traversable) {
// Works for generators too
return iterator_to_array($subject);
return \iterator_to_array($subject);
}

throw new InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(\sprintf(
'arrayval expects arrays, objects or instances of Traversable. Got %s instead.',
get_php_type($subject)
));
Expand Down
6 changes: 2 additions & 4 deletions tests/php/FunctionsTest.php
Expand Up @@ -2,8 +2,6 @@

namespace ipl\Tests\Stdlib;

use ArrayIterator;
use stdClass;
use ipl\Stdlib;

class FunctionsTest extends TestCase
Expand All @@ -17,7 +15,7 @@ public function testGetPhpTypeWithObject()

public function testGetPhpTypeWithInstance()
{
$instance = new stdClass();
$instance = new \stdClass();

$this->assertSame('stdClass', Stdlib\get_php_type($instance));
}
Expand Down Expand Up @@ -49,7 +47,7 @@ public function testArrayvalWithTraversable()
{
$array = ['key' => 'value'];

$traversable = new ArrayIterator($array);
$traversable = new \ArrayIterator($array);

$this->assertSame($array, Stdlib\arrayval($traversable));
}
Expand Down