Skip to content

Commit 9dddf58

Browse files
authored
Merge pull request #16105 from phalcon/code-improvements
Improve and refactor code
2 parents cc1862c + 0f370c0 commit 9dddf58

37 files changed

+276
-371
lines changed

phalcon/Acl/Adapter/Memory.zep

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Memory extends AbstractAdapter
209209
{
210210
var componentName, componentObject;
211211

212-
if typeof componentValue == "object" && componentValue instanceof ComponentInterface {
212+
if typeof componentValue === "object" && componentValue instanceof ComponentInterface {
213213
let componentObject = componentValue;
214214
} else {
215215
let componentObject = new Component(componentValue);
@@ -236,13 +236,13 @@ class Memory extends AbstractAdapter
236236

237237
this->checkExists(this->componentsNames, componentName, "Component");
238238

239-
if unlikely (typeof accessList != "array" && typeof accessList != "string") {
239+
if unlikely (typeof accessList !== "array" && typeof accessList !== "string") {
240240
throw new Exception("Invalid value for the accessList");
241241
}
242242

243243
let exists = true;
244244

245-
if typeof accessList == "array" {
245+
if typeof accessList === "array" {
246246
for accessName in accessList {
247247
let accessKey = componentName . "!" . accessName;
248248

@@ -284,7 +284,7 @@ class Memory extends AbstractAdapter
284284
/**
285285
* Type conversion
286286
*/
287-
if typeof roleToInherits != "array" {
287+
if typeof roleToInherits !== "array" {
288288
let roleToInheritList = [roleToInherits];
289289
} else {
290290
let roleToInheritList = roleToInherits;
@@ -294,7 +294,7 @@ class Memory extends AbstractAdapter
294294
* inherits
295295
*/
296296
for roleToInherit in roleToInheritList {
297-
if typeof roleToInherit == "object" && roleToInherit instanceof RoleInterface {
297+
if typeof roleToInherit === "object" && roleToInherit instanceof RoleInterface {
298298
let roleInheritName = roleToInherit->getName();
299299
} else {
300300
let roleInheritName = roleToInherit;
@@ -383,7 +383,7 @@ class Memory extends AbstractAdapter
383383
{
384384
var roleName, roleObject;
385385

386-
if typeof role == "object" && role instanceof RoleInterface {
386+
if typeof role === "object" && role instanceof RoleInterface {
387387
let roleObject = role;
388388
} elseif is_string(role) {
389389
let roleObject = new Role(role);
@@ -490,13 +490,13 @@ class Memory extends AbstractAdapter
490490
string accessKey;
491491
array localAccess = [];
492492

493-
if typeof accessList == "string" {
493+
if typeof accessList === "string" {
494494
let localAccess = [accessList];
495495
} else {
496496
let localAccess = accessList;
497497
}
498498

499-
if typeof accessList == "array" {
499+
if typeof accessList === "array" {
500500
for accessName in localAccess {
501501
let accessKey = componentName . "!" . accessName;
502502

@@ -600,7 +600,7 @@ class Memory extends AbstractAdapter
600600

601601
bool hasComponent = false, hasRole = false;
602602

603-
if typeof roleName == "object" {
603+
if typeof roleName === "object" {
604604
if roleName instanceof RoleAwareInterface {
605605
let roleObject = roleName,
606606
roleName = roleObject->getRoleName();

phalcon/Acl/Component.zep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Component implements ComponentInterface
3434
*/
3535
public function __construct(string! name, string description = null)
3636
{
37-
if unlikely name == "*" {
37+
if unlikely name === "*" {
3838
throw new Exception("Component name cannot be '*'");
3939
}
4040

phalcon/Acl/Role.zep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Role implements RoleInterface
3434
*/
3535
public function __construct(string! name, string description = null)
3636
{
37-
if unlikely name == "*" {
37+
if unlikely name === "*" {
3838
throw new Exception("Role name cannot be '*'");
3939
}
4040

phalcon/Annotations/Adapter/AbstractAdapter.zep

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract class AbstractAdapter implements AdapterInterface
4141
/**
4242
* Get the class name if it's an object
4343
*/
44-
if typeof className == "object" {
44+
if typeof className === "object" {
4545
let realClassName = get_class(className);
4646
} else {
4747
let realClassName = className;
@@ -158,7 +158,7 @@ abstract class AbstractAdapter implements AdapterInterface
158158

159159
let methods = classAnnotations->getMethodsAnnotations();
160160

161-
if typeof methods == "array" {
161+
if typeof methods === "array" {
162162
for methodKey, method in methods {
163163
if !strcasecmp(methodKey, methodName) {
164164
return method;
@@ -192,7 +192,7 @@ abstract class AbstractAdapter implements AdapterInterface
192192
*/
193193
public function getReader() -> <ReaderInterface>
194194
{
195-
if typeof this->reader != "object" {
195+
if this->reader === null {
196196
let this->reader = new Reader();
197197
}
198198

phalcon/Annotations/Reader.zep

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Reader implements ReaderInterface
4949
/**
5050
* Append the class annotations to the annotations var
5151
*/
52-
if typeof classAnnotations == "array" {
52+
if typeof classAnnotations === "array" {
5353
let annotations["class"] = classAnnotations;
5454
}
5555
}
@@ -74,7 +74,7 @@ class Reader implements ReaderInterface
7474
let constantReflection = reflection->getReflectionConstant(constant);
7575
let comment = constantReflection->getDocComment();
7676

77-
if typeof comment == "string" {
77+
if typeof comment === "string" {
7878
/**
7979
* Parse constant docblock comment
8080
*/
@@ -113,7 +113,7 @@ class Reader implements ReaderInterface
113113
*/
114114
let comment = property->getDocComment();
115115

116-
if typeof comment == "string" {
116+
if typeof comment === "string" {
117117
/**
118118
* Parse property docblock comment
119119
*/
@@ -123,7 +123,7 @@ class Reader implements ReaderInterface
123123
line
124124
);
125125

126-
if typeof propertyAnnotations == "array" {
126+
if typeof propertyAnnotations === "array" {
127127
let annotationsProperties[property->name] = propertyAnnotations;
128128
}
129129
}
@@ -177,7 +177,7 @@ class Reader implements ReaderInterface
177177
*/
178178
public static function parseDocBlock(string docBlock, file = null, line = null) -> array
179179
{
180-
if typeof file != "string" {
180+
if typeof file !== "string" {
181181
let file = "eval code";
182182
}
183183

phalcon/Application/AbstractApplication.zep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class AbstractApplication extends Injectable implements EventsAwareInte
4545
*/
4646
public function __construct(<DiInterface> container = null)
4747
{
48-
if typeof container == "object" {
48+
if container !== null {
4949
let this->container = container;
5050
}
5151
}

phalcon/Cli/Console.zep

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,26 @@ class Console extends AbstractApplication
3636
*/
3737
public function handle(array arguments = null)
3838
{
39-
var className, container, dispatcher, eventsManager, module, moduleName,
39+
var className, dispatcher, module, moduleName,
4040
moduleObject, modules, path, router, task;
4141

42-
let container = this->container;
43-
44-
if unlikely typeof container != "object" {
42+
if this->container === null {
4543
throw new Exception(
4644
"A dependency injection container is required to access internal services"
4745
);
4846
}
4947

50-
let eventsManager = <ManagerInterface> this->eventsManager;
51-
5248
/**
5349
* Call boot event, this allows the developer to perform initialization
5450
* actions
5551
*/
56-
if typeof eventsManager == "object" {
57-
if eventsManager->fire("console:boot", this) === false {
52+
if this->eventsManager !== null {
53+
if this->eventsManager->fire("console:boot", this) === false {
5854
return false;
5955
}
6056
}
6157

62-
let router = <Router> container->getShared("router");
58+
let router = <Router> this->container->getShared("router");
6359

6460
if !count(arguments) && this->arguments {
6561
router->handle(this->arguments);
@@ -77,8 +73,8 @@ class Console extends AbstractApplication
7773
}
7874

7975
if moduleName {
80-
if typeof eventsManager == "object" {
81-
if eventsManager->fire("console:beforeStartModule", this, moduleName) === false {
76+
if this->eventsManager !== null {
77+
if this->eventsManager->fire("console:beforeStartModule", this, moduleName) === false {
8278
return false;
8379
}
8480
}
@@ -93,7 +89,7 @@ class Console extends AbstractApplication
9389

9490
let module = modules[moduleName];
9591

96-
if unlikely typeof module != "array" {
92+
if unlikely typeof module !== "array" {
9793
throw new Exception("Invalid module definition path");
9894
}
9995

@@ -113,37 +109,37 @@ class Console extends AbstractApplication
113109
}
114110
}
115111

116-
let moduleObject = container->get(className);
112+
let moduleObject = this->container->get(className);
117113

118-
moduleObject->registerAutoloaders(container);
119-
moduleObject->registerServices(container);
114+
moduleObject->registerAutoloaders(this->container);
115+
moduleObject->registerServices(this->container);
120116

121-
if typeof eventsManager == "object" {
122-
if eventsManager->fire("console:afterStartModule", this, moduleObject) === false {
117+
if this->eventsManager !== null {
118+
if this->eventsManager->fire("console:afterStartModule", this, moduleObject) === false {
123119
return false;
124120
}
125121
}
126122

127123
}
128124

129-
let dispatcher = <Dispatcher> container->getShared("dispatcher");
125+
let dispatcher = <Dispatcher> this->container->getShared("dispatcher");
130126

131127
dispatcher->setModuleName(router->getModuleName());
132128
dispatcher->setTaskName(router->getTaskName());
133129
dispatcher->setActionName(router->getActionName());
134130
dispatcher->setParams(router->getParams());
135131
dispatcher->setOptions(this->options);
136132

137-
if typeof eventsManager == "object" {
138-
if eventsManager->fire("console:beforeHandleTask", this, dispatcher) === false {
133+
if this->eventsManager !== null {
134+
if this->eventsManager->fire("console:beforeHandleTask", this, dispatcher) === false {
139135
return false;
140136
}
141137
}
142138

143139
let task = dispatcher->dispatch();
144140

145-
if typeof eventsManager == "object" {
146-
eventsManager->fire("console:afterHandleTask", this, task);
141+
if this->eventsManager !== null {
142+
this->eventsManager->fire("console:afterHandleTask", this, task);
147143
}
148144

149145
return task;
@@ -165,7 +161,7 @@ class Console extends AbstractApplication
165161
}
166162

167163
for arg in arguments {
168-
if typeof arg == "string" {
164+
if typeof arg === "string" {
169165
if strncmp(arg, "--", 2) == 0 {
170166
let pos = strpos(arg, "=");
171167

phalcon/Cli/Dispatcher.zep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Dispatcher extends CliDispatcher implements DispatcherInterface
113113

114114
let container = this->container;
115115

116-
if typeof container != "object" {
116+
if container === null {
117117
this->{"throwDispatchException"}(
118118
"A dependency injection container is required to access the 'filter' service",
119119
Exception::EXCEPTION_NO_DI
@@ -198,7 +198,7 @@ class Dispatcher extends CliDispatcher implements DispatcherInterface
198198

199199
let eventsManager = <ManagerInterface> this->eventsManager;
200200

201-
if typeof eventsManager == "object" {
201+
if eventsManager !== null {
202202
if eventsManager->fire("dispatch:beforeException", this, exception) === false {
203203
return false;
204204
}

phalcon/Cli/Router.zep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class Router extends AbstractInjectionAware
259259
this->wasMatched = false,
260260
this->matchedRoute = null;
261261

262-
if typeof arguments != "array" {
262+
if typeof arguments !== "array" {
263263
if unlikely (typeof arguments != "string" && arguments !== null) {
264264
throw new Exception("Arguments must be an array or string");
265265
}

phalcon/Db/Adapter/AbstractAdapter.zep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface
151151
/**
152152
* Create the instance only if the dialect is a string
153153
*/
154-
if typeof dialectClass == "string" {
154+
if typeof dialectClass === "string" {
155155
let this->dialect = create_instance(dialectClass);
156-
} elseif typeof dialectClass == "object" {
156+
} elseif typeof dialectClass === "object" {
157157
let this->dialect = dialectClass;
158158
}
159159

0 commit comments

Comments
 (0)