2

I am getting this error when I submit my extension for technical review at magento marketplace .

I know there are answers available for this , I have gone through following questions as well question 1 && question 2.

but the answer provided there is not resolving the warning .

Here is my code

/**
 * Created by PhpStorm.
 * User: Rahul
 * Date: 31/7/18
 * Time: 4:37 PM
 */

namespace Rahul\DiscountPlugin\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Model\Config;

class InstallSchema implements InstallSchemaInterface
{

    /**
     * @var EavSetup
     */
    private $eavSetup;

    /**
     * @var Config
     */
    private $eavConfig;

    /**
     * InstallData constructor.
     * @param EavSetup $eavSetup
     * @param Config $config
     */

    public function __construct(
        EavSetup $eavSetup,
        Config $config
    ) {
        $this->eavSetup = $eavSetup;
        $this->eavConfig = $config;
    }
    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();

        $table = $setup->getConnection()->newTable(
            $setup->getTable('discountplugin')
        )->addColumn(
            'vatpluginid',
            \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            null,
            ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
            'VatPluginId'
        )->addColumn(
            'apikey',
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            255,
            [],
            'ApiKey'
        )->addColumn(
            'endpoint',
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            255,
            [],
            'EndPoint'
        )->addColumn(
            'created_at',
            \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
            null,
            ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
            'Create date'
        )->addColumn(
            'updated_at',
            \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
            null,
            ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
            'Updated date'
        )->setComment(
            'discount plugin table'
        );
        $setup->getConnection()->createTable($table);

        $eavTable1 = $setup->getTable('quote');
        $eavTable2 = $setup->getTable('sales_order');

        $columns = [
            'save_vat_discount' => [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'nullable' => true,
                'comment' => 'Input option',
            ]
        ];

        $connection = $setup->getConnection();
        foreach ($columns as $name => $definition) {
            $connection->addColumn($eavTable1, $name, $definition);
            $connection->addColumn($eavTable2, $name, $definition);
        }
        $setup->endSetup();
    }
}

can please anyone guide me what I am doing wrong here ?

Thanks

4
  • you have not used that variable that's why it shows error
    – kunj
    Aug 28, 2018 at 12:08
  • 1
    Thanks @kunj , I am already aware about that I have not used that variable , thats why I am asking how to suppress that warning .
    – Mac
    Aug 28, 2018 at 12:20
  • 1
    Addthis code $context->getVersion(); after $installer->startSetup();.
    – kunj
    Aug 28, 2018 at 12:26
  • 1
    Put before public function install() /** * {@inheritdoc} * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */
    – Abdul
    Aug 28, 2018 at 12:27

3 Answers 3

2

try this :

// @codingStandardsIgnoreStart     
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)     
// @codingStandardsIgnoreEnd

OR

As you can see in Magento default CMS installer : /vendor/magento/module-cms/Setup/InstallSchema.php

/**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) 

OR we can do this :

public function install(\Magento\Framework\Setup\SchemaSetupInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();
        $context->getVersion();
8
  • Thanks but it still gives the same warning .
    – Mac
    Aug 28, 2018 at 12:30
  • @RahulMakwana, I have updated answer.
    – kunj
    Aug 28, 2018 at 12:30
  • Thanks , I tried that as well but still getting same warning .
    – Mac
    Aug 28, 2018 at 12:33
  • 1
    Thanks , I have used // @codingStandardsIgnoreStart but it still shows the warning . I am adding my extension for technical review on magento marketplace and getting this warnings .
    – Mac
    Aug 28, 2018 at 13:36
  • 1
    I wanted to suppress this warning but was not able to achieve the same but yes using the $context variable fix , I don't really like this as I wanted to suppress the warning but for now I am using like you suggested .
    – Mac
    Sep 18, 2018 at 6:45
0

Can you try the below code for your file:

<?php
/**
 * Created by PhpStorm.
 * User: Rahul
 * Date: 31/7/18
 * Time: 4:37 PM
 */

namespace Rahul\DiscountPlugin\Setup;

class InstallSchema implements InstallSchemaInterface
{
    public function install(\Magento\Framework\Setup\SchemaSetupInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();

        if (!$installer->tableExists('discountplugin')) {
            $table = $installer->getConnection()->newTable(
                $installer->getTable('discountplugin')
            )->addColumn(
                'vatpluginid',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                null,
                ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                'VatPluginId'
            )->addColumn(
                'apikey',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                [],
                'ApiKey'
            )->addColumn(
                'endpoint',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                [],
                'EndPoint'
            )->addColumn(
                'created_at',
                \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
                'Create date'
            )->addColumn(
                'updated_at',
                \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
                'Updated date'
            )->setComment(
                'discount plugin table'
            );
            $installer->getConnection()->createTable($table);
        }

        $eavTable1 = $installer->getTable('quote');
        $eavTable2 = $installer->getTable('sales_order');

        $columns = [
            'save_vat_discount' => [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'nullable' => true,
                'comment' => 'Input option',
            ]
        ];

        $connection = $installer->getConnection();
        foreach ($columns as $name => $definition) {
            $connection->addColumn($eavTable1, $name, $definition);
            $connection->addColumn($eavTable2, $name, $definition);
        }
        $installer->endSetup();
    }
}
4
  • Thanks for your answer , I tried your code but it still shows the same warning .
    – Mac
    Aug 28, 2018 at 12:21
  • Can you remove the below code which updates quote and sales order table and test again. Aug 28, 2018 at 12:21
  • ok let me try that .
    – Mac
    Aug 28, 2018 at 12:22
  • I tried removing that block of code as well but still getting that warning .
    – Mac
    Aug 28, 2018 at 12:27
0

Use this in the doc block of the function:

/**
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter
 */

The first line is to suppress warning for PhpMd, the latter for Phpcs.

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.