Skip to content

Exception thrown in single catch block passes #93

Closed
@danmooney2

Description

@danmooney2

Preconditions

Steps to reproduce

  • Run phpcs with --standard=Magento2 against file containing multiple catch blocks (it fails as it should):
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento;

/**
 * Doer
 */
class Doer
{
    /**
     * Do Something
     */
    public function doSomething()
    {
        try {
            $result = 2;
        } catch (\DummyException $e) {
            throw $e;
        } catch (\NewException $e) {
            throw $e;
        }

        return $result;
    }
}

Run phpcs with --standard=Magento2 against file containing one catch block (it passes when it should not):

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento;

/**
 * Doer
 */
class Doer
{
    /**
     * Do Something
     */
    public function doSomething()
    {
        try {
            $result = 2;
        } catch (\DummyException $e) {
            throw $e;
        }

        return $result;
    }
}

Expected result

  • Both files should fail Magento.Exceptions.ThrowCatch rule

Actual result

  • Only file with two catch blocks fails Magento.Exceptions.ThrowCatch rule

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfalse negativeRule causes false negative findingsneed to discussRule requires discussion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions