Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework Exception Naming Conventions #219

Open
wants to merge 1 commit into
base: 8.2.x
Choose a base branch
from

Commits on Sep 9, 2020

  1. Rework Exception Naming Conventions

    Until now the SuperfluousExceptionNaming sniff was enabled in Doctrine
    Coding Standard, but every of our projects disabled this sniff in their
    local phpcs.xml rule.
    
    Doctrine does not actually follow this rule, instead we provide the
    context of the exception in the name as a "prefix" similar to PHPs own
    RuntimeException and so on.
    
    This is done, because exceptions are used soley in the context of code
    that reads like:
    
        } catch (DBALException $e) {
        }
    
    If we allow classes named "Exception", then we introduce a developer
    experience problem, because it potentially requires the user
    to make an alias/renaming decision, increasing their mental load:
    
        use OtherLibrary\Exception as OtherException;
        use Doctrine\DBAL\Exception as DBALException;
        use Exception;
    
        } catch (OtherException $e) {
        } catch (DBALException $e) {
        } catch (Exception $e) {
        }
    
    Additionally it makes it hard for developers understanding catch clauses
    when they cannot rely on the fact that "Exception" is the global one.
    
        } catch (Exception $e) { // don't mess with user expectations
    beberlei committed Sep 9, 2020
    Configuration menu
    Copy the full SHA
    d5e2cb7 View commit details
    Browse the repository at this point in the history