D8: interface Drupal\Core\Database\StatementInterface
D7: DatabaseStatementInterface
Both of these interfaces have some "optional" methods, where the docblock exists, but the method itself is commented out:
//protected function __construct(Connection $dbh);
// (this one is a special case, I would say)
// public function setFetchMode($mode, $a1 = NULL, $a2 = array());
// public function fetch($mode = NULL, $cursor_orientation = NULL, $cursor_offset = NULL);
// public function fetchObject();
// function fetchAll($mode = NULL, $column_index = NULL, array $constructor_arguments);
These always generate IDE warnings if you use
db_select('menu_links')
-> ...
->execute()->fetchAll();
Possible solutions:
- Additional interface that includes those optional methods. (or make it more than one interface)
- Abstract base class where the optional methods are defined, but an exception is thrown if they are used.
- Multiple-type return statement on execute().
E.g.
/**
* @return StatementInterface|ExtendedStatementInterface
*/
function execute();
Comments
Comment #1
donquixote commentedI ended up doing a LOT of code style and docblock fixes in dbtng.
https://github.com/donquixote/drupal/compare/D8-2168241-1
This also contains some real bug fixes.
PhpStorm really likes it! Only a few cases are left, where it is legitimate to ignore the IDE warnings.
Lesson learn: If we play nice with PHPDoc, the IDE can actually help us find real bugs, not just cosmetic improvements.
I will make the git history a bit more readable, by splitting up the big commit.
I also think some of the changes might go a bit too far. But at least I can get some feedback on those things.
Comment #2
Crell commentedThose are listed because we want docblocks on them but they're actually defined higher in the class hierarchy by PHP itself. I forget exactly why we had to do that, frankly... It had to do with PHP 5.1-era PDO developers being sloppy, that's all I remember. :-)
Comment #3
donquixote commentedI split up the changes into smaller commits. I hope this is not too overwhelming.
https://github.com/donquixote/drupal/compare/D8-2168241-3
The smaller commits will allow to omit some of the changes on rebase.
And this is the one where I cover the fetchAll() and friends.
https://github.com/donquixote/drupal/commit/1b52211d3458b6e701fe747aeb61...
Comment #4
donquixote commented@Crell:
About the PDO stuff. What if we introduce
With the exact signature of the respective PDO classes.
Then
PDOCompliantStatementInterfacecan extendPDOStatementInterfaceandStatementInterface, etc.EDIT: Although.. we probably don't need all the PDO methods, only some of them. Especially if we want to have statement classes that behave like PDO but don't inherit from PDO, this will be easier if we reduce the PDOStatementInterface to the most relevant methods.
EDIT: Hold on, I think I am running into the same problem that you did years ago. Let's wait until I actually know what I am talking about.
Comment #5
donquixote commentedI managed to re-activate the 4 methods without introducing a new separate interface, and I managed to avoid a conflict with \PDO !
https://github.com/donquixote/drupal/compare/D8-2168241-5
Commit: https://github.com/donquixote/drupal/commit/289eb13ecbfde4e31e1b1fbaeffa...
Comment #6
donquixote commentedNew version, where the stuff in Drupal/migrate/Tests/FakeStatement.php is fixed.
https://github.com/donquixote/drupal/compare/D8-2168241-6
Commit: https://github.com/donquixote/drupal/commit/0668938e2409b71e058ada042b3c...
Comment #7
pwolanin commentedSo, this doesn't cover the execute() method?
Comment #8
donquixote commented@pwolanin:
No idea really :) I think the entire diff is far too big for one issue, so the execute() probably got lost.
And I see that execute() is already covered here. #2226501: Add execute() to the SelectInterface
Here is one re-rolled tag with fixed conflicts. But this does not really fix the problem of doing too much at once.
https://github.com/donquixote/drupal/compare/D8-2168241-8--reroll-and-fi...
I'd say we should split this up into separate issues and do it one step at a time.
Comment #9
donquixote commentedNope, wrong!
The execute() method is contained in both #6 and #8, see
https://github.com/donquixote/drupal/compare/D8-2168241-8--reroll-and-fi...
"Add SelectInterface::execute()"
https://github.com/donquixote/drupal/commit/eda0a53f08302390b0bd4334b9f0...
The difference to the patch in #2226501: Add execute() to the SelectInterface is that it is added at the bottom of SelectInterface, whereas the other patch adds it directly after preExecute(). I suppose the latter is preferable.
I don't care in which order we commit all this, I am open to suggestions.
Comment #10
donquixote commentedOne important question that came to me while looking at this:
If a method Statement::execute() both overrides PDOStatement::execute() and implements StatementInterface::execute(), then is {@inheritdoc} really appropriate?
Comment #11
pwolanin commentedNeeds an update of the issue summary. Also, please post a patch even if you make it possible to look at the comparison view too.
I'm not sure which git history you are talking about making readable.
Looking at the last comparison it seems almost all doxygen cleanup? I don't even see any change to the interface?
Maybe you should split out a pure doc fix patch so that can go in and avoid distracting from the original intent of this issue?
Comment #12
donquixote commentedIf I click on the link in #9, I see a series of commits.
Or we leave this issue with its original intent, and open a new one for the docblock fixes.
Comment #13
donquixote commentedFirst split-out: #2259947: Minor bug fixes in database system
Comment #14
donquixote commentedAnother split-out: #2259979: Docblock fixes in database system, part I
I'd say get these other issues in first, then continue here or create more separate issues.
Comment #15
jhodgdonI believe that this other issue I filed a few days ago is a duplicate of this one:
#2287151: StatementInterface docs have a bunch of obsolete stuff in them
However, this issue is impossible to figure out and there isn't even a patch to look at. Please update the issue summary and upload a patch so we can decide if that other one is a duplicate or not. Thanks!
Comment #17
andypostAt least this change is needed for #2572659: Fix 'Drupal.Commenting.InlineComment.SpacingAfter' coding standard
Comment #18
jhodgdonHm...
I don't think this patch resolves this issue, but as stated in comment #15, it is difficult to tell because the issue summary is unclear... Probably this patch should be put into a different issue, or else a full patch that fully resolves this issue needs to be made. We don't want multiple patches on the same issue.
Anyway, regarding this patch:
In the second line, there is a word missing... "... with a custom without this constructor". Wording could probably be improved too?
lastly? I don't think there is a list that this is the last part of. This wording is therefore a bit confusing to encounter.
Really... this whole paragraph is overly long.
Why do we even need any of this information in the doc block anyway? It *may* have been appropriate when it was an interface method, but in a class I don't think it makes much sense to put any of it here.
Do not use i.e. On another issue we are removing all i.e. in comments.
Comment #21
mile23Most of the methods were uncommented here: #2521832: Uncomment StatementInterface methods
We still have a sort of prototype
__construct()method, which counts as commented code, and makes us unhappy in #2715485: Fix 'Drupal.Commenting.InlineComment.NoSpaceBefore' coding standardComment #28
andypostComment #30
daffie commentedThe class Statement is deprecated. Therefore that part of the patch can be removed.
The part of the patch that removes the docblock for the __construct method of the StatementInterface needs to stay in the patch.
Comment #31
daffie commentedComment #32
daffie commentedThe removal of the docblock for the __construct method of the StatementInterface wiil be done in #3177660: Remove public properties from StatementInterface implementations.
That makes redundant and therefore I will close the issue.