-
Validation must be applied to any function that is passing data to other function, specially in case of database queries.
-
variable names should be
camelCase
(PSR-2) -
There should be no keys validation inside
Repository
. All checking must be validated usingValidator
inController
. -
Method docs must contain what method does.
-
There should be no database interaction from Controller.
-
Single quotes
''
must be used instead of double quotes""
-
Bind interface of
Repository
viaServiceProvider
. Don't useRepositoryClass
directly. It provides more control over structure. -
Try to omit variables that are not in use(free up memory).
-
I did some code refactoring via
PSR-2
standards to these files. -
use of proper return type instead of
mixed
in function docs. It gives more insights what one will get from the method. -
Maintain a config file with defaults, load the config key and make changes to it. it will save a lot of else conditions. Example:
if (isset($data['customer_phone_type'])) {
$data['customer_phone_type'] = 'yes';
} else {
$data['customer_phone_type'] = 'no';
}
instead of this, load config keys and use those.
$data = config->get('app.defaultOptions');
if (isset($data['customer_phone_type'])) {
$data['customer_phone_type'] = 'yes';
}
Default options for customer_phone_type
can have no
as a default. This will omit a lot of else conditions from a
single file, and from entire system.
- Instead of returning everything with
response
method, use simplereturn
withoutresponse
. Laravel will wrap it intoresponse
by itself. However, useresponse
method if you want to send back specificStatus Code
andheaders
.
_app
contains old code, whileapp
contains refactored code.