Questions tagged [coding-standards]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
2answers
32 views

Magento 2.3 example of where proxy is used but not explicitly requested in constructors

I'm trying to find an example in M2 repo where a proxy is used but not explicitly requested in a constructor. Can anyone point me in the right direction? This is in response to phpcs Magento2 ...
0
votes
1answer
15 views

CQRS module example magento2

Can anyone point to some decent github repository where module implements CQRS, SOLID, DRY and testing? I was reading about MSI, but it is kind of complex and huge and I am looking for something ...
0
votes
1answer
70 views

Magento 2 phpcs coding standard rules cheatsheet

Has anyone got a cheat sheet style list of the common Magento 2 code quality exclusions? // phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis // phpcs:disable Magento2.Files.LineLength....
0
votes
1answer
25 views

Magento 2.3 usage of object manager in abstract code - good / bad / indifferent

I know what object manager is. I know why it is used. I know that as a general rule it shouldn't be used. I know why from reading this. https://devdocs.magento.com/guides/v2.3/extension-dev-guide/...
1
vote
1answer
41 views

Magento 2 : coding standards correct way to throw exceptions

When using coding standard checks my attention is often drawn to the use of exceptions. Generally when I'm putting something together I use standard exceptions and later code something more specific. ...
0
votes
1answer
311 views

Magento 2: While running “vendor/bin/phpcbf” Uncaught Error: Class 'PHP_CodeSniffer\Runner' not found

I have faced issue in "vendor/bin/phpcbf" command for resolving custom extension coding standard. I am using Magento ver.2.3.1 Running command in project root: vendor/bin/phpcbf "app/code/...
0
votes
0answers
35 views

PHP Storm XML scan result : redundant default attribute value assignment

I ran a PHP Storm XML scan https://magento.stackexchange.com/a/227343/70343 The part you are interested in is 'How to use PhpStorm code inspector to validate project xml-files' And I just ...
1
vote
1answer
47 views

What is different between magento-coding-standard and marketplace-eqp?

In Magento Marketplace Technical Review It will Check The Coding standard of the Extension So I Need To Check in My Local Machine But I have Found 3 Solution and I am confused what is better ...
0
votes
1answer
46 views

Faster way to doc code

Take this random class https://github.com/magento/magento2/blob/2.3/app/code/Magento/Checkout/Helper/Cart.php Got a mixture of code comments for class, variables, constants, methods etc all nice and ...
0
votes
1answer
263 views

$this deprecated in template logic. What's the alternative?

In this https://github.com/magento/magento2/blob/2.3/app/code/Magento/Contact/view/frontend/templates/form.phtml you see something like this $this->helper('Magento\Contact\Helper\Data')->...
0
votes
2answers
441 views

Magento 2 PHPCS coding standards

I am creating a Magento 2.3 website from scratch. I am having phpcs.xml file on Magento root which contains the rules for PHPCS. These rules get triggered when the build is executed. I am confused ...
1
vote
3answers
108 views

Where to use object manager in Magento 2

I have doubt on object manager someone saying You should not use the ObjectManager directly! but I have questioned if I want to get customer session in my phtml how can I get?. that time can I use ...
0
votes
1answer
96 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
41 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
100 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
196 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
102 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
3
votes
1answer
66 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 $...
2
votes
0answers
107 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?
3
votes
1answer
261 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/...
21
votes
2answers
836 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
81 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
99 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
241 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
341 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
63 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
752 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 ...
2
votes
0answers
217 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 | ...
1
vote
3answers
683 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
366 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. ----------------------...
3
votes
2answers
628 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
207 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
68 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
385 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
457 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' =&...
2
votes
2answers
802 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
521 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\...
2
votes
4answers
3k 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']) ...
2
votes
5answers
2k 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
61 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
2answers
667 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
74 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
237 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 ...
14
votes
4answers
4k views

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

I am currently working on Magento 2 coding standard checking project. Is any other tool available, other than PHP_CodeSniffer, to check Magento 2 and PHP coding standing?
1
vote
2answers
259 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
750 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
84 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
313 views

Correct way to join core tables in magento 2

I am able to join table something like this.. $totalsales = $this->orderCollectionFactory->create() ->addFieldToSelect('*') ->...
7
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 ...