Skip to content

Conversation

@toin0u
Copy link
Member

@toin0u toin0u commented May 2, 2013

Hi,

What do you think @willdurand @Baachi @mrkrstphr ?
Thanks to @Baachi for his idea :)

Btw tests are fixed by #228

Copy link
Member

Choose a reason for hiding this comment

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

I think, mark the method as final is not really necessary. WDY @willdurand @toin0u

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 kept this because of @willdurand's comment: #182 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

But you wrote here that the use should extend from this class to implement his own logic, but this isn't possible with final.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes createFromArray can't be extended but newInstance can as I did here: https://github.com/toin0u/Geotools/blob/master/src/Geotools/Batch/BatchResult.php

Copy link
Member

Choose a reason for hiding this comment

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

The idea is to provide its own ResultInterface instance, not to change the data type returned by the factory. So I think it's correct.

Copy link
Member

Choose a reason for hiding this comment

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

@willdurand Then it would be better to mark the class as final and write it down to the docs?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well there is now ResultFactoryInterface so it's possible to mark DefaultResultFactory and MultipleResultFactory as final but it will introduce a BC break.

Copy link
Member

Choose a reason for hiding this comment

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

@toin0u Good catch! Its not worth enough to introduce a BC break, but we should update the docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Baachi You're totaly right ! We need to update the docs 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Docs updated. Is it good enough ?

willdurand added a commit that referenced this pull request May 3, 2013
Added: DefaultResultFactory and MultipleResultFactory classes - Fix #223
@willdurand willdurand merged commit 639676f into geocoder-php:master May 3, 2013
@willdurand
Copy link
Member

Perfect, thank you!

@toin0u
Copy link
Member Author

toin0u commented May 3, 2013

@Baachi @willdurand Thanks :)

@toin0u toin0u deleted the MultipleResultFactory branch May 3, 2013 07:31
@Baachi
Copy link
Member

Baachi commented May 3, 2013

Perfect 👍

@willdurand
Copy link
Member

mmh, we should update the providers, isn'it?

@toin0u
Copy link
Member Author

toin0u commented May 3, 2013

Yes... And we should update the doc because not every providers return multilple results.
Sorry, my bad :S

@toin0u
Copy link
Member Author

toin0u commented May 3, 2013

Ok I'm looking for this and we have a problem when:

  • the provider returns one result and we use MultileResultFactory
  • the provider returns multiple results and we use DefaultResultFactory

Should we throw an exception in the factory ? Or should factories be more similar by using \SplObjectStorage(BC break) ? @willdurand @Baachi WDYT ?

@Baachi
Copy link
Member

Baachi commented May 5, 2013

I would avoid a BC break. Maybe exceptions are the way to go.

@willdurand
Copy link
Member

I don't understand.

the provider returns one result and we use MultileResultFactory

then, there will be a collection with one item, no problem

the provider returns multiple results and we use DefaultResultFactory

then, the first one will be used, which is the current behavior

@toin0u
Copy link
Member Author

toin0u commented May 6, 2013

I understand what you mean but the problem is:

  • the DefaultResultFactory expects an array (gist)
  • the MultipleResultFactory expects an array of arrays (gist)

This GoogleMapsProvoder returns:

  • one result for 10 rue gambetta, Paris, france
  • multiple results for Paris

So if you got one result with MultipleResultFactory, we got a fatal error here. And multiple results with DefaultResultFactory, we got a null Geocoded object.

I hope I was clear enough and you can see this point :)

@willdurand
Copy link
Member

No I still don't understand, each provider should return an array of arrays.

@toin0u
Copy link
Member Author

toin0u commented May 6, 2013

It's true, it's my mistake, I should wrote array of arrays and array of associate arrays.

Single result:

Array
(
    [latitude] => 48.8234055
    [longitude] => 2.3072664
    ...
)

Multiple results:

Array
(
    [0] => Array
        (
            [latitude] => 48.8234055
            [longitude] => 2.3072664
            ...
        )
    ...
)

@willdurand
Copy link
Member

Providers HAVE TO return all results. The Factory makes the final decision.

@toin0u
Copy link
Member Author

toin0u commented May 6, 2013

I understand what you meant now.

We misunderstood each other because I was exposing a problem when providers return one or multiple results.. And you already assumed that providers return all results :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants