Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
28

Got an unofficial answer from the ECG team on that: First of all, the flagged functions are not necessarily disallowed - they should trigger a manual review on usage to ensure legitimate use. It's a review helper tool, not good/bad code scoring tool. Second, the assumption was it is better to use Magento wrappers (functions/classes) if they exists as they ...


11

The Coding Standard has two goals. make finding of possibly problematic parts a lot easier. An experienced developer already knows which parts of a new module he needs to review, and this standard marks and lists them for him. It is not so he can remove this parts, but to review if they are necessary, problematic or both. support inexperienced developers on ...


9

Ok! I got solution for one or two global variable. I will update question if i found more. For $_SERVER public function __construct(\Magento\Framework\App\RequestInterface $httpRequest,\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Psr\Log\LoggerInterface $logger, \Magento\Store\Model\StoreManagerInterface $storeManager) { $...


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


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


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


4

This warning comes if you do anything else besides $this->someDependency = $dependency; in your constructor. Why? Because Magento instantiates objects as soon as they are requested in a constructor, even if they are never actually used. So it is good practice to have fast instantiation. Any additional logic should happen on demand. How? Let's say ...


4

Try Zend_Validate_File_Exists See /lib/Zend/Validate/File/NotExists.php /lib/Zend/Validate/File/Exists.php $validator = new Zend_Validate_File_Exists(); $validator->addDirectory('users/'); if($validator->isValid('testimage.jpg')){ echo "true"; } else { echo "false"; }


2

I've come to the understanding that my original question actually deals with quite a few of subquestions: Each time the ECG group complains about a certain PHP function that should be used, it is kind of a hassle to find out which wrapper class should be used instead: In this thread, Varien_Io_File and Zend_Validate_File_Exists were already mentioned, and ...


2

Mysql4 models still work, but with 1.7 Resocure models were introduced ... so you'll get a notification, when running codesniffer ... Guess you'll find complete answer here: How to handle deprecated "Mysql4" classes when rewriting resource models Magento 1.9 module oddly breaking when changing resource folder from Mysql4 to Resource


1

One way you can used Object Manager and Media Storage Uploader of magento to get $_FILES data.I know using object manager is not a good idea. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $fileSystem = $objectManager>create('\Magento\Framework\Filesystem'); $mediaPath=$fileSystem->getDirectoryRead(\Magento\Framework\App\...


1

In addition to Renon Stewart answer you can also use ... Varien_Io_File $io = new Varien_Io_File(); if (!$io->fileExists($filePath)) { ... } there is also an !file_exists mehtod: $validatorNot = new Zend_Validate_File_NotExists($path); if ($validatorNot->isValid($file)) { ... }


Only top voted, non community-wiki answers of a minimum length are eligible