Skip to content

Commit 0e45053

Browse files
committed
#135 generic optimisations and cleanups in AnnotationRegistry
1 parent 769c329 commit 0e45053

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

lib/Doctrine/Common/Annotations/AnnotationRegistry.php

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,30 @@ final class AnnotationRegistry
3434
*
3535
* @var array
3636
*/
37-
static private $autoloadNamespaces = array();
37+
static private $autoloadNamespaces = [];
3838

3939
/**
4040
* A map of autoloader callables.
4141
*
4242
* @var array
4343
*/
44-
static private $loaders = array();
44+
static private $loaders = [];
4545

4646
/**
4747
* An array of classes which cannot be found
4848
*
4949
* @var null[] indexed by class name
5050
*/
51-
static private $failedToAutoload = array();
51+
static private $failedToAutoload = [];
5252

5353
/**
5454
* @return void
5555
*/
56-
static public function reset()
56+
public static function reset()
5757
{
58-
self::$autoloadNamespaces = array();
59-
self::$loaders = array();
60-
self::$failedToAutoload = array();
58+
self::$autoloadNamespaces = [];
59+
self::$loaders = [];
60+
self::$failedToAutoload = [];
6161
}
6262

6363
/**
@@ -67,7 +67,7 @@ static public function reset()
6767
*
6868
* @return void
6969
*/
70-
static public function registerFile($file)
70+
public static function registerFile($file)
7171
{
7272
require_once $file;
7373
}
@@ -82,7 +82,7 @@ static public function registerFile($file)
8282
*
8383
* @return void
8484
*/
85-
static public function registerAutoloadNamespace($namespace, $dirs = null)
85+
public static function registerAutoloadNamespace($namespace, $dirs = null)
8686
{
8787
self::$autoloadNamespaces[$namespace] = $dirs;
8888
}
@@ -96,9 +96,9 @@ static public function registerAutoloadNamespace($namespace, $dirs = null)
9696
*
9797
* @return void
9898
*/
99-
static public function registerAutoloadNamespaces(array $namespaces)
99+
public static function registerAutoloadNamespaces(array $namespaces)
100100
{
101-
self::$autoloadNamespaces = array_merge(self::$autoloadNamespaces, $namespaces);
101+
self::$autoloadNamespaces = \array_merge(self::$autoloadNamespaces, $namespaces);
102102
}
103103

104104
/**
@@ -113,42 +113,38 @@ static public function registerAutoloadNamespaces(array $namespaces)
113113
*
114114
* @throws \InvalidArgumentException
115115
*/
116-
static public function registerLoader(callable $callable)
116+
public static function registerLoader(callable $callable)
117117
{
118118
// Reset our static cache now that we have a new loader to work with
119-
self::$failedToAutoload = array();
119+
self::$failedToAutoload = [];
120120
self::$loaders[] = $callable;
121121
}
122122

123123
/**
124124
* Autoloads an annotation class silently.
125-
*
126-
* @param string $class
127-
*
128-
* @return boolean
129125
*/
130-
static public function loadAnnotationClass($class)
126+
public static function loadAnnotationClass(string $class) : bool
131127
{
132128
if (\class_exists($class, false)) {
133129
return true;
134130
}
135131

136-
if (\array_key_exists($class, self::$failedToAutoload[$class])) {
132+
if (\array_key_exists($class, self::$failedToAutoload)) {
137133
return false;
138134
}
139135

140136
foreach (self::$autoloadNamespaces AS $namespace => $dirs) {
141-
if (strpos($class, $namespace) === 0) {
142-
$file = str_replace("\\", DIRECTORY_SEPARATOR, $class) . ".php";
137+
if (\strpos($class, $namespace) === 0) {
138+
$file = \str_replace('\\', \DIRECTORY_SEPARATOR, $class) . '.php';
143139
if ($dirs === null) {
144140
if ($path = stream_resolve_include_path($file)) {
145141
require $path;
146142
return true;
147143
}
148144
} else {
149145
foreach((array)$dirs AS $dir) {
150-
if (is_file($dir . DIRECTORY_SEPARATOR . $file)) {
151-
require $dir . DIRECTORY_SEPARATOR . $file;
146+
if (is_file($dir . \DIRECTORY_SEPARATOR . $file)) {
147+
require $dir . \DIRECTORY_SEPARATOR . $file;
152148
return true;
153149
}
154150
}
@@ -157,7 +153,7 @@ static public function loadAnnotationClass($class)
157153
}
158154

159155
foreach (self::$loaders AS $loader) {
160-
if (call_user_func($loader, $class) === true) {
156+
if ($loader($class) === true) {
161157
return true;
162158
}
163159
}

0 commit comments

Comments
 (0)