Skip to content

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Feb 25, 2018

You always know an exception is an exception when catching it or
throwing it, so the Exception suffix is useless, but hard to avoid when
you need to group exceptions together, which is why it should be present
in abstract exception names.
See http://mnapoli.fr/approaching-coding-style-rationally/#the-exception-suffix

This is the first of a series of goals I want to clarify regarding exceptions in Doctrine before trying to make a BC version of doctrine/orm#6743

At the moment, things are of course absolutely not like that, but I think that those rules could apply to newly-created exceptions.

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes a lot of sense to me 👍

@carusogabriel can you maybe give the implementation a shot?

@carusogabriel
Copy link
Contributor

@Ocramius Two things:
First: What is your opinion about Abstract and Interface suffixes? Maybe we can extend this to them as well.

Second: Just me fixing manually them is enough, or should we create/search a new Sniff?

@Ocramius
Copy link
Member

About the suffix, we don't use it within the doctrine organisation, so we better make that clear. I use it for my own projects, but that's a different story.

We'd need to create a sniff: enforcing by documentation is not effective.

@kukulich
Copy link
Contributor

Concrete exception class names should not be suffixed with Exception

The check is possible. The same goes for Abstract and Interface suffixes. However it's not possible to make the sniff fixable.

Abstract exception class names and exception interface names should be suffixed with Exception

This is not possible to check with sniff.

@carusogabriel
Copy link
Contributor

carusogabriel commented Feb 26, 2018

@Ocramius Perfect. So I’ll try to create our own Sniff fixing it, or see if there’s an existing one!

@kukulich Can you help us with this one as well? I believe that isn’t difficult, a simple check for class modifiers should report it, right?

@kukulich
Copy link
Contributor

@carusogabriel Yes, the sniffs are already in my todo list :) Should be done this week :)

@carusogabriel carusogabriel added this to the 4.0.0 milestone Feb 26, 2018
@kukulich
Copy link
Contributor

@carusogabriel You can try sniffs in dev-master :)

@carusogabriel
Copy link
Contributor

@kukulich Men, you are fast 😱

@greg0ire Do you mind if I add commits to your PR, or do you wanna try it?

@greg0ire
Copy link
Member Author

@carusogabriel please do :)

<!-- Forbid dead code -->
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements"/>
<!-- Forbid suffix "Abstract" for abstract classes -->
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should lines 97 and 101 be moved to other PRs? Or should I add them to the standard?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add all of them ‘cause of #31 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok let me document that too then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SuperfluousAbstractClassNaming and SuperfluousInterfaceNaming forbid both suffix and prefix. So you should document this or add <exclude> to ignore the prefix check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greg0ire I guess we want just the suffix here, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaah ok yes, I think that's it, because I saw a lot of Abstract prefixes in the code.

carusogabriel and others added 2 commits February 28, 2018 19:23
You always know an exception is an exception when catching it or
throwing it, so the Exception suffix is useless, but hard to avoid when
you need to group exceptions together, which is why it should be present
in abstract exception names.
See http://mnapoli.fr/approaching-coding-style-rationally/#the-exception-suffix
@Majkl578
Copy link
Contributor

I am still against dropping the Exception suffix though.

- :white_check_mark: Abstract classes should not be prefixed with `Abstract`
- :white_check_mark: Interfaces should not be suffixed with `Interface`
- :white_check_mark: Concrete exception class names should not be suffixed with `Exception`
- :white_check_mark: Abstract exception class names and exception interface names should be suffixed with `Exception`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @kukulich said, this isn’t possible 😞

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? You can assume inheritance - when ancestor has the Exception suffix, this class has too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right but:

  • Not all exceptions has Exception suffix, eg. TypeError.
  • You cannot report all bugs in one run with code like A extends B extends C extends Exception. You can report C in first run and B in second.

So if you're ok with this, it's possible to check "Abstract exception class names". However, I think it's really not possible to report "exception interface names should be suffixed with Exception"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove the check mark on that one then.

Copy link
Member Author

@greg0ire greg0ire Mar 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh I was too slow, @Ocramius just merged :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greg0ire fixup patch with discussion there please :P

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

- Keep the nesting of control structures per method as small as possible
- Prefer early exit over nesting conditions or using else
- :white_check_mark: Abstract classes should not be prefixed with `Abstract`
- :white_check_mark: Interfaces should not be suffixed with `Interface`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

composer.json Outdated
"squizlabs/php_codesniffer": "^3.2",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.2",
"slevomat/coding-standard": "^4.4.0"
"slevomat/coding-standard": "dev-master"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version 4.5.0 was just released :)

We need the new sniffs.
@Ocramius
Copy link
Member

Ocramius commented Mar 3, 2018

I am still against dropping the Exception suffix though.

@Majkl578 let's give it a shot - I think @greg0ire made awesome progress on the ORM exceptions, so we will see if no suffix leads to confusion :)

@Ocramius Ocramius self-assigned this Mar 3, 2018
@Ocramius Ocramius removed the WIP label Mar 3, 2018
@Ocramius
Copy link
Member

Ocramius commented Mar 3, 2018

🚢-ing this as-is. If it causes problems, we can revert it, but it is worth trying new naming conventions while we still can 👍

@Ocramius Ocramius merged commit b15293e into doctrine:master Mar 3, 2018
@greg0ire greg0ire deleted the exception_suffix branch March 3, 2018 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants