cancel
Showing results for 
Search instead for 
Did you mean: 

Why is there so much poorly written magento core code?

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Why is there so much poorly written magento core code?

Please take a look at the following template for example:

 

vendor\magento\module-catalog\view\frontend\templates\product\list\items.phtml

 

If found code like this many times:

 

There are 3 calls to $block->escapeHtmlAttr($_item->getId()) !!! 

 

 

    <div class="field choice related">
        <input type="checkbox" class="checkbox related" id="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>" name="related_products[]" value="<?= $block->escapeHtmlAttr($_item->getId()) ?>" />
        <label class="label" for="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>"><span><?= $block->escapeHtml(__('Add to Cart')) ?></span></label>
    </div>

 

 

The same code could be written as:

 

<?php $itemId = $block->escapeHtmlAttr($_item->getId()); ?>

<div class="field choice related">
    <input type="checkbox" 
           class="checkbox related"
           id="related-checkbox<?= $itemId ?>"
           name="related_products[]" value="<?= $itemId ?>" />

    <label class="label" for="related-checkbox<?= $itemId ?>">
        <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
    </label>
</div>


and the template is full of such beginner mistakes which costs performance.

 

And there are extremly long lines with about >210 chars, even though you should always keep the max chars in a line to about 80.

 

e.g.

 

<div class="field choice related">
    <input type="checkbox" class="checkbox related" id="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>" name="related_products[]" value="<?= $block->escapeHtmlAttr($_item->getId()) ?>" />
    <label class="label" for="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>"><span><?= $block->escapeHtml(__('Add to Cart')) ?></span></label>
</div>

The whole code is written like this. Why are the magento core coding standards so low??

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Why is there so much poorly written magento core code?

Hi @Eddcapone 

 

I can not say why the code is like this.
But if you have suggestions for improvement, you can create a pull request with the code fix here https://github.com/magento/magento2/issues

---
Problem Solved Click Accept as Solution!:Magento Community India Forum

View solution in original post

2 REPLIES 2

Re: Why is there so much poorly written magento core code?

Hi @Eddcapone 

 

I can not say why the code is like this.
But if you have suggestions for improvement, you can create a pull request with the code fix here https://github.com/magento/magento2/issues

---
Problem Solved Click Accept as Solution!:Magento Community India Forum

Re: Why is there so much poorly written magento core code?

Hello, I found a bug and try to contribute a fix, but if I fork and clone the repo and then execute "composer update" then there are only a few folders in "vendor/magento"

The bug is in \vendor\magento\module-catalog\view\frontend\templates\product\compare\list.phtml

 

What am I supposed to do?

Update: I figured out that the files are in app/code