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

refactor: phpcs and composer related updates #21

Merged
merged 7 commits into from
Jul 7, 2024

Conversation

yigitcukuren
Copy link
Contributor

@yigitcukuren yigitcukuren commented Jul 1, 2024

Hey there,

I know this looks huge, but as far as I can see, there are no standards in the PHP code. I thought I might add some standards to make the PHP SDK more collaborative for everyone. If you think these changes are too much, I wouldn't mind creating multiple PRs for a smoother transition.

@mhmd-azeez mhmd-azeez requested review from mhmd-azeez and bhelx July 1, 2024 13:46
@bhelx
Copy link
Contributor

bhelx commented Jul 1, 2024

Thanks for taking the time to improve it! We don't mind the size of the PR. This seems to be all internal changes correct? Assuming there are no external changes then i'd consider it a simple patch / cleanup. No need to break it up.

* @param int $size Size of the block to allocate in bytes.
*/
function allocate_block(int $size) : int
public function allocate_block(int $size): int
Copy link
Contributor

Choose a reason for hiding this comment

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

do these need to be public? These are fairly low-level methods that we don't want people calling in normal operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I am not completely sure what does these function behind the scene. As far as I checked it is used in HostFunctions.php. If you call these methods in the HostFunctions they should be public, if you don't you can set them as private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed some code and I changed the visibility of unused functions in CurrentPlugin.php. You can guide me about updating visibility of specific methods.

{
return $this->ffi->extism_current_plugin_memory($plugin);
}

function extism_current_plugin_memory_free(FFI\CData $plugin, FFI\CData $ptr): void
public function extism_current_plugin_memory_free(FFI\CData $plugin, FFI\CData $ptr): void
Copy link
Contributor

Choose a reason for hiding this comment

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

does this expose the methods to the external users? This is an internal API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They were already public if you not defined them explicitly protected or private.

From php.net

Class methods may be defined as public, private, or protected. 
Methods declared without any explicit visibility keyword are defined as public.

Copy link
Contributor Author

@yigitcukuren yigitcukuren Jul 1, 2024

Choose a reason for hiding this comment

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

Since this function called in CurrentPlugin, we can't make it private.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, just making sure we expose as little API to the public as possible. Maybe the class should be less accessible? I don't know if there is an equivalent of package only. But I'll leave @mhmd-azeez to pick out any changes that are needed. Thanks so much for this cleanup!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it seems like there is no package level access modifier in php. As a middle ground, I moved LibExtism.php to \Extism\Internal namespace, which is a pattern used by some php libraries like Symfony

@yigitcukuren yigitcukuren requested a review from bhelx July 1, 2024 16:28
Copy link
Contributor

@mhmd-azeez mhmd-azeez left a comment

Choose a reason for hiding this comment

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

Great job @yigitcukuren, thank you very much! Can you please go through LibExtism.php functions and try to mark as many of them private as possible?

@yigitcukuren
Copy link
Contributor Author

yigitcukuren commented Jul 4, 2024

Great job @yigitcukuren, thank you very much! Can you please go through LibExtism.php functions and try to mark as many of them private as possible?

Thank you! I have just updated the visibility of all the internal methods.

@yigitcukuren yigitcukuren requested a review from mhmd-azeez July 6, 2024 09:42
Copy link
Contributor

@mhmd-azeez mhmd-azeez 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 very much for your excellent work @yigitcukuren, I moved LibExtism to \Extism\Internal namespace to make it clear that this class is for internal use only. Let me know if you have any concerns or issues with that. Otherwise, I can go on and merge the PR

@yigitcukuren
Copy link
Contributor Author

yigitcukuren commented Jul 7, 2024

Thank you very much for your excellent work @yigitcukuren, I moved LibExtism to \Extism\Internal namespace to make it clear that this class is for internal use only. Let me know if you have any concerns or issues with that. Otherwise, I can go on and merge the PR

It is perfectly fine! Please go ahead 🙏

@mhmd-azeez mhmd-azeez merged commit 443a762 into extism:main Jul 7, 2024
4 checks passed
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