8000 Stop relying on Type::__toString by greg0ire · Pull Request #2835 · doctrine/dbal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Stop relying on Type::__toString #2835

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

Merged
merged 2 commits into from
Sep 11, 2017

Conversation

greg0ire
Copy link
Member
@greg0ire greg0ire commented Sep 2, 2017

It is a somewhat fragile thing to do.

use Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs;
use Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs;
use Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs;
use Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs;
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 reordered the use statements. Is it good or did the previous order have some meaning I should keep?

Copy link
Member

Choose a reason for hiding this comment

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

No worries on reordering it, I usually do it on a separated commit to make it easier for people to review stuff 😄

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 got lazy there, I'll do that.

@greg0ire greg0ire force-pushed the avoid_type_to_string branch from 2fe3fd6 to e291f88 Compare September 2, 2017 17:52
$type = $field['type'];
if ($type instanceof Types\IntegerType ||
$type instanceof Types\BigIntType ||
$type instanceof Types\SmallIntType
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 I introduce a parent class? This test is done several time ( it done in SQLServerPlatform, for instance)

Copy link
Member Author

Choose a reason for hiding this comment

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

Or maybe a marker interface?

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean something like an AbstractNumberType? It wouldn't introduce number-specific functionality and just be an empty class, if you meant such a solution. A marker interface would have no methods, right? I'm not sure about new class or interface files, that are only introduced for checks. Do those have a purpose in userland for custom types or would those be only used internally?

I also considered (static?) methods for internal type checking, but those had to be maintained too and aren't elegant either. It's like we can only introduce more complexity to Doctrine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean something like an AbstractNumberType? It wouldn't introduce number-specific functionality and just be an empty class, if you meant such a solution.

Correct, but indeed, an interface is better

A marker interface would have no methods, right?

yup

I'm not sure about new class or interface files, that are only introduced for checks. Do those have a purpose in userland for custom types or would those be only used internally?

People that introduce numeric types and would like to benefit from the code behind those checks could implement that interface, so yeah, there is a purpose in userland.

I also considered (static?) methods for internal type checking, but those had to be maintained too and aren't elegant either. It's like we can only introduce more complexity to Doctrine.

Yeah, and I think a marker interface is really not a big thing to make public.

Copy link
Member

Choose a reason for hiding this comment

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

👍 for the marker interface. I'd suggest to mark it as internal to tell people to simply no use it (@internal).

$default = " DEFAULT ".$field['default'];
} elseif (in_array((string) $field['type'], ['DateTime', 'DateTimeTz']) && $field['default'] == $this->getCurrentTimestampSQL()) {
} elseif (($type instanceof Types\DateTimeType || $type instanceof Types\DateTimeTzType)
Copy link
Member Author

Choose a reason for hiding this comment

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

Same here

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, and we probably should have added the immutable type here as well

Copy link
Member Author

Choose a reason for hiding this comment

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

@lcobucci the immutable type extends the mutable type, so it's already ok :)

@greg0ire greg0ire force-pushed the avoid_type_to_string branch 2 times, most recently from ed1e052 to 9008fdf Compare September 2, 2017 18:03
@greg0ire greg0ire changed the title WIP: Stop relying on Type::__toString Stop relying on Type::__toString Sep 2, 2017
@greg0ire greg0ire force-pushed the avoid_type_to_string branch 2 times, most recently from b5ea715 to eb705ad Compare September 2, 2017 22:58
@greg0ire greg0ire mentioned this pull request Sep 3, 2017
9 tasks
Copy link
Member
@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

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

Let's move the build fixes out of this PR (I'm working on that) and simplify things using a marker interface.

@greg0ire
Copy link
Member Author
greg0ire commented Sep 8, 2017

The build fix was just to check I didn't actually break things. I will remove them when the PR looks like it's mergeable.

@greg0ire
Copy link
Member Author
greg0ire commented Sep 8, 2017

Also, please see #2838 for a quick fix of the build until you find a better solution if there is one.

@greg0ire greg0ire force-pushed the avoid_type_to_string branch from eb705ad to 6131a51 Compare September 9, 2017 08:06
} elseif ((string) $field['type'] == 'Date' && $field['default'] == $this->getCurrentDateSQL()) {
$default = " DEFAULT ".$this->getCurrentDateSQL();
} elseif ((string) $field['type'] == 'Boolean') {
} elseif ($type instanceof Types\DateType && $field['default'] == $this->getCurrentDateSQL()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe I should name the marker interface differently because of Types\DateType does not implement it although it does map to a PHP \DateTimeInterface instance? Suggestions?

@greg0ire
Copy link
Member Author
greg0ire commented Sep 9, 2017

@lcobucci please review again. I kept the build-fixing commit to ensure I did not break anything.

@greg0ire
Copy link
Member Author
greg0ire commented Sep 9, 2017

Let's move the build fixes out of this PR (I'm working on that)

How about merging #2838 right now and do it your way later? That would make things easier for all the outstanding PRs...

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.

Needs some tests, as you can see, Travis is green even though there's a fatal error. :/

$default = " DEFAULT ".$this->getCurrentDateSQL();
} elseif ((string) $field['type'] == 'Boolean') {
} elseif ($type instanceof Types\DateType && $field['default'] == $this->getCurrentDateSQL()) {
$default = " DEFAULT ".$this>getCurrentDateSQL();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice one (accidentaly removed -), one would say it would fatal right away, but it won't, only when executed... PHP...

Copy link
Member Author
@greg0ire greg0ire Sep 9, 2017

Choose a reason for hiding this comment

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

woops, nice catch!

Copy link
Member

Choose a reason for hiding this comment

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

Really good eyes here. I didn't saw that too. 👍

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 got very unlucky, that's the only if that was not covered.

@greg0ire greg0ire force-pushed the avoid_type_to_string branch from 6131a51 to c65275b Compare September 9, 2017 15:41
@greg0ire
Copy link
Member Author
greg0ire commented Sep 9, 2017

I created #2851 to prove the test work with the previous code. Please review and merge it, and I shall rebase this.

@greg0ire
Copy link
Member Author
greg0ire commented Sep 9, 2017

Oh snap I need to add #2838 to it if I want to prove anything

@greg0ire greg0ire force-pushed the avoid_type_to_string branch from c65275b to 2cdc601 Compare September 10, 2017 22:07
@Majkl578
Copy link
Contributor

Related issue in ORM: doctrine/orm#5760

It groups things naturally.
It is a somewhat fragile thing to do.
@greg0ire greg0ire force-pushed the avoid_type_to_string branch from 2cdc601 to 9e75bb0 Compare September 11, 2017 06:16
@greg0ire
Copy link
Member Author

Pushed again without the test commit, which was just merged. Please review again @Majkl578 @lcobucci

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.

LGTM 👍

@Ocramius Ocramius self-assigned this Sep 11, 2017
@Ocramius Ocramius added this to the 2.7 milestone Sep 11, 2017
@Ocramius Ocramius merged commit ba421d1 into doctrine:master Sep 11, 2017
@Ocramius
Copy link
Member

🚢

@greg0ire
Copy link
Member Author

Please don't review again then :P


namespace Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
Copy link
Member

Choose a reason for hiding this comment

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

What was the point for this use statement?

Copy link
Member Author

Choose a reason for hiding this comment

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

None I'm afraid 😓


namespace Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
Copy link
Member

Choose a reason for hiding this comment

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

What was the point for this use statement?

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.

5 participants
0