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

Forward compatibility with 3.x #2996

Merged
merged 14 commits into from
Feb 1, 2018
Merged

Conversation

morozov
Copy link
Member

@morozov morozov commented Jan 25, 2018

This is a back-port of non-BC-breaking part of #2958.

Fixes #2953.

Copy link
Contributor

@Majkl578 Majkl578 left a comment

Choose a reason for hiding this comment

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

Nice cleanup. 👍
Travis caught some CS issues on modified lines that are not directly caused by this PR.

docs/en/reference/portability.rst Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Cache/ArrayStatement.php Outdated Show resolved Hide resolved
/**
* Contains portable column case conversions.
*/
class ColumnCase
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make these final, maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. I took it as is from your draft and though final private function __construct() is enough. But it only prohibits instantiation, not extension.

\PDO::PARAM_INT => DB2_LONG,
\PDO::PARAM_STR => DB2_CHAR,
ParameterType::INTEGER => DB2_LONG,
ParameterType::STRING => DB2_CHAR,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we align array members the same way as assignments? 🤔

lib/Doctrine/DBAL/Cache/ArrayStatement.php Show resolved Hide resolved
*
* @return boolean TRUE on success or FALSE on failure.
*/
function bindValue($param, $value, $type = null);

public function bindValue($param, $value, $type = ParameterType::STRING);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't change of default here from null to string BC breaking? (Applies to other signature changes as well.)

Copy link
Member Author

@morozov morozov Jan 25, 2018

Choose a reason for hiding this comment

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

PHP is fine with that judging by https://3v4l.org/95JYL. Semantically, both null and ParameterType::STRING are the same since the latter is used by default in all implementations.

Copy link
Member

@Ocramius Ocramius Jan 26, 2018

Choose a reason for hiding this comment

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

I'd be cautious with that. Does the test suite at least contain a test with bindValue() called with only 2 parameters?

Copy link
Member Author

@morozov morozov Jan 28, 2018

Choose a reason for hiding this comment

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

@Ocramius there is a test like that:

This change indeed was only required for develop to make this code work:

return $this->stmt->bindValue($param, $value, $type);

because NULL appears to not be a valid type for PDO:

$conn = new PDO('mysql:host=localhost;dbname=mysql');
$stmt = $conn->prepare('SELECT ?');
$stmt->bindValue(1, 'foo', null);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump($value);

// NULL

I understand your concern but I don't know what to look for. I manually checked all implementations, and they all either default to binding as string explicitly (IBM DB2, MySQLi, PDO) or don't specify the string/null type at all (OCI8, SQL Server) or seem to not even accept NULL (SQLAnywhere).

I can revert changes in all Statement::bind*() signatures if needed.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine if a test already exists and doesn't explicitly pass the third argument to bindValue().

My only issue was that without a test verifying the default parameter we'd have a stability problem :-)

And yes, PDO is (as usual) being weird with default values :-P

@morozov
Copy link
Member Author

morozov commented Jan 28, 2018

@Majkl578 looks like some of the code style violations are reported on wrong lines. For instance:

FILE: lib/Doctrine/DBAL/Cache/ArrayStatement.php
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
  45 | ERROR | [x] Expected "int" but found "integer" in @var
     |       |     annotation.

The @var integer annotation is on the line 43 which is not affected by this pull request and therefore shouldn't be reported. It should be fixed on the code standard side. It should report the annotation itself, not the return value type. All other false positives are caused by the same reason.

@Majkl578
Copy link
Contributor

I noticed that too while working on #2998. The errors seem to be reported for the element they're connected to. See here - $pointer is the position of matched element (either T_VARIABLE or T_FUNCTION. Not sure if there is any reasoning behind this, normally it's not a problem, but here with the line-based filter it is...

@morozov
Copy link
Member Author

morozov commented Jan 28, 2018

@Majkl578 I think we can live with that. I suspect it may be hard to justify the needed changes in a 3rd-party library (not speaking of that someone will have to implement them). On the other hand, we could get rid of the false positives by fixing annotations.

Maybe @carusogabriel could take a look? 😉

@carusogabriel
Copy link
Contributor

@morozov How can I help? 🤓

@Majkl578
Copy link
Contributor

Majkl578 commented Jan 28, 2018

@morozov Reported here: slevomat/coding-standard#250. It should be trivial to fix for LongTypeHInt sniff, but not sure about TypeHintDeclaration sniff which is pretty complex already.

I hope 2.7 will be shipped anytime soon and then we can merge develop & apply CS same as we did in ORM. 😎

@kukulich
Copy link

@morozov

It should be fixed on the code standard side.

Try composer update. It will work now, I hope :)

@Majkl578
Copy link
Contributor

@kukulich Awesome, thanks!

@morozov Retriggerred the CS stage: https://travis-ci.org/doctrine/dbal/jobs/334442418#L524, can you check now?

@morozov
Copy link
Member Author

morozov commented Jan 29, 2018

@carusogabriel judging by CI failures, we have some @param and @return method annotations which define type of value as integer or boolean. The code style requires them to be represented as int and bool accordingly.

@morozov
Copy link
Member Author

morozov commented Jan 29, 2018

@Majkl578, @kukulich thank you for the update. There's one more false positive like the fixed ones:

FILE: lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 101 | ERROR | Property
     |       | \Doctrine\DBAL\Driver\SQLSrv\SQLSrvStatement::$defaultFetchMode
     |       | does not have @var annotation.
----------------------------------------------------------------------

Unlike those, it doesn't seem possible to fix on the standard side since it reports the absence of annotation. Unless you have an idea.

@carusogabriel, mind fixing issues like this as well?

@carusogabriel
Copy link
Contributor

@morozov No problem. I'm just finishing some stuff, I'll PR separately the annotation types and missing @var!

@morozov
Copy link
Member Author

morozov commented Jan 29, 2018

One more falses-positive:

FILE: tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 137 | ERROR | [x] Method
     |       |     \Doctrine\Tests\DBAL\Functional\PortabilityTest::testPortabilityPdoSqlServer()
     |       |     does not need documentation comment.

The standard doesn't account for PHPUnit annotations.

@Majkl578
Copy link
Contributor

Majkl578 commented Jan 29, 2018

This last one is ours, configuration issue - we do have most of the common annotations whitelisted, but I probably forgot this one (@requires).

@Ocramius
Copy link
Member

Argh, the CS changes introduced recently led to a few merge conflicts here, @morozov. Sorry!

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.

Overall good improvement. Besides a change in a test that isn't really clear to me, this is good to go 👍

@@ -217,7 +240,7 @@ public function databaseUrls()
false,
),
'URL without scheme but default PDO driver' => array(
array('url' => '//foo:bar@localhost/baz', 'pdo' => $pdoMock),
array('url' => '//foo:bar@localhost/baz', 'pdo' => true),
Copy link
Member

Choose a reason for hiding this comment

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

This is a test change that I don't understand.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Ocramius look at the changes in testDatabaseUrl(). Instead of creating mock, the data provider passes a flag to the test method. It will either create the mock if PDO is loaded or will skip the data set.

Copy link
Member

Choose a reason for hiding this comment

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

Got it 👍

@morozov
Copy link
Member Author

morozov commented Jan 29, 2018

I believe we can ignore the code style CI failure for this PR. My entire idea of line-based validation was to avoid the "Fixed code style" commits. But given that this one is a back-port from develop, we cannot amend the ported commits because it will introduce further conflicts during rebase of develop.

@morozov
Copy link
Member Author

morozov commented Feb 1, 2018

@Ocramius anything else you want to get done before merging this?

@Ocramius
Copy link
Member

Ocramius commented Feb 1, 2018

Nope, 🚢

@Ocramius Ocramius added this to the 2.7.0 milestone Feb 1, 2018
@Ocramius Ocramius assigned Ocramius and unassigned morozov Feb 1, 2018
@Ocramius Ocramius merged commit e5fe8c8 into doctrine:master Feb 1, 2018
@morozov morozov deleted the issues/2953-2.x branch February 1, 2018 15:56
@Ocramius
Copy link
Member

Ocramius commented Feb 6, 2018

Handled further CS in #3002

@@ -20,7 +20,8 @@
namespace Doctrine\DBAL\Driver\SQLSrv;

use Doctrine\DBAL\Driver\StatementIterator;
use PDO;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is bug - there is still unqualified PDO::FETCH_ORI_NEXT reference.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like the only place like this. Please see #3024.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants