Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [coding-standards]

The tag has no usage guidance.

0
votes
1answer
20 views

Magento 2 : What is Use of @codingStandardsIgnoreFile, @codeCoverageIgnore, @codingStandardsIgnoreStart and @codingStandardsIgnoreEnd

In Any Custom[Module/Extension] development What is use of @codingStandardsIgnoreFile @codeCoverageIgnore @codingStandardsIgnoreStart @codingStandardsIgnoreEnd It is Valid in Magento Marketplace ...
0
votes
1answer
20 views

Magento 2 : Only dependency assignment operations are allowed in constructor. No other operations are allowed

Magento 2 Coding standard provide me Warning My Code is here namespace Namespace\Modulename\Model; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Ui\DataProvider\...
0
votes
2answers
21 views

Magento 2 : Use of echo language construct is discouraged

i had develop magento 2 extension and i have use ajax call to my controller for getting some data. but coding standard provide me some error my controller code is ...... public function execute() {...
0
votes
1answer
37 views

Magento 2 : Function's nesting level (8) exceeds 5 consider refactoring the function

I have check Coding standard of Module and i have get this is my code public function execute() { $mediaDirectory = $this->filesystem->getDirectoryRead($this->directoryList::MEDIA); ...
2
votes
1answer
36 views

Magento 2 : Coding standerd Provide me Some Warnings How to solve it?

I have checking my Module`s Code using --standard=MEQP2 that provide me some warnings How can i use the core function of php in Magento 2.3.1
2
votes
1answer
49 views

Magento 2 : How to set $_FILES = $file in Magento 2.3.0 with Magento Coding Standard?

I had develop one module and it works currectly But When I have check Coding standard using phpcs it will provide me Error in php coding standard --standard=MEQP2 Error is i have get result of $...
1
vote
0answers
23 views

The use of function html_entity_decode is forbidden. What should we use instead?

Ecg coding standards forbids using html_entity_decode method. What should we use instead?
2
votes
1answer
74 views

Magento227 Maketplace Coding Standard Issue

When I run: phpcs /path/to/module --standard=MEQP2 It gives me the following error PHP Fatal error: Trait 'MEQP\Utils\Helper' not found in /opt/marketplace-eqp/MEQP2/Sniffs/Classes/...
20
votes
2answers
502 views

Magento 2 - good practice to use/avoid magic getters?

Magic getters on Varien_Object (M1) and DataObject (M2) are common practice, but with Magento 2 it feels wrong to use it. Good: easy to read/write Bad It causes problems when using digits in keys (...
1
vote
0answers
34 views

Outdated codesniffer in MEQP2 composer.json for Magento 2.2?

How to correctly test against MEQP2 standard? Normally i use vendor/bin/phpcs --standard=PSR2 To supress errors a i use this: //phpcs:ignore or //phpcs:disable PSR2 When using MEQP2 standards ...
0
votes
0answers
68 views

Magento 2 : Installing magento 2 code standards with code sniffer in ubuntu

Can anybody please tell me how do i install Magento 2 code standards in Ubuntu form scratch? I am trying to install Composer and Code sniffer 3.0 but getting alot of errors.
0
votes
0answers
82 views

Magento 2 : Error - Only dependency assignment operations are allowed in constructor. No other operations are allowed

WARNING | Only dependency assignment operations are allowed in | | constructor. No other operations are allowed. I am getting this type of error while checking magento coding standard. ...
1
vote
1answer
186 views

MEQP Gives a Warning : Data load getFirstItem() method detected in loop

I want to get the First item from the collection so I have used following code. But it gives some warning on the usage of getFirstItem() protected $_sampleFactory; public function __construct( \...
1
vote
1answer
281 views

How to solve direct object instantiation warning

I used following code ->order(new \Zend_Db_Expr('FIELD(option_id,' . implode(',', $totalPro).')')); That give following warning. Direct object instantiation (object of \Zend_Db_Expr) is ...
1
vote
1answer
50 views

Alternatives or additional tools for Magento 1 EQP Coding Standard?

As I was working on a new "awesome" M1 extension (after I've read How to write a custom extension and others best practice like this or this), I decided to check if I was respecting the coding ...
1
vote
3answers
432 views

Magento 2 : Are php code sniffers the right tool for extension development?

I am creating a custom extension for Magento 2 and looking for the tool that can help me in the code standards. I come to know about PHP code sniffers from google. Is the PHP code sniffer is right ...
1
vote
0answers
108 views

Possible useless methods overriding magento2

This is a grid collection file. In this i didn't get any grid issues. According to CodingStandard it shows this warning: ---------------------------------------------------------------------- 32 | ...
0
votes
2answers
459 views

Magento 2: MassAction Model LSD method delete()

My massaction functionalities are working fine. According to CodingStandard it shows this warning. ---------------------------------------------------------------------- 38 | WARNING | Model LSD ...
0
votes
1answer
222 views

Modification of Magento 2 database core table

I am getting this error in UpgradeSchema. I have added one column in these core tables, functionalities are working good. According to coding standard it shows warning message. ----------------------...
4
votes
2answers
499 views

Warning : Session object MUST NOT be requested in constructor [duplicate]

75 | WARNING | Session object MUST NOT be requested in constructor. | | It can only be passed as a method argument. 79 | WARNING | Session object MUST NOT be requested in constructor....
1
vote
2answers
168 views

Magento2 coding standard public interface

According to coding standard protected function should not be used, so i have changed from protected to public then, I am getting this warning from coding standard, Warning: The use of public non-...
0
votes
2answers
58 views

Magento 2 : How to write a custom extension? [closed]

There is already a question on how to write a custom extension at How to write a custom extension? , but most of the answers I read , while being good and really detailed are about magento 1, so felt ...
1
vote
2answers
272 views

How to use session in dependency injection with parent construct?

Below error is showing when I tried to run with MEQP2 sniff. Code: class History extends \Magento\Sales\Block\Order\History { /** * @param \Magento\Framework\View\Element\Template\Context $...
1
vote
1answer
325 views

Magento 2 Short array syntax is not allowed while Module testing.

Magento 2 module testing tools gives error "short array syntax not allowed", we do code like following public function toOptionArray() { return [ ['value' => 0, 'label' =&...
1
vote
1answer
416 views

The use of function pathinfo() is discouraged Magento 2

I am checking uploaded file extension by pathinfo() function of php but in coding standard check it's shows The use of function pathinfo() is discouraged My code: $fileExt = pathinfo($file, ...
0
votes
1answer
357 views

Spaces must be used to indent lines; tabs are not allowed Magento 2

I am checking coding standards of my module. I face this warning in technical report Spaces must be used to indent lines; tabs are not allowed public function __construct( \Magento\Backend\App\...
1
vote
4answers
2k views

check file uploaded or not without $_FILES in Magento 2

I'm checking condition like file uploaded or not, for that I used $_FILES but as magento 2 coding standards we cannot use $_FILES. if ($id) { $model->load($id); } //if (isset($_FILES['file']) ...
1
vote
5answers
1k views

Mage::getStoreConfig in PHTML

We're on Magento 1.9.3.4 and we want to display the phone number in the header. Is it ok to just put into header.phtml <?php echo Mage::getStoreConfig('general/store_information/phone') ?> ...
0
votes
1answer
58 views

How to access $_FILES in magentos way?

For ECG you should avoid using "superglobals", but is there any Magento, Zend or Varien method to replace $_FILES? Couldn't find anything in Mage_Core_Controller_Request_Http or ...
1
vote
1answer
567 views

Magento 2: Only dependency assignment operations are allowed in constructor. Coding standard error

"WARNING | Only dependency assignment operations are allowed in constructor. No other operations are allowed". I'm getting this warning error while checking the coding standard in Magento2 code ...
3
votes
1answer
63 views

what does @api in doctype promise

I'm working on fixing a core bug so that I can do a pull request... for this I'm adding new exception type... <?php /** * AfterCommitException Exception * * Copyright © Magento, Inc. All rights ...
2
votes
1answer
209 views

Why does my module getting warrning “Mysql4 classes are obsolete ”

Hello i have create custom module and getting warning Mysql4 classes are obsolete class Mymodule_Custom_Model_Mysql4_Stores extends Mage_Core_Model_Mysql4_Abstract { public function ...
10
votes
3answers
1k views

ECG compliance: How to do?

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 ...
13
votes
4answers
2k views

What are all the tools available for checking Magento 2 coding standard?

I am currently working on Magento 2 coding standard checking project. Any other tool available other than PHP_CodeSniffer to check Magento 2 and PHP coding standing.
1
vote
2answers
225 views

ECG compliant alternative method for file_get_contents (remote XML)

What is correct "ECG-way" to load an remote XML file? For local files this works: $xml = new Varien_Simplexml_Config($configFile); $node = $xml->getNode('my/selected/node'); But not from remote ...
5
votes
1answer
655 views

Magento2 PHP CodeSniffer - “Use of protected class members is discouraged”

My question is - why the usage of protected members in class in Magento 2 is discouraged? I looked into other questions that ask about warnings of the PHP CodeSniffer for Magento 2, but nobody ...
2
votes
0answers
76 views

How to go around “Incorrect namespace usage(s)” in static tests

I have a simple CRUD module for Magento 2. When I run the static tests I get the following error/warning. "Incorrect namespace usage(s) found in file..... <Vendor>_<Module>". The ...
0
votes
1answer
288 views

Correct way to join core tables in magento 2

I am able to join table something like this.. $totalsales = $this->orderCollectionFactory->create() ->addFieldToSelect('*') ->...
8
votes
2answers
2k views

Magento 2 codingStandardsIgnoreFile

In phtml file these comment used // @codingStandardsIgnoreFile e.g vendor/magento/module-sales/view/frontend/templates/email/items.phtml line 7 Anyone know why it is used and can i use that too in ...
9
votes
1answer
512 views

What are the static tests checking?

After building my module I tried running bin/magento dev:tests:run static. This reported a few problems with my code, but I'm not sure exactly what is checked when running this tests. The official ...
0
votes
1answer
77 views

Coding standard clarification in Magento2

I have installed PHP_Codesniffer extension to find out the Magento 2 coding standard issues. I have run the below command. phpcs --standard=Ecg --extensions=php,xml,phtml --report-full=/path/testing....
0
votes
2answers
1k views

How to add one file with classes third party library in to Magento 2?

I have a single PHP file with some classes as a library. For example: <?php class addShipment { public $packages; // przesylkaType public $id; // int } class addShipmentResponse { ...
0
votes
1answer
60 views

Can i replace die() with Mage::throwException()

I have to replace this code die('Could not open socket'); because of coding standard can i replace with it Mage::throwException() Mage::throwException('Could not open socket');
1
vote
1answer
304 views

MEQP1 possible error list for Magento1

Can anyone give me solution for these warnings. Model LSD method load() detected in loop $item = Mage::getModel('catalog/product')->load($item->getProductId()); Data load getFirstItem() ...
4
votes
1answer
359 views

What is replacement of include_once and require_once MEQP1 standard

Got these WARNINGS how can I resolve it ? "include_once" statement detected. File manipulations are discouraged. Concatenating is forbidden. "require_once" statement detected. File ...
2
votes
1answer
290 views

MEQP1 standard INSERT detected outside of Resource Model

Below line causing warning in codesniffer in MEQP1 standard $data = $installer->getConnection()->insert($eavTypeTable, array('entity_type_code'=>'test')); This line causing the Warning ...
1
vote
1answer
33 views

Magento 2 : What's the proper location to put repositories?

In Magento 2.1: When I look at the customer module, I note that the customer repository is located in the folder for resource models: Magento\Customer\Model\ResourceModel\CustomerRepository But ...
11
votes
4answers
3k views

Filesystem best practices

I'm working on some Magento 2 extension that requires reading files from the file system. When running the php sniffer using the ECGM2 standards, it complains about the fact that I'm using functions ...
3
votes
1answer
262 views

Does Magento 2 follow the PSR2 or Zend standard?

I am testing my extension code against the PSR2 and Zend standards. However, the two standards conflict. I found a problem which I fixed for Zend, which then showed as an error in PSR2. If I fix it ...
1
vote
1answer
448 views

$_FILES in Magento2 ECG : system configuration

How can I use $_FILES (Super global variable )in Magento2 system configuration as per ECG coding standard. I know I can use in simple form like below. where my_file_uploader is name of fieldId $...