ECG compliance: How to do?How to write a custom extension?How to handle deprecated “Mysql4” classes when...
Manga about a female worker who got dragged into another world together with this high school girl and she was just told she's not needed anymore
How to deal with fear of taking dependencies
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Pristine Bit Checking
Where else does the Shulchan Aruch quote an authority by name?
Can the Produce Flame cantrip be used to grapple, or as an unarmed strike, in the right circumstances?
Filling an area between two curves
How do I create uniquely male characters?
Does the average primeness of natural numbers tend to zero?
How can I fix this gap between bookcases I made?
Landing in very high winds
Information to fellow intern about hiring?
How could a lack of term limits lead to a "dictatorship?"
Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?
Is Social Media Science Fiction?
Is domain driven design an anti-SQL pattern?
How to make payment on the internet without leaving a money trail?
Was there ever an axiom rendered a theorem?
What do the Banks children have against barley water?
Doomsday-clock for my fantasy planet
What is the offset in a seaplane's hull?
Are objects structures and/or vice versa?
A poker game description that does not feel gimmicky
Why do UK politicians seemingly ignore opinion polls on Brexit?
ECG compliance: How to do?
How to write a custom extension?How to handle deprecated “Mysql4” classes when rewriting resource modelsHow to check if a collection has items?Magento 1: Performance optimizations to delete entitiesWhat is faster - getting raw attribute value or use collection?Find MIN & MAX value of product attribute in a large categoryHow to fix 'getFirstItem does not limit the result of collection load to one item` warning?Magento 1.9 module oddly breaking when changing resource folder from Mysql4 to ResourceHow to write a custom extension?Why are so many PHP functions disallowed in the Magento ECG Coding Standard?Magento ECG discourage $_FILES superglobalUnable to add magento-ecg/coding-standard to PHP_CodeSniffer:Magento 2: what's the status of M2 regarding PSR compliance?How could I create magento 2 code sniffs ruleset.xml or does someone have it?How to access $_FILES in magentos way?How to modify delete method using objectManagerMagento 2 : How to write a custom extension?PCI Compliance Scanning Tool For Any Version Of Magento Site
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
There is something like a coding standard
for Magento 1, called ECG
where numerous things should be avoided or methods that should not be used.
Let's try to create a list that covers all cases that are throwing "errors" or "warning" in your code.
Below you'll find a list with all possible warnings. I'll update this post at regular intervals and link to given and upvoted answers.
Note: please try to avoid duplicate answers ;)
Download: https://github.com/magento-ecg/coding-standard
ECG Sniffs
Classes
Mysql4
Mysql4 classes are obsolete.
- How to handle deprecated “Mysql4” classes when rewriting resource models
- Magento 1.9 module oddly breaking when changing resource folder from Mysql4 to Resource
Object Instantiation
Direct object instantiation (class %s) is discouraged in Magento.
protected $disallowedClassPrefixes = array(
'Mage_',
'Enterprise_',
);
...
PHP
Goto
Use of goto is discouraged.
...
Namespace
Namespace for "'.$exceptionClassName.'" class is not specified.
...
Private Class Member
Private class member detected.
...
Var
Private class member detected.
...
Performance
Collection Count
Unnecessary loading of a Magento data collection. Use the getSize() method instead.
- How to check if a collection has items?
FetchAll
fetchAll() can be memory inefficient for large data sets.
...
GetFirstItem
getFirstItem() does not limit the result of collection load to one item.
- GetFirstItem - https://magento.stackexchange.com/a/179309/46249
Loop
Array size calculation function %s detected in loop
Model LSD method %s detected in loop
Data load %s method detected in loop
protected $countFunctions = array(
'sizeof',
'count'
);
protected $modelLsdMethods = array(
'load',
'save',
'delete'
);
- load
- Find MIN & MAX value of product attribute in a large category
- ...
Security
Acl
Missing the %s() ACL method in the %s class.
const PARENT_CLASS_NAME = 'Mage_Adminhtml_Controller_Action';
const REQUIRED_ACL_METHOD_NAME = '_isAllowed';
...
Discouraged Function
public $forbiddenFunctions = array(
'^is_dir' => null,
'^is_file$' => null,
'^pathinfo$' => null,
);
...
Forbidden Function
public $forbiddenFunctions = array(
'^assert$' => null,
'^bind_textdomain_codeset$' => null,
'^bindtextdomain$' => null,
'^bz.*$' => null,
'^call_user_func$' => null,
'^call_user_func_array$' => null,
'^chdir$' => null,
'^chgrp$' => null,
'^chmod$' => null,
'^chown$' => null,
'^chroot$' => null,
'^com_load_typelib$' => null,
'^copy$' => null,
'^create_function$' => null,
'^curl_.*$' => null,
'^cyrus_connect$' => null,
'^dba_.*$' => null,
'^dbase_.*$' => null,
'^dbx_.*$' => null,
'^dcgettext$' => null,
'^dcngettext$' => null,
'^dgettext$' => null,
'^dio_.*$' => null,
'^dirname$' => null,
'^dngettext$' => null,
'^domxml_.*$' => null,
'^exec$' => null,
'^fbsql_.*$' => null,
'^fdf_add_doc_javascript$' => null,
'^fdf_open$' => null,
'^fopen$' => null,
'^fsockopen$' => null,
'^ftp_.*$' => null,
'^fwrite$' => null,
'^gettext$' => null,
'^gz.*$' => null,
'^header$' => null,
'^highlight_file$' => null,
'^ibase_.*$' => null,
'^id3_set_tag$' => null,
'^ifx_.*$' => null,
'^image.*$' => null,
'^imap_.*$' => null,
'^ingres_.*$' => null,
'^ircg_.*$' => null,
'^ldap_.*$' => null,
'^link$' => null,
'^mail$' => null,
'^mb_send_mail$' => null,
'^mkdir$' => null,
'^move_uploaded_file$' => null,
'^msession_.*$' => null,
'^msg_send$' => null,
'^msql$' => null,
'^msql_.*$' => null,
'^mssql_.*$' => null,
'^mysql_.*$' => null,
'^odbc_.*$' => null,
'^opendir$' => null,
'^openlog$' => null,
'^ora_.*$' => null,
'^ovrimos_.*$' => null,
'^parse_ini_file$' => null,
'^parse_str$' => null,
'^parse_url$' => null,
'^parsekit_compile_string$' => null,
'^passthru$' => null,
'^pcntl_.*$' => null,
'^posix_.*$' => null,
'^pfpro_.*$' => null,
'^pfsockopen$' => null,
'^pg_.*$' => null,
'^php_check_syntax$' => null,
'^popen$' => null,
'^print_r$' => null,
'^printf$' => null,
'^proc_open$' => null,
'^putenv$' => null,
'^readfile$' => null,
'^readgzfile$' => null,
'^readline$' => null,
'^readlink$' => null,
'^register_shutdown_function$' => null,
'^register_tick_function$' => null,
'^rename$' => null,
'^rmdir$' => null,
'^scandir$' => null,
'^session_.*$' => null,
'^set_include_path$' => null,
'^set_ini$' => null,
'^set_time_limit$' => null,
'^setcookie$' => null,
'^setlocale$' => null,
'^setrawcookie$' => null,
'^shell_exec$' => null,
'^sleep$' => null,
'^socket_.*$' => null,
'^stream_.*$' => null,
'^sybase_.*$' => null,
'^symlink$' => null,
'^syslog$' => null,
'^system$' => null,
'^touch$' => null,
'^trigger_error$' => null,
'^unlink$' => null,
'^vprintf$' => null,
'^mysqli.*$' => null,
'^oci_connect$' => null,
'^oci_pconnect$' => null,
'^quotemeta$' => null,
'^sqlite_popen$' => null,
'^time_nanosleep$' => null,
'^base64_decode$' => null,
'^base_convert$' => null,
'^basename$' => null,
'^chr$' => null,
'^convert_cyr_string$' => null,
'^dba_nextkey$' => null,
'^dns_get_record$' => null,
'^extract$' => null,
'^fdf_.*$' => null,
'^fget.*$' => null,
'^fread$' => null,
'^fflush$' => null,
'^get_browser$' => null,
'^get_headers$' => null,
'^get_meta_tags$' => null,
'^getallheaders$' => null,
'^getenv$' => null,
'^getopt$' => null,
'^headers_list$' => null,
'^hebrev$' => null,
'^hebrevc$' => null,
'^highlight_string$' => null,
'^html_entity_decode$' => null,
'^ibase_blob_import$' => null,
'^id3_get_tag$' => null,
'^import_request_variables$' => null,
'^ircg_nickname_unescape$' => null,
'^ldap_get_values$' => null,
'^mb_decode_mimeheader$' => null,
'^mb_parse_str$' => null,
'^mcrypt_decrypt$' => null,
'^mdecrypt_generic$' => null,
'^msg_receive$' => null,
'^ngettext$' => null,
'^ob_get_contents$' => null,
'^ob_get_flush$' => null,
'^rawurldecode$' => null,
'^shm_get_var$' => null,
'^stripcslashes$' => null,
'^stripslashes$' => null,
'^token_get_all$' => null,
'^unpack$' => null,
'^convert_uudecode$' => null,
'^iconv_mime_decode$' => null,
'^iconv_mime_decode_headers$' => null,
'^iconv_mime_encode$' => null,
'^iconv_set_encoding$' => null,
'^php_strip_whitespace$' => null,
'^addcslashes$' => null,
'^addslashes$' => null,
'^escapeshellarg$' => null,
'^escapeshellcmd$' => null,
'^gettype$' => null,
'^var_dump$' => null,
'^tempnam$' => null,
'^realpath$' => null,
'^linkinfo$' => null,
'^lstat$' => null,
'^stat$' => null,
'^lchgrp$' => null,
'^lchown$' => null,
'^show_source$' => null,
'^is_executable$' => null,
'^is_link$' => null,
'^is_readable$' => null,
'^is_writable$' => null,
'^is_writeable$' => null,
'^is_uploaded_file$' => null,
'^glob$' => null,
'^ssh2_.*$' => null,
'^delete$' => null,
'^file.*$' => null,
);
- ...
- curl_: - https://magento.stackexchange.com/a/178642/46249
- file_exists - https://magento.stackexchange.com/a/178641/46249
- ...
Include File
"%s" statement detected. File manipulations are discouraged.
... Statement is not a function, no parentheses are required.
... Passing urls is forbidden.
... Concatenating is forbidden.
... Variables inside are insecure.
public $urlPattern = '#(https?|ftp)://.*#i';
...
Language Construct
Incorrect usage of back quote string constant. Back quotes should be always inside strings.
Use of %s language construct is discouraged.
return array(
T_EXIT,
T_ECHO,
T_PRINT,
T_BACKTICK
);
...
Superglobal
Direct use of %s Superglobal detected.
public $superGlobalErrors = array(
'$GLOBALS',
'$_GET',
'$_POST',
'$_SESSION',
'$_REQUEST',
'$_ENV'
);
public $superGlobalWarning = array(
'$_FILES',
'$_COOKIE',
'$_SERVER',
);
Sql
Raw Query
Possible raw SQL statement %s detected
public $statements = array(
'SELECT',
'UPDATE',
'INSERT',
'CREATE',
'DELETE',
'ALTER',
'DROP'
);
public $queryFunctions = array(
'query',
'raw_query'
);
...
Slow Query
Possible slow SQL statement %s detected
Possible slow SQL method %s detected
public $adapterMethods = array(
'group',
'having',
'distinct',
'addLikeEscape',
'escapeLikeValue',
'union',
'orHaving',
);
public $rawStatements = array(
'GROUP BY',
'HAVING',
'DISTINCT',
'LIKE',
'UNION',
);
...
Strings
RegEx
Possible executable regular expression in %s. Make sure that the pattern doesn't contain "e" modifier
public $functions = array(
'preg_replace',
);
...
String Concat
Use of + operator to concatenate two strings detected
...
String Position
Identical operator === is not used for testing the return value of %s function
public $functions = array(
'strpos',
'stripos',
);
- http://php.net/manual/en/function.strpos.php#refsect1-function.strpos-examples
- http://php.net/manual/en/function.stripos.php#refsect1-function.stripos-examples
Related questions & answers for best-practice
- What is faster - getting raw attribute value or use collection?
- Magento 1: Performance optimizations to delete entities
magento-1 best-practice coding-standards magento-ecg
|
show 2 more comments
There is something like a coding standard
for Magento 1, called ECG
where numerous things should be avoided or methods that should not be used.
Let's try to create a list that covers all cases that are throwing "errors" or "warning" in your code.
Below you'll find a list with all possible warnings. I'll update this post at regular intervals and link to given and upvoted answers.
Note: please try to avoid duplicate answers ;)
Download: https://github.com/magento-ecg/coding-standard
ECG Sniffs
Classes
Mysql4
Mysql4 classes are obsolete.
- How to handle deprecated “Mysql4” classes when rewriting resource models
- Magento 1.9 module oddly breaking when changing resource folder from Mysql4 to Resource
Object Instantiation
Direct object instantiation (class %s) is discouraged in Magento.
protected $disallowedClassPrefixes = array(
'Mage_',
'Enterprise_',
);
...
PHP
Goto
Use of goto is discouraged.
...
Namespace
Namespace for "'.$exceptionClassName.'" class is not specified.
...
Private Class Member
Private class member detected.
...
Var
Private class member detected.
...
Performance
Collection Count
Unnecessary loading of a Magento data collection. Use the getSize() method instead.
- How to check if a collection has items?
FetchAll
fetchAll() can be memory inefficient for large data sets.
...
GetFirstItem
getFirstItem() does not limit the result of collection load to one item.
- GetFirstItem - https://magento.stackexchange.com/a/179309/46249
Loop
Array size calculation function %s detected in loop
Model LSD method %s detected in loop
Data load %s method detected in loop
protected $countFunctions = array(
'sizeof',
'count'
);
protected $modelLsdMethods = array(
'load',
'save',
'delete'
);
- load
- Find MIN & MAX value of product attribute in a large category
- ...
Security
Acl
Missing the %s() ACL method in the %s class.
const PARENT_CLASS_NAME = 'Mage_Adminhtml_Controller_Action';
const REQUIRED_ACL_METHOD_NAME = '_isAllowed';
...
Discouraged Function
public $forbiddenFunctions = array(
'^is_dir' => null,
'^is_file$' => null,
'^pathinfo$' => null,
);
...
Forbidden Function
public $forbiddenFunctions = array(
'^assert$' => null,
'^bind_textdomain_codeset$' => null,
'^bindtextdomain$' => null,
'^bz.*$' => null,
'^call_user_func$' => null,
'^call_user_func_array$' => null,
'^chdir$' => null,
'^chgrp$' => null,
'^chmod$' => null,
'^chown$' => null,
'^chroot$' => null,
'^com_load_typelib$' => null,
'^copy$' => null,
'^create_function$' => null,
'^curl_.*$' => null,
'^cyrus_connect$' => null,
'^dba_.*$' => null,
'^dbase_.*$' => null,
'^dbx_.*$' => null,
'^dcgettext$' => null,
'^dcngettext$' => null,
'^dgettext$' => null,
'^dio_.*$' => null,
'^dirname$' => null,
'^dngettext$' => null,
'^domxml_.*$' => null,
'^exec$' => null,
'^fbsql_.*$' => null,
'^fdf_add_doc_javascript$' => null,
'^fdf_open$' => null,
'^fopen$' => null,
'^fsockopen$' => null,
'^ftp_.*$' => null,
'^fwrite$' => null,
'^gettext$' => null,
'^gz.*$' => null,
'^header$' => null,
'^highlight_file$' => null,
'^ibase_.*$' => null,
'^id3_set_tag$' => null,
'^ifx_.*$' => null,
'^image.*$' => null,
'^imap_.*$' => null,
'^ingres_.*$' => null,
'^ircg_.*$' => null,
'^ldap_.*$' => null,
'^link$' => null,
'^mail$' => null,
'^mb_send_mail$' => null,
'^mkdir$' => null,
'^move_uploaded_file$' => null,
'^msession_.*$' => null,
'^msg_send$' => null,
'^msql$' => null,
'^msql_.*$' => null,
'^mssql_.*$' => null,
'^mysql_.*$' => null,
'^odbc_.*$' => null,
'^opendir$' => null,
'^openlog$' => null,
'^ora_.*$' => null,
'^ovrimos_.*$' => null,
'^parse_ini_file$' => null,
'^parse_str$' => null,
'^parse_url$' => null,
'^parsekit_compile_string$' => null,
'^passthru$' => null,
'^pcntl_.*$' => null,
'^posix_.*$' => null,
'^pfpro_.*$' => null,
'^pfsockopen$' => null,
'^pg_.*$' => null,
'^php_check_syntax$' => null,
'^popen$' => null,
'^print_r$' => null,
'^printf$' => null,
'^proc_open$' => null,
'^putenv$' => null,
'^readfile$' => null,
'^readgzfile$' => null,
'^readline$' => null,
'^readlink$' => null,
'^register_shutdown_function$' => null,
'^register_tick_function$' => null,
'^rename$' => null,
'^rmdir$' => null,
'^scandir$' => null,
'^session_.*$' => null,
'^set_include_path$' => null,
'^set_ini$' => null,
'^set_time_limit$' => null,
'^setcookie$' => null,
'^setlocale$' => null,
'^setrawcookie$' => null,
'^shell_exec$' => null,
'^sleep$' => null,
'^socket_.*$' => null,
'^stream_.*$' => null,
'^sybase_.*$' => null,
'^symlink$' => null,
'^syslog$' => null,
'^system$' => null,
'^touch$' => null,
'^trigger_error$' => null,
'^unlink$' => null,
'^vprintf$' => null,
'^mysqli.*$' => null,
'^oci_connect$' => null,
'^oci_pconnect$' => null,
'^quotemeta$' => null,
'^sqlite_popen$' => null,
'^time_nanosleep$' => null,
'^base64_decode$' => null,
'^base_convert$' => null,
'^basename$' => null,
'^chr$' => null,
'^convert_cyr_string$' => null,
'^dba_nextkey$' => null,
'^dns_get_record$' => null,
'^extract$' => null,
'^fdf_.*$' => null,
'^fget.*$' => null,
'^fread$' => null,
'^fflush$' => null,
'^get_browser$' => null,
'^get_headers$' => null,
'^get_meta_tags$' => null,
'^getallheaders$' => null,
'^getenv$' => null,
'^getopt$' => null,
'^headers_list$' => null,
'^hebrev$' => null,
'^hebrevc$' => null,
'^highlight_string$' => null,
'^html_entity_decode$' => null,
'^ibase_blob_import$' => null,
'^id3_get_tag$' => null,
'^import_request_variables$' => null,
'^ircg_nickname_unescape$' => null,
'^ldap_get_values$' => null,
'^mb_decode_mimeheader$' => null,
'^mb_parse_str$' => null,
'^mcrypt_decrypt$' => null,
'^mdecrypt_generic$' => null,
'^msg_receive$' => null,
'^ngettext$' => null,
'^ob_get_contents$' => null,
'^ob_get_flush$' => null,
'^rawurldecode$' => null,
'^shm_get_var$' => null,
'^stripcslashes$' => null,
'^stripslashes$' => null,
'^token_get_all$' => null,
'^unpack$' => null,
'^convert_uudecode$' => null,
'^iconv_mime_decode$' => null,
'^iconv_mime_decode_headers$' => null,
'^iconv_mime_encode$' => null,
'^iconv_set_encoding$' => null,
'^php_strip_whitespace$' => null,
'^addcslashes$' => null,
'^addslashes$' => null,
'^escapeshellarg$' => null,
'^escapeshellcmd$' => null,
'^gettype$' => null,
'^var_dump$' => null,
'^tempnam$' => null,
'^realpath$' => null,
'^linkinfo$' => null,
'^lstat$' => null,
'^stat$' => null,
'^lchgrp$' => null,
'^lchown$' => null,
'^show_source$' => null,
'^is_executable$' => null,
'^is_link$' => null,
'^is_readable$' => null,
'^is_writable$' => null,
'^is_writeable$' => null,
'^is_uploaded_file$' => null,
'^glob$' => null,
'^ssh2_.*$' => null,
'^delete$' => null,
'^file.*$' => null,
);
- ...
- curl_: - https://magento.stackexchange.com/a/178642/46249
- file_exists - https://magento.stackexchange.com/a/178641/46249
- ...
Include File
"%s" statement detected. File manipulations are discouraged.
... Statement is not a function, no parentheses are required.
... Passing urls is forbidden.
... Concatenating is forbidden.
... Variables inside are insecure.
public $urlPattern = '#(https?|ftp)://.*#i';
...
Language Construct
Incorrect usage of back quote string constant. Back quotes should be always inside strings.
Use of %s language construct is discouraged.
return array(
T_EXIT,
T_ECHO,
T_PRINT,
T_BACKTICK
);
...
Superglobal
Direct use of %s Superglobal detected.
public $superGlobalErrors = array(
'$GLOBALS',
'$_GET',
'$_POST',
'$_SESSION',
'$_REQUEST',
'$_ENV'
);
public $superGlobalWarning = array(
'$_FILES',
'$_COOKIE',
'$_SERVER',
);
Sql
Raw Query
Possible raw SQL statement %s detected
public $statements = array(
'SELECT',
'UPDATE',
'INSERT',
'CREATE',
'DELETE',
'ALTER',
'DROP'
);
public $queryFunctions = array(
'query',
'raw_query'
);
...
Slow Query
Possible slow SQL statement %s detected
Possible slow SQL method %s detected
public $adapterMethods = array(
'group',
'having',
'distinct',
'addLikeEscape',
'escapeLikeValue',
'union',
'orHaving',
);
public $rawStatements = array(
'GROUP BY',
'HAVING',
'DISTINCT',
'LIKE',
'UNION',
);
...
Strings
RegEx
Possible executable regular expression in %s. Make sure that the pattern doesn't contain "e" modifier
public $functions = array(
'preg_replace',
);
...
String Concat
Use of + operator to concatenate two strings detected
...
String Position
Identical operator === is not used for testing the return value of %s function
public $functions = array(
'strpos',
'stripos',
);
- http://php.net/manual/en/function.strpos.php#refsect1-function.strpos-examples
- http://php.net/manual/en/function.stripos.php#refsect1-function.stripos-examples
Related questions & answers for best-practice
- What is faster - getting raw attribute value or use collection?
- Magento 1: Performance optimizations to delete entities
magento-1 best-practice coding-standards magento-ecg
LOL about this post, you wrote almost a doc :)
– PЯINCƏ
Jul 22 '17 at 22:49
@Prince someone else could help a bit to complete this :P
– sv3n
Jul 22 '17 at 22:59
I don't think so :)
– PЯINCƏ
Jul 22 '17 at 23:04
any alternative for stripcslashes()? @sv3n thanks for such description question and answers :)
– Keyur Shah
Jan 30 '18 at 14:05
@KeyurShah No. Either ignore warning or try to avoid "before" :) In wich case you use it? Maybe add this as question?
– sv3n
Jan 30 '18 at 21:26
|
show 2 more comments
There is something like a coding standard
for Magento 1, called ECG
where numerous things should be avoided or methods that should not be used.
Let's try to create a list that covers all cases that are throwing "errors" or "warning" in your code.
Below you'll find a list with all possible warnings. I'll update this post at regular intervals and link to given and upvoted answers.
Note: please try to avoid duplicate answers ;)
Download: https://github.com/magento-ecg/coding-standard
ECG Sniffs
Classes
Mysql4
Mysql4 classes are obsolete.
- How to handle deprecated “Mysql4” classes when rewriting resource models
- Magento 1.9 module oddly breaking when changing resource folder from Mysql4 to Resource
Object Instantiation
Direct object instantiation (class %s) is discouraged in Magento.
protected $disallowedClassPrefixes = array(
'Mage_',
'Enterprise_',
);
...
PHP
Goto
Use of goto is discouraged.
...
Namespace
Namespace for "'.$exceptionClassName.'" class is not specified.
...
Private Class Member
Private class member detected.
...
Var
Private class member detected.
...
Performance
Collection Count
Unnecessary loading of a Magento data collection. Use the getSize() method instead.
- How to check if a collection has items?
FetchAll
fetchAll() can be memory inefficient for large data sets.
...
GetFirstItem
getFirstItem() does not limit the result of collection load to one item.
- GetFirstItem - https://magento.stackexchange.com/a/179309/46249
Loop
Array size calculation function %s detected in loop
Model LSD method %s detected in loop
Data load %s method detected in loop
protected $countFunctions = array(
'sizeof',
'count'
);
protected $modelLsdMethods = array(
'load',
'save',
'delete'
);
- load
- Find MIN & MAX value of product attribute in a large category
- ...
Security
Acl
Missing the %s() ACL method in the %s class.
const PARENT_CLASS_NAME = 'Mage_Adminhtml_Controller_Action';
const REQUIRED_ACL_METHOD_NAME = '_isAllowed';
...
Discouraged Function
public $forbiddenFunctions = array(
'^is_dir' => null,
'^is_file$' => null,
'^pathinfo$' => null,
);
...
Forbidden Function
public $forbiddenFunctions = array(
'^assert$' => null,
'^bind_textdomain_codeset$' => null,
'^bindtextdomain$' => null,
'^bz.*$' => null,
'^call_user_func$' => null,
'^call_user_func_array$' => null,
'^chdir$' => null,
'^chgrp$' => null,
'^chmod$' => null,
'^chown$' => null,
'^chroot$' => null,
'^com_load_typelib$' => null,
'^copy$' => null,
'^create_function$' => null,
'^curl_.*$' => null,
'^cyrus_connect$' => null,
'^dba_.*$' => null,
'^dbase_.*$' => null,
'^dbx_.*$' => null,
'^dcgettext$' => null,
'^dcngettext$' => null,
'^dgettext$' => null,
'^dio_.*$' => null,
'^dirname$' => null,
'^dngettext$' => null,
'^domxml_.*$' => null,
'^exec$' => null,
'^fbsql_.*$' => null,
'^fdf_add_doc_javascript$' => null,
'^fdf_open$' => null,
'^fopen$' => null,
'^fsockopen$' => null,
'^ftp_.*$' => null,
'^fwrite$' => null,
'^gettext$' => null,
'^gz.*$' => null,
'^header$' => null,
'^highlight_file$' => null,
'^ibase_.*$' => null,
'^id3_set_tag$' => null,
'^ifx_.*$' => null,
'^image.*$' => null,
'^imap_.*$' => null,
'^ingres_.*$' => null,
'^ircg_.*$' => null,
'^ldap_.*$' => null,
'^link$' => null,
'^mail$' => null,
'^mb_send_mail$' => null,
'^mkdir$' => null,
'^move_uploaded_file$' => null,
'^msession_.*$' => null,
'^msg_send$' => null,
'^msql$' => null,
'^msql_.*$' => null,
'^mssql_.*$' => null,
'^mysql_.*$' => null,
'^odbc_.*$' => null,
'^opendir$' => null,
'^openlog$' => null,
'^ora_.*$' => null,
'^ovrimos_.*$' => null,
'^parse_ini_file$' => null,
'^parse_str$' => null,
'^parse_url$' => null,
'^parsekit_compile_string$' => null,
'^passthru$' => null,
'^pcntl_.*$' => null,
'^posix_.*$' => null,
'^pfpro_.*$' => null,
'^pfsockopen$' => null,
'^pg_.*$' => null,
'^php_check_syntax$' => null,
'^popen$' => null,
'^print_r$' => null,
'^printf$' => null,
'^proc_open$' => null,
'^putenv$' => null,
'^readfile$' => null,
'^readgzfile$' => null,
'^readline$' => null,
'^readlink$' => null,
'^register_shutdown_function$' => null,
'^register_tick_function$' => null,
'^rename$' => null,
'^rmdir$' => null,
'^scandir$' => null,
'^session_.*$' => null,
'^set_include_path$' => null,
'^set_ini$' => null,
'^set_time_limit$' => null,
'^setcookie$' => null,
'^setlocale$' => null,
'^setrawcookie$' => null,
'^shell_exec$' => null,
'^sleep$' => null,
'^socket_.*$' => null,
'^stream_.*$' => null,
'^sybase_.*$' => null,
'^symlink$' => null,
'^syslog$' => null,
'^system$' => null,
'^touch$' => null,
'^trigger_error$' => null,
'^unlink$' => null,
'^vprintf$' => null,
'^mysqli.*$' => null,
'^oci_connect$' => null,
'^oci_pconnect$' => null,
'^quotemeta$' => null,
'^sqlite_popen$' => null,
'^time_nanosleep$' => null,
'^base64_decode$' => null,
'^base_convert$' => null,
'^basename$' => null,
'^chr$' => null,
'^convert_cyr_string$' => null,
'^dba_nextkey$' => null,
'^dns_get_record$' => null,
'^extract$' => null,
'^fdf_.*$' => null,
'^fget.*$' => null,
'^fread$' => null,
'^fflush$' => null,
'^get_browser$' => null,
'^get_headers$' => null,
'^get_meta_tags$' => null,
'^getallheaders$' => null,
'^getenv$' => null,
'^getopt$' => null,
'^headers_list$' => null,
'^hebrev$' => null,
'^hebrevc$' => null,
'^highlight_string$' => null,
'^html_entity_decode$' => null,
'^ibase_blob_import$' => null,
'^id3_get_tag$' => null,
'^import_request_variables$' => null,
'^ircg_nickname_unescape$' => null,
'^ldap_get_values$' => null,
'^mb_decode_mimeheader$' => null,
'^mb_parse_str$' => null,
'^mcrypt_decrypt$' => null,
'^mdecrypt_generic$' => null,
'^msg_receive$' => null,
'^ngettext$' => null,
'^ob_get_contents$' => null,
'^ob_get_flush$' => null,
'^rawurldecode$' => null,
'^shm_get_var$' => null,
'^stripcslashes$' => null,
'^stripslashes$' => null,
'^token_get_all$' => null,
'^unpack$' => null,
'^convert_uudecode$' => null,
'^iconv_mime_decode$' => null,
'^iconv_mime_decode_headers$' => null,
'^iconv_mime_encode$' => null,
'^iconv_set_encoding$' => null,
'^php_strip_whitespace$' => null,
'^addcslashes$' => null,
'^addslashes$' => null,
'^escapeshellarg$' => null,
'^escapeshellcmd$' => null,
'^gettype$' => null,
'^var_dump$' => null,
'^tempnam$' => null,
'^realpath$' => null,
'^linkinfo$' => null,
'^lstat$' => null,
'^stat$' => null,
'^lchgrp$' => null,
'^lchown$' => null,
'^show_source$' => null,
'^is_executable$' => null,
'^is_link$' => null,
'^is_readable$' => null,
'^is_writable$' => null,
'^is_writeable$' => null,
'^is_uploaded_file$' => null,
'^glob$' => null,
'^ssh2_.*$' => null,
'^delete$' => null,
'^file.*$' => null,
);
- ...
- curl_: - https://magento.stackexchange.com/a/178642/46249
- file_exists - https://magento.stackexchange.com/a/178641/46249
- ...
Include File
"%s" statement detected. File manipulations are discouraged.
... Statement is not a function, no parentheses are required.
... Passing urls is forbidden.
... Concatenating is forbidden.
... Variables inside are insecure.
public $urlPattern = '#(https?|ftp)://.*#i';
...
Language Construct
Incorrect usage of back quote string constant. Back quotes should be always inside strings.
Use of %s language construct is discouraged.
return array(
T_EXIT,
T_ECHO,
T_PRINT,
T_BACKTICK
);
...
Superglobal
Direct use of %s Superglobal detected.
public $superGlobalErrors = array(
'$GLOBALS',
'$_GET',
'$_POST',
'$_SESSION',
'$_REQUEST',
'$_ENV'
);
public $superGlobalWarning = array(
'$_FILES',
'$_COOKIE',
'$_SERVER',
);
Sql
Raw Query
Possible raw SQL statement %s detected
public $statements = array(
'SELECT',
'UPDATE',
'INSERT',
'CREATE',
'DELETE',
'ALTER',
'DROP'
);
public $queryFunctions = array(
'query',
'raw_query'
);
...
Slow Query
Possible slow SQL statement %s detected
Possible slow SQL method %s detected
public $adapterMethods = array(
'group',
'having',
'distinct',
'addLikeEscape',
'escapeLikeValue',
'union',
'orHaving',
);
public $rawStatements = array(
'GROUP BY',
'HAVING',
'DISTINCT',
'LIKE',
'UNION',
);
...
Strings
RegEx
Possible executable regular expression in %s. Make sure that the pattern doesn't contain "e" modifier
public $functions = array(
'preg_replace',
);
...
String Concat
Use of + operator to concatenate two strings detected
...
String Position
Identical operator === is not used for testing the return value of %s function
public $functions = array(
'strpos',
'stripos',
);
- http://php.net/manual/en/function.strpos.php#refsect1-function.strpos-examples
- http://php.net/manual/en/function.stripos.php#refsect1-function.stripos-examples
Related questions & answers for best-practice
- What is faster - getting raw attribute value or use collection?
- Magento 1: Performance optimizations to delete entities
magento-1 best-practice coding-standards magento-ecg
There is something like a coding standard
for Magento 1, called ECG
where numerous things should be avoided or methods that should not be used.
Let's try to create a list that covers all cases that are throwing "errors" or "warning" in your code.
Below you'll find a list with all possible warnings. I'll update this post at regular intervals and link to given and upvoted answers.
Note: please try to avoid duplicate answers ;)
Download: https://github.com/magento-ecg/coding-standard
ECG Sniffs
Classes
Mysql4
Mysql4 classes are obsolete.
- How to handle deprecated “Mysql4” classes when rewriting resource models
- Magento 1.9 module oddly breaking when changing resource folder from Mysql4 to Resource
Object Instantiation
Direct object instantiation (class %s) is discouraged in Magento.
protected $disallowedClassPrefixes = array(
'Mage_',
'Enterprise_',
);
...
PHP
Goto
Use of goto is discouraged.
...
Namespace
Namespace for "'.$exceptionClassName.'" class is not specified.
...
Private Class Member
Private class member detected.
...
Var
Private class member detected.
...
Performance
Collection Count
Unnecessary loading of a Magento data collection. Use the getSize() method instead.
- How to check if a collection has items?
FetchAll
fetchAll() can be memory inefficient for large data sets.
...
GetFirstItem
getFirstItem() does not limit the result of collection load to one item.
- GetFirstItem - https://magento.stackexchange.com/a/179309/46249
Loop
Array size calculation function %s detected in loop
Model LSD method %s detected in loop
Data load %s method detected in loop
protected $countFunctions = array(
'sizeof',
'count'
);
protected $modelLsdMethods = array(
'load',
'save',
'delete'
);
- load
- Find MIN & MAX value of product attribute in a large category
- ...
Security
Acl
Missing the %s() ACL method in the %s class.
const PARENT_CLASS_NAME = 'Mage_Adminhtml_Controller_Action';
const REQUIRED_ACL_METHOD_NAME = '_isAllowed';
...
Discouraged Function
public $forbiddenFunctions = array(
'^is_dir' => null,
'^is_file$' => null,
'^pathinfo$' => null,
);
...
Forbidden Function
public $forbiddenFunctions = array(
'^assert$' => null,
'^bind_textdomain_codeset$' => null,
'^bindtextdomain$' => null,
'^bz.*$' => null,
'^call_user_func$' => null,
'^call_user_func_array$' => null,
'^chdir$' => null,
'^chgrp$' => null,
'^chmod$' => null,
'^chown$' => null,
'^chroot$' => null,
'^com_load_typelib$' => null,
'^copy$' => null,
'^create_function$' => null,
'^curl_.*$' => null,
'^cyrus_connect$' => null,
'^dba_.*$' => null,
'^dbase_.*$' => null,
'^dbx_.*$' => null,
'^dcgettext$' => null,
'^dcngettext$' => null,
'^dgettext$' => null,
'^dio_.*$' => null,
'^dirname$' => null,
'^dngettext$' => null,
'^domxml_.*$' => null,
'^exec$' => null,
'^fbsql_.*$' => null,
'^fdf_add_doc_javascript$' => null,
'^fdf_open$' => null,
'^fopen$' => null,
'^fsockopen$' => null,
'^ftp_.*$' => null,
'^fwrite$' => null,
'^gettext$' => null,
'^gz.*$' => null,
'^header$' => null,
'^highlight_file$' => null,
'^ibase_.*$' => null,
'^id3_set_tag$' => null,
'^ifx_.*$' => null,
'^image.*$' => null,
'^imap_.*$' => null,
'^ingres_.*$' => null,
'^ircg_.*$' => null,
'^ldap_.*$' => null,
'^link$' => null,
'^mail$' => null,
'^mb_send_mail$' => null,
'^mkdir$' => null,
'^move_uploaded_file$' => null,
'^msession_.*$' => null,
'^msg_send$' => null,
'^msql$' => null,
'^msql_.*$' => null,
'^mssql_.*$' => null,
'^mysql_.*$' => null,
'^odbc_.*$' => null,
'^opendir$' => null,
'^openlog$' => null,
'^ora_.*$' => null,
'^ovrimos_.*$' => null,
'^parse_ini_file$' => null,
'^parse_str$' => null,
'^parse_url$' => null,
'^parsekit_compile_string$' => null,
'^passthru$' => null,
'^pcntl_.*$' => null,
'^posix_.*$' => null,
'^pfpro_.*$' => null,
'^pfsockopen$' => null,
'^pg_.*$' => null,
'^php_check_syntax$' => null,
'^popen$' => null,
'^print_r$' => null,
'^printf$' => null,
'^proc_open$' => null,
'^putenv$' => null,
'^readfile$' => null,
'^readgzfile$' => null,
'^readline$' => null,
'^readlink$' => null,
'^register_shutdown_function$' => null,
'^register_tick_function$' => null,
'^rename$' => null,
'^rmdir$' => null,
'^scandir$' => null,
'^session_.*$' => null,
'^set_include_path$' => null,
'^set_ini$' => null,
'^set_time_limit$' => null,
'^setcookie$' => null,
'^setlocale$' => null,
'^setrawcookie$' => null,
'^shell_exec$' => null,
'^sleep$' => null,
'^socket_.*$' => null,
'^stream_.*$' => null,
'^sybase_.*$' => null,
'^symlink$' => null,
'^syslog$' => null,
'^system$' => null,
'^touch$' => null,
'^trigger_error$' => null,
'^unlink$' => null,
'^vprintf$' => null,
'^mysqli.*$' => null,
'^oci_connect$' => null,
'^oci_pconnect$' => null,
'^quotemeta$' => null,
'^sqlite_popen$' => null,
'^time_nanosleep$' => null,
'^base64_decode$' => null,
'^base_convert$' => null,
'^basename$' => null,
'^chr$' => null,
'^convert_cyr_string$' => null,
'^dba_nextkey$' => null,
'^dns_get_record$' => null,
'^extract$' => null,
'^fdf_.*$' => null,
'^fget.*$' => null,
'^fread$' => null,
'^fflush$' => null,
'^get_browser$' => null,
'^get_headers$' => null,
'^get_meta_tags$' => null,
'^getallheaders$' => null,
'^getenv$' => null,
'^getopt$' => null,
'^headers_list$' => null,
'^hebrev$' => null,
'^hebrevc$' => null,
'^highlight_string$' => null,
'^html_entity_decode$' => null,
'^ibase_blob_import$' => null,
'^id3_get_tag$' => null,
'^import_request_variables$' => null,
'^ircg_nickname_unescape$' => null,
'^ldap_get_values$' => null,
'^mb_decode_mimeheader$' => null,
'^mb_parse_str$' => null,
'^mcrypt_decrypt$' => null,
'^mdecrypt_generic$' => null,
'^msg_receive$' => null,
'^ngettext$' => null,
'^ob_get_contents$' => null,
'^ob_get_flush$' => null,
'^rawurldecode$' => null,
'^shm_get_var$' => null,
'^stripcslashes$' => null,
'^stripslashes$' => null,
'^token_get_all$' => null,
'^unpack$' => null,
'^convert_uudecode$' => null,
'^iconv_mime_decode$' => null,
'^iconv_mime_decode_headers$' => null,
'^iconv_mime_encode$' => null,
'^iconv_set_encoding$' => null,
'^php_strip_whitespace$' => null,
'^addcslashes$' => null,
'^addslashes$' => null,
'^escapeshellarg$' => null,
'^escapeshellcmd$' => null,
'^gettype$' => null,
'^var_dump$' => null,
'^tempnam$' => null,
'^realpath$' => null,
'^linkinfo$' => null,
'^lstat$' => null,
'^stat$' => null,
'^lchgrp$' => null,
'^lchown$' => null,
'^show_source$' => null,
'^is_executable$' => null,
'^is_link$' => null,
'^is_readable$' => null,
'^is_writable$' => null,
'^is_writeable$' => null,
'^is_uploaded_file$' => null,
'^glob$' => null,
'^ssh2_.*$' => null,
'^delete$' => null,
'^file.*$' => null,
);
- ...
- curl_: - https://magento.stackexchange.com/a/178642/46249
- file_exists - https://magento.stackexchange.com/a/178641/46249
- ...
Include File
"%s" statement detected. File manipulations are discouraged.
... Statement is not a function, no parentheses are required.
... Passing urls is forbidden.
... Concatenating is forbidden.
... Variables inside are insecure.
public $urlPattern = '#(https?|ftp)://.*#i';
...
Language Construct
Incorrect usage of back quote string constant. Back quotes should be always inside strings.
Use of %s language construct is discouraged.
return array(
T_EXIT,
T_ECHO,
T_PRINT,
T_BACKTICK
);
...
Superglobal
Direct use of %s Superglobal detected.
public $superGlobalErrors = array(
'$GLOBALS',
'$_GET',
'$_POST',
'$_SESSION',
'$_REQUEST',
'$_ENV'
);
public $superGlobalWarning = array(
'$_FILES',
'$_COOKIE',
'$_SERVER',
);
Sql
Raw Query
Possible raw SQL statement %s detected
public $statements = array(
'SELECT',
'UPDATE',
'INSERT',
'CREATE',
'DELETE',
'ALTER',
'DROP'
);
public $queryFunctions = array(
'query',
'raw_query'
);
...
Slow Query
Possible slow SQL statement %s detected
Possible slow SQL method %s detected
public $adapterMethods = array(
'group',
'having',
'distinct',
'addLikeEscape',
'escapeLikeValue',
'union',
'orHaving',
);
public $rawStatements = array(
'GROUP BY',
'HAVING',
'DISTINCT',
'LIKE',
'UNION',
);
...
Strings
RegEx
Possible executable regular expression in %s. Make sure that the pattern doesn't contain "e" modifier
public $functions = array(
'preg_replace',
);
...
String Concat
Use of + operator to concatenate two strings detected
...
String Position
Identical operator === is not used for testing the return value of %s function
public $functions = array(
'strpos',
'stripos',
);
- http://php.net/manual/en/function.strpos.php#refsect1-function.strpos-examples
- http://php.net/manual/en/function.stripos.php#refsect1-function.stripos-examples
Related questions & answers for best-practice
- What is faster - getting raw attribute value or use collection?
- Magento 1: Performance optimizations to delete entities
magento-1 best-practice coding-standards magento-ecg
magento-1 best-practice coding-standards magento-ecg
edited Jul 25 '17 at 1:39
sv3n
asked Jun 12 '17 at 17:01
sv3nsv3n
9,93662456
9,93662456
LOL about this post, you wrote almost a doc :)
– PЯINCƏ
Jul 22 '17 at 22:49
@Prince someone else could help a bit to complete this :P
– sv3n
Jul 22 '17 at 22:59
I don't think so :)
– PЯINCƏ
Jul 22 '17 at 23:04
any alternative for stripcslashes()? @sv3n thanks for such description question and answers :)
– Keyur Shah
Jan 30 '18 at 14:05
@KeyurShah No. Either ignore warning or try to avoid "before" :) In wich case you use it? Maybe add this as question?
– sv3n
Jan 30 '18 at 21:26
|
show 2 more comments
LOL about this post, you wrote almost a doc :)
– PЯINCƏ
Jul 22 '17 at 22:49
@Prince someone else could help a bit to complete this :P
– sv3n
Jul 22 '17 at 22:59
I don't think so :)
– PЯINCƏ
Jul 22 '17 at 23:04
any alternative for stripcslashes()? @sv3n thanks for such description question and answers :)
– Keyur Shah
Jan 30 '18 at 14:05
@KeyurShah No. Either ignore warning or try to avoid "before" :) In wich case you use it? Maybe add this as question?
– sv3n
Jan 30 '18 at 21:26
LOL about this post, you wrote almost a doc :)
– PЯINCƏ
Jul 22 '17 at 22:49
LOL about this post, you wrote almost a doc :)
– PЯINCƏ
Jul 22 '17 at 22:49
@Prince someone else could help a bit to complete this :P
– sv3n
Jul 22 '17 at 22:59
@Prince someone else could help a bit to complete this :P
– sv3n
Jul 22 '17 at 22:59
I don't think so :)
– PЯINCƏ
Jul 22 '17 at 23:04
I don't think so :)
– PЯINCƏ
Jul 22 '17 at 23:04
any alternative for stripcslashes()? @sv3n thanks for such description question and answers :)
– Keyur Shah
Jan 30 '18 at 14:05
any alternative for stripcslashes()? @sv3n thanks for such description question and answers :)
– Keyur Shah
Jan 30 '18 at 14:05
@KeyurShah No. Either ignore warning or try to avoid "before" :) In wich case you use it? Maybe add this as question?
– sv3n
Jan 30 '18 at 21:26
@KeyurShah No. Either ignore warning or try to avoid "before" :) In wich case you use it? Maybe add this as question?
– sv3n
Jan 30 '18 at 21:26
|
show 2 more comments
3 Answers
3
active
oldest
votes
Forbidden Function
file_exists()
The use of function file_exists() is forbidden
incorrect:
if (!file_exists($filePath)) {
...
}
correct:
$io = new Varien_Io_File();
if (!$io->fileExists($filePath)) {
...
}
or
$validatorNot = new Zend_Validate_File_NotExists($path);
if ($validatorNot->isValid($file)) {
...
}
add a comment |
GetFirstItem
getFirstItem() does not limit the result of collection load to one item.
incorrect:
$collection = Mage::getModel('catalog/category')
->load(41)
->getProductCollection()
->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight = $product->getData('weight');
correct:
Apply limit before grab data.
$collection->getSelect()->limit(1)
or
$collection->setPageSize(1, 1)
Expamples:
Collection with 750 products ...
Without limiting before:
- Total Incl. Wall Time (microsec): 2,116,522 microsecs
- Total Incl. CPU (microsecs): 2,101,688 microsecs
- Total Incl. MemUse (bytes): 4,783,504 bytes
- Total Incl. PeakMemUse (bytes): 4,363,112 bytes
- Number of Function Calls: 104,187
With using getSelect()->limit(1)
:
- Total Incl. Wall Time (microsec): 149,803 microsecs
- Total Incl. CPU (microsecs): 131,405 microsecs
- Total Incl. MemUse (bytes): 2,384,840 bytes
- Total Incl. PeakMemUse (bytes): 1,827,112 bytes
- Number of Function Calls: 5,327
With using setPageSize(1, 1)
- Total Incl. Wall Time (microsec): 155,025 microsecs
- Total Incl. CPU (microsecs): 136,191 microsecs
- Total Incl. MemUse (bytes): 2,413,128 bytes
- Total Incl. PeakMemUse (bytes): 1,856,064 bytes
- Number of Function Calls: 5,515
Note:
This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem()
instead.
I am gettingData access method LIMIT detected outside of Resource Model
when using limit`
– Amit Patel
Dec 12 '17 at 8:10
1
Here is more details
– Amit Patel
Dec 12 '17 at 10:35
add a comment |
Forbidden Function
curl_xyz
The use of function curl_init(), curl_setopt(), curl_exec(), curl_close() is forbidden
incorrect:
$ch = curl_init();
curl_setopt($connection, CURLOPT_HTTPHEADER, $header);
curl_setopt($connection, CURLOPT_POSTFIELDS, $request);
curl_setopt($connection, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
correct:
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_POSTFIELDS => $request
);
$curl = new Varien_Http_Adapter_Curl();
$curl->setOptions($options);
$curl->write(Zend_Http_Client::GET, $url, Zend_Http_Client::HTTP_0);
$response = $curl->read();
$curl->close();
I used above code and it is giving me errorUncaught Error: Class 'CustomRmaHelperVarien_Http_Adapter_Curl' not found
. How to use the class i found it in vendor but no luck.
– Nitin Pawar
Mar 5 '18 at 8:59
@NitinPawar can you please open a new question? Something seems to be wrong with your code.
– sv3n
Mar 5 '18 at 9:01
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f178640%2fecg-compliance-how-to-do%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Forbidden Function
file_exists()
The use of function file_exists() is forbidden
incorrect:
if (!file_exists($filePath)) {
...
}
correct:
$io = new Varien_Io_File();
if (!$io->fileExists($filePath)) {
...
}
or
$validatorNot = new Zend_Validate_File_NotExists($path);
if ($validatorNot->isValid($file)) {
...
}
add a comment |
Forbidden Function
file_exists()
The use of function file_exists() is forbidden
incorrect:
if (!file_exists($filePath)) {
...
}
correct:
$io = new Varien_Io_File();
if (!$io->fileExists($filePath)) {
...
}
or
$validatorNot = new Zend_Validate_File_NotExists($path);
if ($validatorNot->isValid($file)) {
...
}
add a comment |
Forbidden Function
file_exists()
The use of function file_exists() is forbidden
incorrect:
if (!file_exists($filePath)) {
...
}
correct:
$io = new Varien_Io_File();
if (!$io->fileExists($filePath)) {
...
}
or
$validatorNot = new Zend_Validate_File_NotExists($path);
if ($validatorNot->isValid($file)) {
...
}
Forbidden Function
file_exists()
The use of function file_exists() is forbidden
incorrect:
if (!file_exists($filePath)) {
...
}
correct:
$io = new Varien_Io_File();
if (!$io->fileExists($filePath)) {
...
}
or
$validatorNot = new Zend_Validate_File_NotExists($path);
if ($validatorNot->isValid($file)) {
...
}
edited Jun 16 '17 at 0:07
community wiki
2 revs
sv3n
add a comment |
add a comment |
GetFirstItem
getFirstItem() does not limit the result of collection load to one item.
incorrect:
$collection = Mage::getModel('catalog/category')
->load(41)
->getProductCollection()
->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight = $product->getData('weight');
correct:
Apply limit before grab data.
$collection->getSelect()->limit(1)
or
$collection->setPageSize(1, 1)
Expamples:
Collection with 750 products ...
Without limiting before:
- Total Incl. Wall Time (microsec): 2,116,522 microsecs
- Total Incl. CPU (microsecs): 2,101,688 microsecs
- Total Incl. MemUse (bytes): 4,783,504 bytes
- Total Incl. PeakMemUse (bytes): 4,363,112 bytes
- Number of Function Calls: 104,187
With using getSelect()->limit(1)
:
- Total Incl. Wall Time (microsec): 149,803 microsecs
- Total Incl. CPU (microsecs): 131,405 microsecs
- Total Incl. MemUse (bytes): 2,384,840 bytes
- Total Incl. PeakMemUse (bytes): 1,827,112 bytes
- Number of Function Calls: 5,327
With using setPageSize(1, 1)
- Total Incl. Wall Time (microsec): 155,025 microsecs
- Total Incl. CPU (microsecs): 136,191 microsecs
- Total Incl. MemUse (bytes): 2,413,128 bytes
- Total Incl. PeakMemUse (bytes): 1,856,064 bytes
- Number of Function Calls: 5,515
Note:
This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem()
instead.
I am gettingData access method LIMIT detected outside of Resource Model
when using limit`
– Amit Patel
Dec 12 '17 at 8:10
1
Here is more details
– Amit Patel
Dec 12 '17 at 10:35
add a comment |
GetFirstItem
getFirstItem() does not limit the result of collection load to one item.
incorrect:
$collection = Mage::getModel('catalog/category')
->load(41)
->getProductCollection()
->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight = $product->getData('weight');
correct:
Apply limit before grab data.
$collection->getSelect()->limit(1)
or
$collection->setPageSize(1, 1)
Expamples:
Collection with 750 products ...
Without limiting before:
- Total Incl. Wall Time (microsec): 2,116,522 microsecs
- Total Incl. CPU (microsecs): 2,101,688 microsecs
- Total Incl. MemUse (bytes): 4,783,504 bytes
- Total Incl. PeakMemUse (bytes): 4,363,112 bytes
- Number of Function Calls: 104,187
With using getSelect()->limit(1)
:
- Total Incl. Wall Time (microsec): 149,803 microsecs
- Total Incl. CPU (microsecs): 131,405 microsecs
- Total Incl. MemUse (bytes): 2,384,840 bytes
- Total Incl. PeakMemUse (bytes): 1,827,112 bytes
- Number of Function Calls: 5,327
With using setPageSize(1, 1)
- Total Incl. Wall Time (microsec): 155,025 microsecs
- Total Incl. CPU (microsecs): 136,191 microsecs
- Total Incl. MemUse (bytes): 2,413,128 bytes
- Total Incl. PeakMemUse (bytes): 1,856,064 bytes
- Number of Function Calls: 5,515
Note:
This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem()
instead.
I am gettingData access method LIMIT detected outside of Resource Model
when using limit`
– Amit Patel
Dec 12 '17 at 8:10
1
Here is more details
– Amit Patel
Dec 12 '17 at 10:35
add a comment |
GetFirstItem
getFirstItem() does not limit the result of collection load to one item.
incorrect:
$collection = Mage::getModel('catalog/category')
->load(41)
->getProductCollection()
->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight = $product->getData('weight');
correct:
Apply limit before grab data.
$collection->getSelect()->limit(1)
or
$collection->setPageSize(1, 1)
Expamples:
Collection with 750 products ...
Without limiting before:
- Total Incl. Wall Time (microsec): 2,116,522 microsecs
- Total Incl. CPU (microsecs): 2,101,688 microsecs
- Total Incl. MemUse (bytes): 4,783,504 bytes
- Total Incl. PeakMemUse (bytes): 4,363,112 bytes
- Number of Function Calls: 104,187
With using getSelect()->limit(1)
:
- Total Incl. Wall Time (microsec): 149,803 microsecs
- Total Incl. CPU (microsecs): 131,405 microsecs
- Total Incl. MemUse (bytes): 2,384,840 bytes
- Total Incl. PeakMemUse (bytes): 1,827,112 bytes
- Number of Function Calls: 5,327
With using setPageSize(1, 1)
- Total Incl. Wall Time (microsec): 155,025 microsecs
- Total Incl. CPU (microsecs): 136,191 microsecs
- Total Incl. MemUse (bytes): 2,413,128 bytes
- Total Incl. PeakMemUse (bytes): 1,856,064 bytes
- Number of Function Calls: 5,515
Note:
This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem()
instead.
GetFirstItem
getFirstItem() does not limit the result of collection load to one item.
incorrect:
$collection = Mage::getModel('catalog/category')
->load(41)
->getProductCollection()
->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight = $product->getData('weight');
correct:
Apply limit before grab data.
$collection->getSelect()->limit(1)
or
$collection->setPageSize(1, 1)
Expamples:
Collection with 750 products ...
Without limiting before:
- Total Incl. Wall Time (microsec): 2,116,522 microsecs
- Total Incl. CPU (microsecs): 2,101,688 microsecs
- Total Incl. MemUse (bytes): 4,783,504 bytes
- Total Incl. PeakMemUse (bytes): 4,363,112 bytes
- Number of Function Calls: 104,187
With using getSelect()->limit(1)
:
- Total Incl. Wall Time (microsec): 149,803 microsecs
- Total Incl. CPU (microsecs): 131,405 microsecs
- Total Incl. MemUse (bytes): 2,384,840 bytes
- Total Incl. PeakMemUse (bytes): 1,827,112 bytes
- Number of Function Calls: 5,327
With using setPageSize(1, 1)
- Total Incl. Wall Time (microsec): 155,025 microsecs
- Total Incl. CPU (microsecs): 136,191 microsecs
- Total Incl. MemUse (bytes): 2,413,128 bytes
- Total Incl. PeakMemUse (bytes): 1,856,064 bytes
- Number of Function Calls: 5,515
Note:
This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem()
instead.
edited Jun 16 '17 at 0:58
community wiki
3 revs
sv3n
I am gettingData access method LIMIT detected outside of Resource Model
when using limit`
– Amit Patel
Dec 12 '17 at 8:10
1
Here is more details
– Amit Patel
Dec 12 '17 at 10:35
add a comment |
I am gettingData access method LIMIT detected outside of Resource Model
when using limit`
– Amit Patel
Dec 12 '17 at 8:10
1
Here is more details
– Amit Patel
Dec 12 '17 at 10:35
I am getting
Data access method LIMIT detected outside of Resource Model
when using limit`– Amit Patel
Dec 12 '17 at 8:10
I am getting
Data access method LIMIT detected outside of Resource Model
when using limit`– Amit Patel
Dec 12 '17 at 8:10
1
1
Here is more details
– Amit Patel
Dec 12 '17 at 10:35
Here is more details
– Amit Patel
Dec 12 '17 at 10:35
add a comment |
Forbidden Function
curl_xyz
The use of function curl_init(), curl_setopt(), curl_exec(), curl_close() is forbidden
incorrect:
$ch = curl_init();
curl_setopt($connection, CURLOPT_HTTPHEADER, $header);
curl_setopt($connection, CURLOPT_POSTFIELDS, $request);
curl_setopt($connection, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
correct:
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_POSTFIELDS => $request
);
$curl = new Varien_Http_Adapter_Curl();
$curl->setOptions($options);
$curl->write(Zend_Http_Client::GET, $url, Zend_Http_Client::HTTP_0);
$response = $curl->read();
$curl->close();
I used above code and it is giving me errorUncaught Error: Class 'CustomRmaHelperVarien_Http_Adapter_Curl' not found
. How to use the class i found it in vendor but no luck.
– Nitin Pawar
Mar 5 '18 at 8:59
@NitinPawar can you please open a new question? Something seems to be wrong with your code.
– sv3n
Mar 5 '18 at 9:01
add a comment |
Forbidden Function
curl_xyz
The use of function curl_init(), curl_setopt(), curl_exec(), curl_close() is forbidden
incorrect:
$ch = curl_init();
curl_setopt($connection, CURLOPT_HTTPHEADER, $header);
curl_setopt($connection, CURLOPT_POSTFIELDS, $request);
curl_setopt($connection, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
correct:
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_POSTFIELDS => $request
);
$curl = new Varien_Http_Adapter_Curl();
$curl->setOptions($options);
$curl->write(Zend_Http_Client::GET, $url, Zend_Http_Client::HTTP_0);
$response = $curl->read();
$curl->close();
I used above code and it is giving me errorUncaught Error: Class 'CustomRmaHelperVarien_Http_Adapter_Curl' not found
. How to use the class i found it in vendor but no luck.
– Nitin Pawar
Mar 5 '18 at 8:59
@NitinPawar can you please open a new question? Something seems to be wrong with your code.
– sv3n
Mar 5 '18 at 9:01
add a comment |
Forbidden Function
curl_xyz
The use of function curl_init(), curl_setopt(), curl_exec(), curl_close() is forbidden
incorrect:
$ch = curl_init();
curl_setopt($connection, CURLOPT_HTTPHEADER, $header);
curl_setopt($connection, CURLOPT_POSTFIELDS, $request);
curl_setopt($connection, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
correct:
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_POSTFIELDS => $request
);
$curl = new Varien_Http_Adapter_Curl();
$curl->setOptions($options);
$curl->write(Zend_Http_Client::GET, $url, Zend_Http_Client::HTTP_0);
$response = $curl->read();
$curl->close();
Forbidden Function
curl_xyz
The use of function curl_init(), curl_setopt(), curl_exec(), curl_close() is forbidden
incorrect:
$ch = curl_init();
curl_setopt($connection, CURLOPT_HTTPHEADER, $header);
curl_setopt($connection, CURLOPT_POSTFIELDS, $request);
curl_setopt($connection, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
correct:
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_POSTFIELDS => $request
);
$curl = new Varien_Http_Adapter_Curl();
$curl->setOptions($options);
$curl->write(Zend_Http_Client::GET, $url, Zend_Http_Client::HTTP_0);
$response = $curl->read();
$curl->close();
edited 24 mins ago
community wiki
5 revs, 2 users 98%
sv3n
I used above code and it is giving me errorUncaught Error: Class 'CustomRmaHelperVarien_Http_Adapter_Curl' not found
. How to use the class i found it in vendor but no luck.
– Nitin Pawar
Mar 5 '18 at 8:59
@NitinPawar can you please open a new question? Something seems to be wrong with your code.
– sv3n
Mar 5 '18 at 9:01
add a comment |
I used above code and it is giving me errorUncaught Error: Class 'CustomRmaHelperVarien_Http_Adapter_Curl' not found
. How to use the class i found it in vendor but no luck.
– Nitin Pawar
Mar 5 '18 at 8:59
@NitinPawar can you please open a new question? Something seems to be wrong with your code.
– sv3n
Mar 5 '18 at 9:01
I used above code and it is giving me error
Uncaught Error: Class 'CustomRmaHelperVarien_Http_Adapter_Curl' not found
. How to use the class i found it in vendor but no luck.– Nitin Pawar
Mar 5 '18 at 8:59
I used above code and it is giving me error
Uncaught Error: Class 'CustomRmaHelperVarien_Http_Adapter_Curl' not found
. How to use the class i found it in vendor but no luck.– Nitin Pawar
Mar 5 '18 at 8:59
@NitinPawar can you please open a new question? Something seems to be wrong with your code.
– sv3n
Mar 5 '18 at 9:01
@NitinPawar can you please open a new question? Something seems to be wrong with your code.
– sv3n
Mar 5 '18 at 9:01
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f178640%2fecg-compliance-how-to-do%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
LOL about this post, you wrote almost a doc :)
– PЯINCƏ
Jul 22 '17 at 22:49
@Prince someone else could help a bit to complete this :P
– sv3n
Jul 22 '17 at 22:59
I don't think so :)
– PЯINCƏ
Jul 22 '17 at 23:04
any alternative for stripcslashes()? @sv3n thanks for such description question and answers :)
– Keyur Shah
Jan 30 '18 at 14:05
@KeyurShah No. Either ignore warning or try to avoid "before" :) In wich case you use it? Maybe add this as question?
– sv3n
Jan 30 '18 at 21:26