Skip to content

Some refactor to make the code cleaner #2

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 61 commits into from
Sep 4, 2019
Merged

Some refactor to make the code cleaner #2

merged 61 commits into from
Sep 4, 2019

Conversation

ecastro98
Copy link
Member

It would also be able to be used with composer, the package manager for php.

@qaisjp
Copy link
Contributor

qaisjp commented Jan 14, 2019

I've deleted commit 0205974 & fixed some other bugs to make the commit history cleaner. You will need to git fetch and then git reset origin/feature/refactor --hard so that you get the updated repo.

@ecastro98
Copy link
Member Author

For some reason, WIP check dissapeared. Do not merge while 'WIP' is in title.

@ecastro98 ecastro98 changed the title WIP: Some refactor to make the code cleaner Some refactor to make the code cleaner Sep 3, 2019
@ecastro98
Copy link
Member Author

More and more changes >:D @qaisjp @Deltanic

Copy link
Contributor

@qaisjp qaisjp left a comment

Choose a reason for hiding this comment

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

I gave it a read, this looks great!

Whilst I cannot judge whether or not the code is idiomatic (I am not a PHP developer), I couldn't find any obvious issues 👍

My only comment would be that I am not sure if supporting the following syntax is a good idea:

$response = $mta->someResource->callableFunction($arg1, $arg2, $arg3, ...);

My concern is that, if we add more ways to interact with a server, the possibility of clashing with existing resources might prevent us from adding more methods.

What do you think? It is totally your call whether or not to keep the functionality.

@ecastro98
Copy link
Member Author

We have MtaService class where it happens the real interaction with the server. The magic method (in Resource class) will execute the method call from the service so if we add more ways to interact with a server, it should happen here with no problems.

Plus, it also adds some DX.

Although, I will remove the magic getter from Mta class and keep $mta->getResource('someResource') to get a resource because it restrict us to create public properties that could be important in the future.

So the final ways to call a resource function will be:

$response = $mta->getResource('someResource')->call('callableFunction', $arg1, $arg2, $arg3, ...);
// or
$response = $mta->getResource('someResource')->callableFunction($arg1, $arg2, $arg3, ...);

@qaisjp
Copy link
Contributor

qaisjp commented Sep 4, 2019

Although, I will remove the magic getter from Mta class and keep $mta->getResource('someResource') to get a resource because it restrict us to create public properties that could be important in the future.

This is actually what I was referring to. I didn't even notice the $res->callableFunction(...) shorthand!

I notice Resource.php has this:

public function getName()
{
    return $this->name;
}

If there's a callable function getName, wouldn't you be required to use $resource->call('getName', ...) instead?

I agree it's nice to have the shorthand, but imo there's the same issue here. Maybe a nice way around that would be to support $res->call->callableFunction(...) or $res->rpc->callableFunction(...) instead?

@ecastro98
Copy link
Member Author

Agree. I will add it tomorrow.

@qaisjp
Copy link
Contributor

qaisjp commented Sep 4, 2019

Oh, and one more thing, the license.

It looks like all of this is original work, so the license should be completely up to you.

I'd recommend either:

@ecastro98
Copy link
Member Author

@qaisjp What about now?

@Deltanic Deltanic removed their request for review September 4, 2019 20:55
@Deltanic Deltanic removed their assignment Sep 4, 2019
Copy link
Contributor

@qaisjp qaisjp left a comment

Choose a reason for hiding this comment

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

Go for merge!

@ecastro98 ecastro98 merged commit 0b6a38c into multitheftauto:master Sep 4, 2019
@ecastro98 ecastro98 deleted the feature/refactor branch September 5, 2019 14:03
@ecastro98 ecastro98 restored the feature/refactor branch September 5, 2019 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants