Skip to content

Commit 46bb088

Browse files
committed
Add logical operator rules
1 parent 4e5fabe commit 46bb088

2 files changed

Lines changed: 53 additions & 31 deletions

File tree

system/Debug/CustomExceptions.php

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace CodeIgniter;
1+
<?php
2+
3+
namespace CodeIgniter;
24

35
/**
46
* CodeIgniter
@@ -35,48 +37,57 @@
3537
* @since Version 3.0.0
3638
* @filesource
3739
*/
38-
3940
/**
4041
* Custom Exceptions
4142
*
42-
* These exceptions are provided for you use, and work to provide a consistent
43+
* These exceptions are provided for your use, and work to provide a consistent
4344
* experience across the application. The default error codes are already set,
4445
* and will be used to provide both HTTP status codes and CLI exit codes.
4546
*
47+
* The Error Exceptions below are primarily to provide a way to have
48+
* information logged automatically by the application's log system.
49+
*
4650
* @package CodeIgniter
4751
*/
4852

49-
50-
/*
51-
The Error Exceptions below are primarily to provide a way to have information logged
52-
automatically by the application's log system.
53-
*/
54-
5553
/**
56-
* Exception for automatic logging.
54+
* Error: system is unusable
5755
*/
58-
class EmergencyError extends \Error {}; // system is unusable
56+
class EmergencyError extends \Error
57+
{
58+
59+
}
5960

6061
/**
61-
* Exception for automatic logging.
62+
* Error: Action must be taken immediately (system/db down, etc)
6263
*/
63-
class AlertError extends \Error {}; // Action must be taken immediately (system/db down, etc)
64+
class AlertError extends \Error
65+
{
66+
67+
}
6468

6569
/**
66-
* Exception for automatic logging.
70+
* Error: Critical conditions, like component unavailble, etc.
6771
*/
68-
class CriticalError extends \Error {}; // Critical conditions, like component unavailble, etc.
72+
class CriticalError extends \Error
73+
{
74+
75+
}
6976

7077
/**
71-
* Exception for automatic logging.
78+
* Error: Runtime errors that do not require immediate action
7279
*/
73-
class Error extends \Error {}; // Runtime errors that do not require immediate action
80+
class Error extends \Error
81+
{
82+
83+
}
7484

7585
/**
7686
* Exception for automatic logging.
7787
*/
7888
class PageNotFoundException extends \OutOfBoundsException
7989
{
90+
8091
/**
8192
* Error code
8293
* @var int
@@ -85,13 +96,12 @@ class PageNotFoundException extends \OutOfBoundsException
8596

8697
}
8798

88-
;
89-
9099
/**
91100
* Exception for automatic logging.
92101
*/
93102
class ConfigException extends CriticalError
94103
{
104+
95105
/**
96106
* Error code
97107
* @var int
@@ -100,13 +110,12 @@ class ConfigException extends CriticalError
100110

101111
}
102112

103-
;
104-
105113
/**
106114
* Exception for automatic logging.
107115
*/
108116
class UnknownFileException extends CriticalError
109117
{
118+
110119
/**
111120
* Error code
112121
* @var int
@@ -115,13 +124,12 @@ class UnknownFileException extends CriticalError
115124

116125
}
117126

118-
;
119-
120127
/**
121128
* Exception for automatic logging.
122129
*/
123130
class UnknownClassException extends CriticalError
124131
{
132+
125133
/**
126134
* Error code
127135
* @var int
@@ -130,13 +138,12 @@ class UnknownClassException extends CriticalError
130138

131139
}
132140

133-
;
134-
135141
/**
136142
* Exception for automatic logging.
137143
*/
138144
class UnknownMethodException extends CriticalError
139145
{
146+
140147
/**
141148
* Error code
142149
* @var int
@@ -145,13 +152,12 @@ class UnknownMethodException extends CriticalError
145152

146153
}
147154

148-
;
149-
150155
/**
151156
* Exception for automatic logging.
152157
*/
153158
class UserInputException extends \OutOfBoundsException
154159
{
160+
155161
/**
156162
* Error code
157163
* @var int
@@ -160,19 +166,16 @@ class UserInputException extends \OutOfBoundsException
160166

161167
}
162168

163-
;
164-
165169
/**
166170
* Exception for automatic logging.
167171
*/
168172
class DatabaseException extends Error
169173
{
174+
170175
/**
171176
* Error code
172177
* @var int
173178
*/
174179
protected $code = 8;
175180

176181
}
177-
178-
;

user_guide_src/source/contributing/styleguide.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,25 @@ Operators
199199
- An operator MUST NOT be the last set of printable characters on a line.
200200
- An operator MAY be the first set of printable characters on a line.
201201

202+
Logical Operators
203+
=================
204+
205+
- Use the symbol versions (**||** and **&&**) of the logical operators
206+
instead of the word versions (**OR** and **AND**).
207+
208+
- This is consistent with other programming languages
209+
- It avoids the problem of the assignment operator (**=**) having
210+
higher precedence::
211+
212+
$result = true && false; // $result is false, expected
213+
$result = true OR false; // $result is true, evaluated as "($result = true) OR false"
214+
$result = (true OR false); // $result is false
215+
216+
- The logical negation operator MUST be separated from its argument by a
217+
single space, as in **! $result** instead of **!$result**
218+
- If there is potential confusion with a logical expression, then use
219+
parentheses for clarity, as shown above.
220+
202221
Other
203222
=====
204223

0 commit comments

Comments
 (0)