Questions tagged [coding-standards]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
29 views

What can we use for exist query in magento2?

We have two approaches to find if the record exists in database or not First $select = $this->bookResource->getConnection()->select() ->distinct() ->from( $this->bookResource-&...
0
votes
1answer
22 views

Can any conditional operators be used with an element while defining a multidimensional array?

While building a multi-dimensional array as shown below, I need to use a loop to retrieve some value from $this_fulfillment_record to be assigned to "amount" =>. Can a if statement be ...
1
vote
1answer
28 views

Load resource models without using deprecated getResource

I'm using Magento\Newsletter\Model\ResourceModel\Subscriber::loadByCustomerData Code is like this /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */ [...] $subscriber = $this->...
1
vote
1answer
86 views

Use base64_decode and base64_encode as per Magento ECG

I am using the base64_decode() and base64_encode() in my code but PHPCS says The use of function base64_decode() is discouraged so what's the equivalence of this core PHP function in Magento2?
0
votes
1answer
22 views

Magento 2 code sniffer showing session_id() warning

After running the code sniffer on Magento 2 extension got several warnings and that includes one warning saying "The use of function session_id() is discouraged". So what is the alternative ...
0
votes
1answer
53 views

How to test module in different Magento and PHP versions using CI?

I have an open-source module in Github and I'd like to automatically test it via CI using the Magento Coding Standard and different Magento installations in different PHP versions. For example: ...
1
vote
1answer
104 views

Magento 2 Overide public static method of framwork class

I want to override public static function getCorrectFileName method of Magento\Framework\File\Uploader, I have check with Preference and Plugin but it is not working for me. Anyone have idea about ...
0
votes
0answers
16 views

Best way to decrease the class complexity?

i am developing magneto 2 extension in which my classes code exceeds the standard class limit also there are some common methods that need to be placed in on location. So what will be the best ...
1
vote
2answers
158 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
74 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 ...
1
vote
1answer
400 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
32 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
61 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
2answers
1k 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/...
1
vote
1answer
70 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 Solution. ...
0
votes
1answer
132 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 ...
1
vote
3answers
787 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
2k 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
302 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
243 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
49 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
352 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
477 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
243 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
85 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
174 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
348 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
1k 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
95 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
104 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
291 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
371 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
68 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
1k 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 ...
3
votes
0answers
319 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
817 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
477 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
701 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
236 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
91 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
480 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
547 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
3answers
1k 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
918 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
4k 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
65 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
702 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
86 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
253 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 ...