15

I'm running the codesniffer with the EcgM2 standard on my custom extension and I'm getting the warning

The method parameter $context is never used

for the InstallSchema.php file.
How can I make this warning go away?
My method looks like this (notice the SuppressWarnings at the top of it):

/**
 * {@inheritdoc}
 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
    //my install script here that does not use the parameter $context
}

5 Answers 5

10

I was able to hide the dirt under the rug like this:

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

I'm not proud of it, but it works.

2
  • adding the // @codingStandardsIgnoreEnd between the method signature and the opening curly brace will cause a phpcs warning - phpcs: opening brace should be on the line after the declaration; found 1 blank line(s)
    – Radu
    Commented Jun 11, 2019 at 14:05
  • right. it can be added after the opening bracket. I edited the answer.
    – Marius
    Commented Jun 11, 2019 at 14:18
6

Update phpcs (squizlabs/PHP_CodeSniffer) to latest (v3.2.3 at 2017-03-06) and use like:

/**
 * {@inheritdoc}
 */
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
    //my install script here that does not use the parameter $context
}
0
4

I think this is the right way:

/**
 * {@inheritdoc}
 * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter
 */
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
    //my install script here that does not use the parameter $context
}
2

I'm pretty sure the suppress warning rule you will have to use is:

Generic.CodeAnalysis.UnusedFunctionParameter

So this should be the code to use in your PHP Docblock:

@SuppressWarnings(Generic.CodeAnalysis.UnusedFunctionParameter)
3
  • thanks for digging this up, but it has no effect
    – Marius
    Commented Jun 28, 2016 at 13:54
  • 1
    @Marius hmm that's annoying Commented Jun 28, 2016 at 13:57
  • still not working :(
    – Haim
    Commented Jan 15, 2019 at 14:27
2

Just in case if someone has the same configuration, it works for me but with OP's SuppressWarnings ! No other answer worked.

So @SuppressWarnings(PHPMD.UnusedFormalParameter) actually works with PHPMD.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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