0

I created a extension submitted for approval On my local there is Varnish cashe enabled but sudo php bin/magento setup:di:compile runs without any error.

I got 6 errors in Technical Report

Environment: Operating System - Centos 7, PHP Version - 7.0.28, Magento Platform - 2.0.17 CE Varnish, Sampla Data

Command: setup:di:compile

Installation issue:  Proxies code generation... 1/7 [====>-----------------------] 14% 1 sec 42.0 MiB
                     -------- some more lines than
                     Interception cache generation... 6/7 [========================>---] 85% 36 secs 232.0 MiBErrors during compilation:
Companyname\Modulename\Block\HomehorizontalWidget
Incorrect dependency in class Companyname\Modulename\Block\HomehorizontalWidget in /var/www/html/vendor/Companyname/Modulename/Block/HomehorizontalWidget.php
\Magento\Framework\Filesystem already exists in context object
Companyname\Modulename\Helper\Data
Incorrect dependency in class Companyname\Modulename\Helper\Data in /var/www/html/vendor/Companyname/Modulename/Helper/Data.php
\Magento\Framework\App\Config\ScopeConfigInterface already exists in context object
Total Errors Count: 2
Errors during compilation:
Companyname\Modulename\Block\HomehorizontalWidget
Incorrect dependency in class Companyname\Modulename\Block\HomehorizontalWidget in /var/www/html/vendor/Companyname/Modulename/Block/HomehorizontalWidget.php
\Magento\Framework\Filesystem already exists in context object
Companyname\Modulename\Helper\Data
Incorrect dependency in class Companyname\Modulename\Helper\Data in /var/www/html/vendor/Companyname/Modulename/Helper/Data.php
\Magento\Framework\App\Config\ScopeConfigInterface already exists in context object
Total Errors Count: 2
Errors during compilation:
Companyname\Modulename\Block\HomehorizontalWidget
Incorrect dependency in class Companyname\Modulename\Block\HomehorizontalWidget in /var/www/html/vendor/Companyname/Modulename/Block/HomehorizontalWidget.php
\Magento\Framework\Filesystem already exists in context object
Companyname\Modulename\Helper\Data
Incorrect dependency in class Companyname\Modulename\Helper\Data in /var/www/html/vendor/Companyname/Modulename/Helper/Data.php
\Magento\Framework\App\Config\ScopeConfigInterface already exists in context object
Total Errors Count: 2

Interception cache generation... 7/7 [============================] 100% 40 secs 232.0 MiB
Generated code and dependency injection configuration successfully.     

file : /var/www/html/magento2/app/code/Companyname/Reviews/Block/HomehorizontalWidget.php

   <?php
    namespace Companyname\Reviews\Block;

    #File: app/code/Companyname/Reviews/Block/HomehorizontalWidget.php

    class HomehorizontalWidget extends \Magento\Framework\View\Element\Template
    {

        /**
         * @var \Magento\Framework\Registry
         * @var \Companyname\Reviews\Helper\Data
         * @var \Magento\Framework\Filesystem
         * @var  \Magento\Framework\Image\AdapterFactory
         *
         */

        protected $_helper;
        protected $jsonHelper;
        protected $_filesystem;
        protected $_imageFactory;
        protected $_registry;

        /**
         *
         * @param \Magento\Framework\View\Element\Template\Context $context
         * @param array                                            $data
         * @param \Magento\Framework\Registry                      $registry
         * @param \Companyname\Reviews\Helper\Data                      $helper
         * @param \Magento\Framework\Json\Helper\Data              $jsonHelper
         * @param \Magento\Framework\Filesystem                    $filesystem
         * @param \Magento\Framework\Image\AdapterFactory          $imageFactory
         */
        public function __construct(
            \Magento\Framework\View\Element\Template\Context $context,
            array $data = [],
            \Magento\Framework\Registry $registry,
            \Companyname\Reviews\Helper\Data $helper,
            \Magento\Framework\Json\Helper\Data $jsonHelper,
            \Magento\Framework\Filesystem $filesystem,
            \Magento\Framework\Image\AdapterFactory $imageFactory
        ) {
            parent::__construct($context, $data);

            $this->_helper       = $helper;
            $this->jsonHelper    = $jsonHelper;
            $this->_filesystem   = $filesystem;
            $this->_registry     = $registry;
            $this->_imageFactory = $imageFactory;
        }
..................

Update :After removing _filesystem i got below fatal error

<?php
namespace Companyname\Reviews\Block;

class HomehorizontalWidget extends \Magento\Framework\View\Element\Template
{
    protected $_helper;
    protected $jsonHelper;
    //protected $_filesystem;  removed
    protected $_imageFactory;
    protected $_registry;


    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        array $data = [],
        \Magento\Framework\Registry $registry,
        \Companyname\Reviews\Helper\Data $helper,
        \Magento\Framework\Json\Helper\Data $jsonHelper,
        // \Magento\Framework\Filesystem $filesystem, removed
        \Magento\Framework\Image\AdapterFactory $imageFactory
    ) {
        parent::__construct($context, $data);

        $this->_helper       = $helper;
        $this->jsonHelper    = $jsonHelper;
       // $this->_filesystem   = $filesystem; removed
        $this->_registry     = $registry;
        $this->_imageFactory = $imageFactory;
    }

Error:

Fatal error: Uncaught TypeError: Argument 6 passed to Companyname\Reviews\Block\HomehorizontalWidget::__construct() must be an instance of Magento\Framework\Image\AdapterFactory, instance of Magento\Framework\Filesystem given, called in /var/www/html/magento2/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 111 and defined in /var/www/html/magento2/app/code/Companyname/Reviews/Block/HomehorizontalWidget.php:29 Stack trace: #0 /var/www/html/magento2/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(111): Companyname\Reviews\Block\HomehorizontalWidget->__construct(Object(Magento\Framework\View\Element\Template\Context), Array, Object(Magento\Framework\Registry), Object(Companyname\Reviews\Helper\Data), Object(Magento\Framework\Json\Helper\Data), Object(Magento\Framework\Filesystem), Object(Magento\Framework\Image\AdapterFactory)) #1 /var/www/html/magento2/vendor/magento/framework/ObjectManager/Factory/Compiled.php(108): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Companyname\\Rev in /var/www/html/magento2/app/code/Companyname/Reviews/Block/HomehorizontalWidget.php on line 29
6
  • It seems like you are injecting stuff that is already included in context. Mar 21, 2018 at 8:10
  • can i share the constructor HomehorizontalWidget.php
    – inrsaurabh
    Mar 21, 2018 at 8:12
  • Have a look at the error. It tells you all the classes that are already in the context object. Mar 21, 2018 at 8:14
  • i shared on of the file , can you plz see
    – inrsaurabh
    Mar 21, 2018 at 8:18
  • Do i need to remove those lines \Magento\Framework\Filesystem ?
    – inrsaurabh
    Mar 21, 2018 at 8:24

1 Answer 1

4

The error is clear on what is wrong. Its complaining that you're inject classes that are already in the context object. Have a look at this for a better understanding of what the context is.

Context objects were introduced to isolate third party developers from changes in constructors of abstract classes.

You need to remove these two classes you are injecting into the block and helper classes and instead use what is already included in the context class.

\Magento\Framework\Filesystem 

\Magento\Framework\App\Config\ScopeConfigInterface

Instead just call $context->getFilesystem() and $this->scopeConfig

7
  • i removed protected $_filesystem; , \Magento\Framework\Filesystem $filesystem, and $this->_filesystem = $filesystem; , now it gives me another error in local envirnment
    – inrsaurabh
    Mar 21, 2018 at 8:47
  • i have no idea about the use of _filesystem here, is it necessary to use this in block , i took help form other sources
    – inrsaurabh
    Mar 21, 2018 at 8:51
  • .... If you're not using it then why include it in the first place? Its always good to understand what the code does instead of just copying and pasting. Mar 21, 2018 at 8:56
  • yes i understood that i must read understand before copy, currently i am not using _filesystem anywhere in the file after __construct
    – inrsaurabh
    Mar 21, 2018 at 9:03
  • i think _filesystem is used as once i am trying to create a funtionality related to imageFactory now that functionality is removed so i need to remove the both classes magento.stackexchange.com/questions/134360/…
    – inrsaurabh
    Mar 21, 2018 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.