Questions tagged [coding-standards]
The coding-standards tag has no summary.
89 questions
0
votes
2
answers
321
views
Magento 2 coding standards phpcs giving , ERROR: Referenced sniff "PHPCompatibility.FunctionUse.RemovedFunctions" does not exist
when I am running the command to check phpcs issues,
vendor/bin/phpcs --standard=Magento2 /filepath/
ERROR: Referenced sniff "PHPCompatibility.FunctionUse.RemovedFunctions" does not ...
2
votes
0
answers
1k
views
How ignore Deprecated Functionality: Optional parameter $data declared before required parameter
As we know Magento latest version 2.4.5 version is compatible with PHP-8.x. When running setup:di: compile, it throws an exception
Deprecated Functionality: Optional parameter $data declared before ...
2
votes
4
answers
1k
views
Magento 2 coding standards : phpcs --standard=PHPCompatibility github action to check extension code
Today I came across a really useful set of tools. Magento 2 github actions:
https://github.com/extdn/github-actions-m2
Which means you can run a github action workflows to scan your code for Magento ...
-4
votes
1
answer
70
views
How to Standard Coding base on Magento Architecture For Query optimization
How to Optimization magento1 & 2 default Products, Order, Customer, Wishlist etc.. collection query?
0
votes
1
answer
48
views
@return description in magento-coding-standard
I am currently working on bringing my extensions to the current coding standard.
So, when writing a function, normally I would describe it the following way:
protected function exampleFunction(string $...
1
vote
2
answers
1k
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
1
answer
441
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 ...
2
votes
1
answer
1k
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->...
2
votes
4
answers
4k
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
1
answer
108
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 ...
1
vote
1
answer
493
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:
...
2
votes
1
answer
2k
views
Magento 2 Override public static method of framework 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 ...
1
vote
2
answers
1k
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
1
answer
482
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 ...
2
votes
1
answer
3k
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....