ECG compliance: How to do? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)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

Student Loan from years ago pops up and is taking my salary

How to determine omitted units in a publication

One-dimensional Japanese puzzle

Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?

60's-70's movie: home appliances revolting against the owners

Sub-subscripts in strings cause different spacings than subscripts

For what reasons would an animal species NOT cross a *horizontal* land bridge?

Homework question about an engine pulling a train

Identify 80s or 90s comics with ripped creatures (not dwarves)

How to handle characters who are more educated than the author?

Why doesn't shell automatically fix "useless use of cat"?

Keeping a retro style to sci-fi spaceships?

How to support a colleague who finds meetings extremely tiring?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

The following signatures were invalid: EXPKEYSIG 1397BC53640DB551

Circular reasoning in L'Hopital's rule

Do warforged have souls?

Working through the single responsibility principle (SRP) in Python when calls are expensive

What information about me do stores get via my credit card?

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

Can the Right Ascension and Argument of Perigee of a spacecraft's orbit keep varying by themselves with time?

What can I do if neighbor is blocking my solar panels intentionally?

What do I do when my TA workload is more than expected?

How many cones with angle theta can I pack into the unit sphere?



ECG compliance: How to do?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)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;








10















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









share|improve this question
























  • 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


















10















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









share|improve this question
























  • 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














10












10








10


2






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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 25 '17 at 1:39







sv3n

















asked Jun 12 '17 at 17:01









sv3nsv3n

9,95162457




9,95162457












  • 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











  • @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











3 Answers
3






active

oldest

votes


















6














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))
...






share|improve this answer
































    5














    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.






    share|improve this answer

























    • I am getting Data 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


















    5














    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();
    $responseBody = Zend_Http_Response::extractBody($response);
    $curl->close();





    share|improve this answer

























    • 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











    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
    );



    );













    draft saved

    draft discarded


















    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









    6














    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))
    ...






    share|improve this answer





























      6














      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))
      ...






      share|improve this answer



























        6












        6








        6







        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))
        ...






        share|improve this answer















        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))
        ...







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 16 '17 at 0:07


























        community wiki





        2 revs
        sv3n
























            5














            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.






            share|improve this answer

























            • I am getting Data 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















            5














            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.






            share|improve this answer

























            • I am getting Data 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













            5












            5








            5







            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.






            share|improve this answer















            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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 16 '17 at 0:58


























            community wiki





            3 revs
            sv3n













            • I am getting Data 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






            • 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











            5














            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();
            $responseBody = Zend_Http_Response::extractBody($response);
            $curl->close();





            share|improve this answer

























            • 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















            5














            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();
            $responseBody = Zend_Http_Response::extractBody($response);
            $curl->close();





            share|improve this answer

























            • 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













            5












            5








            5







            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();
            $responseBody = Zend_Http_Response::extractBody($response);
            $curl->close();





            share|improve this answer















            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();
            $responseBody = Zend_Http_Response::extractBody($response);
            $curl->close();






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 9 at 6:08


























            community wiki





            6 revs, 2 users 97%
            sv3n













            • 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

















            • 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
















            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

















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Bulk add to cart function issuecart vs. mini cart issue … rwd themeRedirect Add to cart button to cart pageAdd to cart issue - Magento 2.1The requested Payment Method is not available When creating an orderM2: reason add-to-cart might not function in production modeAdd to cart issue in some android devicesMagento 2 - custom price can not add to subtotal and grand total after add to cartAdd to cart codeIssue with my cart module on pdp and cart pages, just keeps spinningBulk price and quantity update using rest api

            Magento2 - How to hide price filter only in specific categories?Multiselect price filter attribute in layered navigationhide only some categories from layered navigation in magentoRemove Price Filter on certain categoriescustomize layered price filter?Hide Price for a particular customer groupPrice filter in layered navigation not working correctly with price including tax in magento 2.2.3Magento 2 how to hide attribute at Layered navigation?Magento 2. how to hide price only for specific categoriesMagento 2 How can I hide the price and total from cart and checkout summary?Magento2: Can we add navigation layered filter like price filter for other attribute?