Skip to content

Conversation

TomasVotruba
Copy link

@TomasVotruba TomasVotruba commented Nov 16, 2017

Replaces #647 with passing tests and CS

Why?

This package would be still available for PHP 5.6-.

Questions

1. How to approach string/int issue in parameters?

Often there was random typehint and for string and int there was autore-type to string rawurlencode method.

Should be allow both string and int and manuall rawurlencode((string) $id) or be strict in parameters?

2. How to approach null/array return values?

At least accroding to tests, some api calls return null on fail or empty results. Array was expected in typehtings.

At the moment they return array|null. Is that ok?

@m1guelpf
Copy link
Contributor

How to approach null/array return values?

@TomasVotruba I'm not really sure, but I think in PHP7 you can use array? as a typehint, which I believe is better

@TomasVotruba
Copy link
Author

TomasVotruba commented Nov 16, 2017

@m1guelpf Sure. We should move to PHP 7.1 in standalone PR, one step at a time.

This is rather architecture question, whether all these methods should return array/null

@GrahamCampbell
Copy link
Contributor

GrahamCampbell commented Nov 18, 2017

Sure. We should move to PHP 7.1 in standalone PR, oen step at a time.

I think that's probably a bit fast. ^7.0 will be a good version constraint through 2018 I think.

@TomasVotruba
Copy link
Author

@GrahamCampbell My point was not in this PR. It should be PHP 7.0 only

@GrahamCampbell
Copy link
Contributor

Sure. I was just making the point that I'd 👎 anything beyond this PR unless there were some really good reasons.

@cursedcoder
Copy link
Contributor

What about strict types declaration in every file?
Is it possible to enforce it once? Maybe some composer flag?

@TomasVotruba
Copy link
Author

@cursedcoder Sure, we can require that in coding standard, as I did in php-ml. But again, I'd do that in separate PR, after this one gets resolved to prevent redundant conflicts.

@Nyholm
Copy link
Collaborator

Nyholm commented Dec 12, 2017

I will tag 2.7 within a few minutes.
Could you resolve these conflicts and then merge this PR and make 2.8 our first version without PHP5.

@TomasVotruba
Copy link
Author

Hey, I'm glad you got to this.

Sure, let me know after 2.7 is tagged

@Nyholm
Copy link
Collaborator

Nyholm commented Dec 12, 2017

It's tagged now =)

@TomasVotruba
Copy link
Author

Rebase done 👍

@TomasVotruba
Copy link
Author

TomasVotruba commented Dec 13, 2017

Btw, what about bumping to PHP 7.1 in next PR? Even PHPUnit is now on board

Copy link
Collaborator

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Thank you. I've started to review this. I found a few issues that occur repeatedly in this PR. Could you address all of them?

public function getPerPage();

public function setPerPage($perPage);
public function setPerPage(int $perPage = null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this correct? Why do we allow null?

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 not something new. You can specify no pagination and let github decide AFAIK. It's written as comment on some inheritance of this interface.

* @return array
*/
public function show($clientId)
public function show($clientId): array
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be a string here, right?

public function show($clientId): array
{
return $this->get('/authorizations/'.rawurlencode($clientId));
return $this->get('/authorizations/'.rawurlencode((string) $clientId));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Type casting here could be removed.

* @return array
* @return array|null
*/
public function create(array $params, $OTPCode = null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

$OPTCode is string, right?

public function update($clientId, array $params)
{
return $this->patch('/authorizations/'.rawurlencode($clientId), $params);
return $this->patch('/authorizations/'.rawurlencode((string) $clientId), $params);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, shouldnt client ID be a string? Can you verify?

* Reset an authorization.
*
* @param $clientId
* @param $token
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not remove these with adding type annotations.

Copy link
Author

Choose a reason for hiding this comment

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

What is the type here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I’m not sure without reading the code and docs.

@TomasVotruba
Copy link
Author

Every added type was to fix tests, that failed due to strict types.

* @author Joseph Bielawski <stloyd@gmail.com>
*/
class ErrorException extends \ErrorException implements ExceptionInterface
class ErrorException extends \Exception implements ExceptionInterface
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this change needed?

Copy link
Author

@TomasVotruba TomasVotruba Dec 16, 2017

Choose a reason for hiding this comment

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

It's quite a long time since PR so I'm not sure.

I think it was related to mocks in some way. Try running test with/without it please to confirm.

@acrobat
Copy link
Collaborator

acrobat commented Dec 16, 2017

Imho this PR does a bit to much. Bumping php, adding typehints, cs fixes, etc. This makes it a bit hard for me to review the PR. Maybe we should split this up a bit.

Leave the style changes out for example as this can be done in a separate pr (I've started one with new styleci fixers, but maybe more is needed).

Bump the php version, adapt travis to it and make sure the tests still pass. After that we can start converting typehints. This way we have multiple "small" pr's which makes easy reviews and quick merges :)

This is just my opinion of course, don't know what you guys think of this.

Btw I'm definitely in favor of bumping php and thanks already for the work @TomasVotruba!

@Nyholm
Copy link
Collaborator

Nyholm commented Jan 4, 2018

I agree with acrobat.

Tomas, what is the status here?

@TomasVotruba
Copy link
Author

What is the decision here?

@acrobat
Copy link
Collaborator

acrobat commented Jan 5, 2018

I think we should split the pr. Leave this one for now and open a new PR where you bump the php version, adapt the travis build matrix and make sure tests still pass. From there on we can make the next steps (like adding typehints etc) in separate pr's.

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is in the way of think of the project. Keeping the PHP way looks like a better alternative. Also, the indentation is wrong (it should definitely be on a new line)

@Nek-
Copy link
Contributor

Nek- commented Jan 5, 2018

About the first point (1. How to approach string/int issue in parameters?) the proper way to fix that is to not declare strict type hinting and type hinting string (the result is an automatic cast).

@TomasVotruba
Copy link
Author

Not relevant anymore. I'm closing to clean my opened PRs.

Feel free to cherry pick anything you need.

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.

7 participants