{"id":650,"date":"2017-06-10T18:26:07","date_gmt":"2017-06-10T17:26:07","guid":{"rendered":"https:\/\/www.muratyaman.co.uk\/wp\/?p=650"},"modified":"2020-04-04T12:27:04","modified_gmt":"2020-04-04T11:27:04","slug":"how-not-to-write-oop-php-code","status":"publish","type":"post","link":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/2017\/06\/how-not-to-write-oop-php-code\/","title":{"rendered":"How NOT to write (OOP PHP) code"},"content":{"rendered":"<p>My comment on one of the files of SuiteCRM:<\/p>\n<p><a href=\"https:\/\/github.com\/salesagility\/SuiteCRM\/issues\/3561\">https:\/\/github.com\/salesagility\/SuiteCRM\/issues\/3561<\/a><\/p>\n<p>which was closed and kindly &#8220;put&#8221; aside (IGNORED basically!):<\/p>\n<p><a href=\"https:\/\/trello.com\/b\/Ht7LbMqw\/suitecrm-suggestion-box\">https:\/\/trello.com\/b\/Ht7LbMqw\/suitecrm-suggestion-box<\/a><\/p>\n<p>So&#8230;<\/p>\n<p><strong>Expected Behaviour<\/strong><\/p>\n<p>It has to extend\/implement only SugarBean and some relevant functions.<br \/>\nMany functions must be implemented by separate classes<br \/>\nesp. email management functions related to POP3 and IMAP<br \/>\nso that we can maintain and extend the features easily.<br \/>\ne.g. replace IMAP layer with a HTTP API<br \/>\nWe must aim for smaller functions and classes:<\/p>\n<p><a href=\"http:\/\/swreflections.blogspot.co.uk\/2012\/12\/rule-of-30-when-is-method-class-or.html\">http:\/\/swreflections.blogspot.co.uk\/2012\/12\/rule-of-30-when-is-method-class-or.html<\/a><\/p>\n<p><strong>Actual Behaviour<\/strong><\/p>\n<p><a href=\"https:\/\/github.com\/salesagility\/SuiteCRM\/blob\/master\/modules\/InboundEmail\/InboundEmail.php\">https:\/\/github.com\/salesagility\/SuiteCRM\/blob\/master\/modules\/InboundEmail\/InboundEmail.php<\/a><\/p>\n<p>Includes\/implements so much code.<br \/>\nhere is a short list of almost 170 functions<\/p>\n<p>&#8211; InboundEmail::getFormattedRawSource()<br \/>\n&#8211; InboundEmail::convertToUtf8()<br \/>\n&#8211; InboundEmail::getFormattedHeaders()<br \/>\n&#8211; InboundEmail::emptyTrash()<br \/>\n&#8211; InboundEmail::importMessages()<br \/>\n&#8211; InboundEmail::checkEmail()<br \/>\n&#8211; InboundEmail::fetchCheckedEmails()<br \/>\n&#8211; InboundEmail::search()<br \/>\n&#8211; InboundEmail::retrieve*()<br \/>\n&#8211; InboundEmail::save*()<br \/>\n&#8211; InboundEmail::*IMAP*() many IMAP functions<br \/>\n&#8211; InboundEmail::*Pop3*() many POP3 functions<br \/>\n&#8211; InboundEmail::*Cache*() many Cache functions<br \/>\n&#8211; InboundEmail::*Mailserver() connect\/disconnect etc.<br \/>\n&#8211; InboundEmail::*Folder() rename, delete etc.<\/p>\n<p>etc. etc. !!! You get the idea \ud83d\ude41<\/p>\n<p>Also, it is polluted with a function and two classes:<\/p>\n<p>&#8211; function this_callback<br \/>\n&#8211; class temp<br \/>\n&#8211; class Overview<\/p>\n<p><strong>Possible Fix<\/strong><\/p>\n<p>Many functions must be implemented by separate classes<br \/>\ne.g. ImapManager, Pop3Manager, EmailParser, CacheManager, FileSystemObject, etc.<\/p>\n<p><strong>My Environment<\/strong><\/p>\n<p>* SuiteCRM Version used: 7.8.3<br \/>\n* Browser name and version (e.g. Chrome Version 58 (64-bit)):<br \/>\n* Environment name and version (e.g. MySQL 5.7, PHP 7.0):<br \/>\n* Operating System and version (e.g Ubuntu 16.04)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My comment on one of the files of SuiteCRM &#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[65,26],"class_list":["post-650","post","type-post","status-publish","format-standard","hentry","category-technology","tag-oop","tag-php"],"_links":{"self":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=650"}],"version-history":[{"count":4,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/650\/revisions"}],"predecessor-version":[{"id":878,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/650\/revisions\/878"}],"wp:attachment":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}