Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/php-short-array-syntax' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Jun 5, 2015
2 parents 19d9236 + 1cf9d2f commit b247db7
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 138 deletions.
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $config->fixers(
'object_operator',
'php_closing_tag',
'remove_lines_between_uses',
'short_array_syntax',
'short_tag',
'standardize_not_equal',
'trailing_spaces',
Expand Down
6 changes: 3 additions & 3 deletions src/AutoloaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class AutoloaderFactory
/**
* @var array All autoloaders registered using the factory
*/
protected static $loaders = array();
protected static $loaders = [];

/**
* @var StandardAutoloader StandardAutoloader instance for resolving
Expand Down Expand Up @@ -143,7 +143,7 @@ public static function getRegisteredAutoloader($class)
public static function unregisterAutoloaders()
{
foreach (static::getRegisteredAutoloaders() as $class => $autoloader) {
spl_autoload_unregister(array($autoloader, 'autoload'));
spl_autoload_unregister([$autoloader, 'autoload']);
unset(static::$loaders[$class]);
}
}
Expand All @@ -161,7 +161,7 @@ public static function unregisterAutoloader($autoloaderClass)
}

$autoloader = static::$loaders[$autoloaderClass];
spl_autoload_unregister(array($autoloader, 'autoload'));
spl_autoload_unregister([$autoloader, 'autoload']);
unset(static::$loaders[$autoloaderClass]);
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ClassMapAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class ClassMapAutoloader implements SplAutoloader
* Registry of map files that have already been loaded
* @var array
*/
protected $mapsLoaded = array();
protected $mapsLoaded = [];

/**
* Class name/filename map
* @var array
*/
protected $map = array();
protected $map = [];

/**
* Constructor
Expand Down Expand Up @@ -150,7 +150,7 @@ public function autoload($class)
*/
public function register()
{
spl_autoload_register(array($this, 'autoload'), true, true);
spl_autoload_register([$this, 'autoload'], true, true);
}

/**
Expand Down Expand Up @@ -202,7 +202,7 @@ public static function realPharPath($path)
}

$prefixLength = 5 + strlen($match[1]);
$parts = explode('/', str_replace(array('/', '\\'), '/', substr($path, $prefixLength)));
$parts = explode('/', str_replace(['/', '\\'], '/', substr($path, $prefixLength)));
$parts = array_values(array_filter($parts, function ($p) {
return ($p !== '' && $p !== '.');
}));
Expand Down
20 changes: 10 additions & 10 deletions src/ModuleAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ class ModuleAutoloader implements SplAutoloader
/**
* @var array An array of module paths to scan
*/
protected $paths = array();
protected $paths = [];

/**
* @var array An array of modulename => path
*/
protected $explicitPaths = array();
protected $explicitPaths = [];

/**
* @var array An array of namespaceName => namespacePath
*/
protected $namespacedPaths = array();
protected $namespacedPaths = [];

/**
* @var string Will contain the absolute phar:// path to the executable when packaged as phar file
Expand All @@ -43,12 +43,12 @@ class ModuleAutoloader implements SplAutoloader
/**
* @var array An array of supported phar extensions (filled on constructor)
*/
protected $pharExtensions = array();
protected $pharExtensions = [];

/**
* @var array An array of module classes to their containing files
*/
protected $moduleClassMap = array();
protected $moduleClassMap = [];

/**
* Constructor
Expand All @@ -61,11 +61,11 @@ public function __construct($options = null)
{
if (extension_loaded('phar')) {
$this->pharBasePath = Phar::running(true);
$this->pharExtensions = array(
$this->pharExtensions = [
'phar',
'phar.tar',
'tar',
);
];

// ext/zlib enabled -> phar can read gzip & zip compressed files
if (extension_loaded('zlib')) {
Expand Down Expand Up @@ -325,7 +325,7 @@ protected function loadModuleFromPhar($pharPath, $class)
*/
public function register()
{
spl_autoload_register(array($this, 'autoload'));
spl_autoload_register([$this, 'autoload']);
}

/**
Expand All @@ -335,7 +335,7 @@ public function register()
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'autoload'));
spl_autoload_unregister([$this, 'autoload']);
}

/**
Expand Down Expand Up @@ -385,7 +385,7 @@ public function registerPath($path, $moduleName = false)
));
}
if ($moduleName) {
if (in_array(substr($moduleName, -2), array('\\*', '\\%'))) {
if (in_array(substr($moduleName, -2), ['\\*', '\\%'])) {
$this->namespacedPaths[substr($moduleName, 0, -2)] = static::normalizePath($path);
} else {
$this->explicitPaths[$moduleName] = static::normalizePath($path);
Expand Down
6 changes: 3 additions & 3 deletions src/PluginClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class PluginClassLoader implements PluginClassLocator
* List of plugin name => class name pairs
* @var array
*/
protected $plugins = array();
protected $plugins = [];

/**
* Static map allow global seeding of plugin loader
* @var array
*/
protected static $staticMap = array();
protected static $staticMap = [];

/**
* Constructor
Expand Down Expand Up @@ -60,7 +60,7 @@ public function __construct($map = null)
public static function addStaticMap($map)
{
if (null === $map) {
static::$staticMap = array();
static::$staticMap = [];
return;
}

Expand Down
12 changes: 6 additions & 6 deletions src/StandardAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class StandardAutoloader implements SplAutoloader
/**
* @var array Namespace/directory pairs to search; ZF library added by default
*/
protected $namespaces = array();
protected $namespaces = [];

/**
* @var array Prefix/directory pairs to search
*/
protected $prefixes = array();
protected $prefixes = [];

/**
* @var bool Whether or not the autoloader should also act as a fallback autoloader
Expand Down Expand Up @@ -240,7 +240,7 @@ public function autoload($class)
*/
public function register()
{
spl_autoload_register(array($this, 'autoload'));
spl_autoload_register([$this, 'autoload']);
}

/**
Expand All @@ -254,7 +254,7 @@ protected function transformClassNameToFilename($class, $directory)
{
// $class may contain a namespace portion, in which case we need
// to preserve any underscores in that portion.
$matches = array();
$matches = [];
preg_match('/(?P<namespace>.+\\\)?(?P<class>[^\\\]+$)/', $class, $matches);

$class = (isset($matches['class'])) ? $matches['class'] : '';
Expand All @@ -276,7 +276,7 @@ protected function transformClassNameToFilename($class, $directory)
*/
protected function loadClass($class, $type)
{
if (!in_array($type, array(self::LOAD_NS, self::LOAD_PREFIX, self::ACT_AS_FALLBACK))) {
if (!in_array($type, [self::LOAD_NS, self::LOAD_PREFIX, self::ACT_AS_FALLBACK])) {
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException();
}
Expand Down Expand Up @@ -317,7 +317,7 @@ protected function loadClass($class, $type)
protected function normalizeDirectory($directory)
{
$last = $directory[strlen($directory) - 1];
if (in_array($last, array('/', '\\'))) {
if (in_array($last, ['/', '\\'])) {
$directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR;
return $directory;
}
Expand Down
80 changes: 40 additions & 40 deletions test/AutoloaderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function setUp()
if (!is_array($this->loaders)) {
// spl_autoload_functions does not return empty array when no
// autoloaders registered...
$this->loaders = array();
$this->loaders = [];
}

// Store original include_path
Expand Down Expand Up @@ -52,11 +52,11 @@ public function tearDown()

public function testRegisteringValidMapFilePopulatesAutoloader()
{
AutoloaderFactory::factory(array(
'Zend\Loader\ClassMapAutoloader' => array(
AutoloaderFactory::factory([
'Zend\Loader\ClassMapAutoloader' => [
__DIR__ . '/_files/goodmap.php',
),
));
],
]);
$loader = AutoloaderFactory::getRegisteredAutoloader('Zend\Loader\ClassMapAutoloader');
$map = $loader->getAutoloadMap();
$this->assertInternalType('array', $map);
Expand All @@ -71,68 +71,68 @@ public function testRegisteringValidMapFilePopulatesAutoloader()
public function testFactoryCatchesInvalidClasses()
{
include __DIR__ . '/_files/InvalidInterfaceAutoloader.php';
AutoloaderFactory::factory(array(
'InvalidInterfaceAutoloader' => array()
));
AutoloaderFactory::factory([
'InvalidInterfaceAutoloader' => []
]);
}

public function testFactoryDoesNotRegisterDuplicateAutoloaders()
{
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
AutoloaderFactory::factory([
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
'TestNamespace' => __DIR__ . '/TestAsset/TestNamespace',
),
),
));
],
],
]);
$this->assertEquals(1, count(AutoloaderFactory::getRegisteredAutoloaders()));
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
AutoloaderFactory::factory([
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
'ZendTest\Loader\TestAsset\TestPlugins' => __DIR__ . '/TestAsset/TestPlugins',
),
),
));
],
],
]);
$this->assertEquals(1, count(AutoloaderFactory::getRegisteredAutoloaders()));
$this->assertTrue(class_exists('TestNamespace\NoDuplicateAutoloadersCase'));
$this->assertTrue(class_exists('ZendTest\Loader\TestAsset\TestPlugins\Foo'));
}

public function testCanUnregisterAutoloaders()
{
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
AutoloaderFactory::factory([
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
'TestNamespace' => __DIR__ . '/TestAsset/TestNamespace',
),
),
));
],
],
]);
AutoloaderFactory::unregisterAutoloaders();
$this->assertEquals(0, count(AutoloaderFactory::getRegisteredAutoloaders()));
}

public function testCanUnregisterAutoloadersByClassName()
{
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
AutoloaderFactory::factory([
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
'TestNamespace' => __DIR__ . '/TestAsset/TestNamespace',
),
),
));
],
],
]);
AutoloaderFactory::unregisterAutoloader('Zend\Loader\StandardAutoloader');
$this->assertEquals(0, count(AutoloaderFactory::getRegisteredAutoloaders()));
}

public function testCanGetValidRegisteredAutoloader()
{
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
AutoloaderFactory::factory([
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
'TestNamespace' => __DIR__ . '/TestAsset/TestNamespace',
),
),
));
],
],
]);
$autoloader = AutoloaderFactory::getRegisteredAutoloader('Zend\Loader\StandardAutoloader');
$this->assertInstanceOf('Zend\Loader\StandardAutoloader', $autoloader);
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public function testFactoryWithInvalidArgumentThrowsException()
public function testFactoryWithInvalidAutoloaderClassThrowsException()
{
$this->setExpectedException('Zend\Loader\Exception\InvalidArgumentException');
AutoloaderFactory::factory(array('InvalidAutoloader' => array()));
AutoloaderFactory::factory(['InvalidAutoloader' => []]);
}

public function testCannotBeInstantiatedViaConstructor()
Expand All @@ -178,7 +178,7 @@ public function testPassingNoArgumentsToFactoryInstantiatesAndRegistersStandardA
$loader = array_shift($loaders);
$this->assertInstanceOf('Zend\Loader\StandardAutoloader', $loader);

$test = array($loader, 'autoload');
$test = [$loader, 'autoload'];
$found = false;
foreach (spl_autoload_functions() as $function) {
if ($function === $test) {
Expand Down

0 comments on commit b247db7

Please sign in to comment.