Questions tagged [coding-standards]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
39 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
14 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 ...
2
votes
1answer
36 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
31 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
48 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
68 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
57 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
30 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
34 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
41 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
52 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
41 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
57 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
46 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
132 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/...
19
votes
2answers
550 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
51 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
91 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
94 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
209 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
314 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
53 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
505 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
125 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
533 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
244 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
543 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
179 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
62 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
303 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
360 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
495 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
370 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']) ...
2
votes
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
59 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
599 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
66 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
220 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
3k 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
230 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
687 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
79 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
295 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 ...
8
votes
1answer
543 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
83 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
61 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');